kubernetes不健康的入口后端 [英] kubernetes unhealthy ingress backend
问题描述
我遵循了负载均衡器教程: https://cloud.google .com/container-engine/docs/tutorials/http-balancer ,当我使用Nginx映像时,尽管后端切换到不正常状态,尝试使用自己的应用程序映像时,它仍然可以正常工作.
I followed the load balancer tutorial: https://cloud.google.com/container-engine/docs/tutorials/http-balancer which is working fine when I use the Nginx image, when I try and use my own application image though the backend switches to unhealthy.
我的应用程序重定向到/(返回302),但是我在pod定义中添加了livenessProbe
:
My application redirects on / (returns a 302) but I added a livenessProbe
in the pod definition:
livenessProbe:
httpGet:
path: /ping
port: 4001
httpHeaders:
- name: X-health-check
value: kubernetes-healthcheck
- name: X-Forwarded-Proto
value: https
- name: Host
value: foo.bar.com
我的入口看起来像:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: foo
spec:
backend:
serviceName: foo
servicePort: 80
rules:
- host: foo.bar.com
服务配置为:
kind: Service
apiVersion: v1
metadata:
name: foo
spec:
type: NodePort
selector:
app: foo
ports:
- port: 80
targetPort: 4001
ingress describe ing
中的后端运行状况如下:
Backends health in ingress describe ing
looks like:
backends: {"k8s-be-32180--5117658971cfc555":"UNHEALTHY"}
以及入口规则如下:
Rules:
Host Path Backends
---- ---- --------
* * foo:80 (10.0.0.7:4001,10.0.1.6:4001)
任何指针都收到了好评,我一直在努力解决这个问题,好几个小时都没有运气.
Any pointers greatly received, I've been trying to work this out for hours with no luck.
更新
我已将readinessProbe
添加到我的部署中,但是似乎仍会命中/,并且入口仍不健康.我的探针看起来像:
I have added the readinessProbe
to my deployment but something still appears to hit / and the ingress is still unhealthy. My probe looks like:
readinessProbe:
httpGet:
path: /ping
port: 4001
httpHeaders:
- name: X-health-check
value: kubernetes-healthcheck
- name: X-Forwarded-Proto
value: https
- name: Host
value: foo.com
我将服务更改为:
kind: Service
apiVersion: v1
metadata:
name: foo
spec:
type: NodePort
selector:
app: foo
ports:
- port: 4001
targetPort: 4001
Update2
从readinessProbe
中删除自定义标头后,它开始工作!非常感谢.
After I removed the custom headers from the readinessProbe
it started working! Many thanks.
推荐答案
您需要添加一个readinessProbe(只需复制您的livenessProbe).
You need to add a readinessProbe (just copy your livenessProbe).
GCE L7入口文档中对此进行了解释.
健康检查
当前,所有服务后端必须满足以下任一要求,才能通过从GCE负载平衡器发送给它的HTTP运行状况检查:1.在'/'上响应200.内容没关系. 2.在支持服务的Pod上公开一个任意URL,作为准备情况调查.
Currently, all service backends must satisfy either of the following requirements to pass the HTTP health checks sent to it from the GCE loadbalancer: 1. Respond with a 200 on '/'. The content does not matter. 2. Expose an arbitrary url as a readiness probe on the pods backing the Service.
还要确保readinessProbe指向您公开给Ingress的端口.在您的情况下,这很好,因为您只有一个端口,如果添加另一个端口,则可能会遇到麻烦.
Also make sure that the readinessProbe is pointing to the same port that you expose to the Ingress. In your case that's fine since you have only one port, if you add another one you may run into trouble.
这篇关于kubernetes不健康的入口后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!