带有路由的 GCE 入口总是回退到 default-http-backend
GCE ingress with routes always falls back to default-http-backend
Kubernetes 版本:1.4.5
我有一个非常简单的服务 type: NodePort
。它只是 return 在 /info
上的一些文字。我正在使用带有 TLS 的默认 GKE 入口控制器(L7 Google 负载均衡器)。如果我使用以下入口,一切都会按预期工作:
工作入口
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: global-ingress
namespace: global
annotations:
kubernetes.io/ingress.allow-http: "false"
spec:
tls:
- secretName: tls-secret
backend:
serviceName: gate-front
servicePort: 80
curl -k https://130.211.39.140/info
POD: gate-front-1871107570-ue07p
IP: 10.0.2.26
REQ: /info
$ kubectl describe ing
Name: global-ingress
Namespace: global
Address: 130.211.39.140
Default backend: gate-front:80 (10.0.2.25:8080,10.0.2.26:8080)
TLS:
tls-secret terminates
Rules:
Host Path Backends
---- ---- --------
* * gate-front:80 (10.0.2.25:8080,10.0.2.26:8080)
Annotations:
backends: {"k8s-be-31966--f3f0bf21d171a625":"HEALTHY"}
https-forwarding-rule: k8s-fws-global-global-ingress--f3f0bf21d171a625
https-target-proxy: k8s-tps-global-global-ingress--f3f0bf21d171a625
url-map: k8s-um-global-global-ingress--f3f0bf21d171a625
损坏的入口
但是,如果我引入一个规则并省略默认后端,所有请求 return default backend - 404
。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: global-ingress
namespace: global
annotations:
kubernetes.io/ingress.allow-http: "false"
spec:
tls:
- secretName: tls-secret
rules:
- http:
paths:
- path: /gate
backend:
serviceName: gate-front
servicePort: 80
curl -k https://130.211.33.150/gate/info
default backend - 404
$ kubectl describe ing
Name: global-ingress
Namespace: global
Address: 130.211.33.150
Default backend: default-http-backend:80 (10.0.2.3:8080)
TLS:
tls-secret terminates
Rules:
Host Path Backends
---- ---- --------
*
/gate gate-front:80 (<none>)
Annotations:
https-forwarding-rule: k8s-fws-global-global2-ingress--f3f0bf21d171a625
https-target-proxy: k8s-tps-global-global2-ingress--f3f0bf21d171a625
url-map: k8s-um-global-global2-ingress--f3f0bf21d171a625
backends: {"k8s-be-31966--f3f0bf21d171a625":"HEALTHY","k8s-be-32552--f3f0bf21d171a625":"HEALTHY"}
如果我添加主机并使用 curl -k --resolve ...
,我会得到相同的行为。
我浏览了以下文档和示例:
- http://kubernetes.io/docs/user-guide/ingress/
- https://github.com/kubernetes/contrib/blob/master/ingress/controllers/gce/README.md
任何人都可以阐明这一点吗?
https://github.com/kubernetes/ingress-gce/blob/master/README.md#paths
你能否看一下这部分,如果它解决了问题,请发表评论:
Note what just happened, the endpoint exposes /hostname, and the loadbalancer forwarded the entire matching url to the endpoint. This means if you had '/foo' in the Ingress and tried accessing /hostname, your endpoint would've received /foo/hostname and not known how to route it. Now update the Ingress to access static content via the /fs endpoint:
我遇到了类似的问题,但原因不同,如果您使用的是 GCE,请记住每个入口控制器都会获得一个新 IP。
我已将我的 DNS 指向我创建的第一个入口控制器,并且不知道新的入口控制器获得了新的 IP。来自错误主机的流量被发送到我的第一个入口控制器,所以 404 响应是正确的。
使用 kubectl 检查入口控制器,确保您正确指向 DNS:
kubectl describe ingress/<name>
Kubernetes 版本:1.4.5
我有一个非常简单的服务 type: NodePort
。它只是 return 在 /info
上的一些文字。我正在使用带有 TLS 的默认 GKE 入口控制器(L7 Google 负载均衡器)。如果我使用以下入口,一切都会按预期工作:
工作入口
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: global-ingress
namespace: global
annotations:
kubernetes.io/ingress.allow-http: "false"
spec:
tls:
- secretName: tls-secret
backend:
serviceName: gate-front
servicePort: 80
curl -k https://130.211.39.140/info
POD: gate-front-1871107570-ue07p
IP: 10.0.2.26
REQ: /info
$ kubectl describe ing
Name: global-ingress
Namespace: global
Address: 130.211.39.140
Default backend: gate-front:80 (10.0.2.25:8080,10.0.2.26:8080)
TLS:
tls-secret terminates
Rules:
Host Path Backends
---- ---- --------
* * gate-front:80 (10.0.2.25:8080,10.0.2.26:8080)
Annotations:
backends: {"k8s-be-31966--f3f0bf21d171a625":"HEALTHY"}
https-forwarding-rule: k8s-fws-global-global-ingress--f3f0bf21d171a625
https-target-proxy: k8s-tps-global-global-ingress--f3f0bf21d171a625
url-map: k8s-um-global-global-ingress--f3f0bf21d171a625
损坏的入口
但是,如果我引入一个规则并省略默认后端,所有请求 return default backend - 404
。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: global-ingress
namespace: global
annotations:
kubernetes.io/ingress.allow-http: "false"
spec:
tls:
- secretName: tls-secret
rules:
- http:
paths:
- path: /gate
backend:
serviceName: gate-front
servicePort: 80
curl -k https://130.211.33.150/gate/info
default backend - 404
$ kubectl describe ing
Name: global-ingress
Namespace: global
Address: 130.211.33.150
Default backend: default-http-backend:80 (10.0.2.3:8080)
TLS:
tls-secret terminates
Rules:
Host Path Backends
---- ---- --------
*
/gate gate-front:80 (<none>)
Annotations:
https-forwarding-rule: k8s-fws-global-global2-ingress--f3f0bf21d171a625
https-target-proxy: k8s-tps-global-global2-ingress--f3f0bf21d171a625
url-map: k8s-um-global-global2-ingress--f3f0bf21d171a625
backends: {"k8s-be-31966--f3f0bf21d171a625":"HEALTHY","k8s-be-32552--f3f0bf21d171a625":"HEALTHY"}
如果我添加主机并使用 curl -k --resolve ...
,我会得到相同的行为。
我浏览了以下文档和示例:
- http://kubernetes.io/docs/user-guide/ingress/
- https://github.com/kubernetes/contrib/blob/master/ingress/controllers/gce/README.md
任何人都可以阐明这一点吗?
https://github.com/kubernetes/ingress-gce/blob/master/README.md#paths
你能否看一下这部分,如果它解决了问题,请发表评论:
Note what just happened, the endpoint exposes /hostname, and the loadbalancer forwarded the entire matching url to the endpoint. This means if you had '/foo' in the Ingress and tried accessing /hostname, your endpoint would've received /foo/hostname and not known how to route it. Now update the Ingress to access static content via the /fs endpoint:
我遇到了类似的问题,但原因不同,如果您使用的是 GCE,请记住每个入口控制器都会获得一个新 IP。
我已将我的 DNS 指向我创建的第一个入口控制器,并且不知道新的入口控制器获得了新的 IP。来自错误主机的流量被发送到我的第一个入口控制器,所以 404 响应是正确的。
使用 kubectl 检查入口控制器,确保您正确指向 DNS:
kubectl describe ingress/<name>