gpt4 book ai didi

docker - kubernetes 不健康的入口后端

转载 作者:IT老高 更新时间:2023-10-28 12:40:04 25 4
gpt4 key购买 nike

我遵循了负载平衡器教程:https://cloud.google.com/container-engine/docs/tutorials/http-balancer当我使用 Nginx 镜像时,它工作正常,当我尝试使用我自己的应用程序镜像时,虽然后端切换到不健康状态。

我的应用程序在/上重定向(返回 302),但我在 pod 定义中添加了 livenessProbe:

    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:       {"k8s-be-32180--5117658971cfc555":"UNHEALTHY"}

入口规则如下:

Rules:
Host Path Backends
---- ---- --------
* * foo:80 (10.0.0.7:4001,10.0.1.6:4001)

收到的任何指示,我一直在尝试解决这个问题几个小时,但没有运气。

更新

我已将 readinessProbe 添加到我的部署中,但似乎仍有一些东西击中/并且入口仍然不正常。我的探针看起来像:

    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

更新2

readinessProbe 中删除自定义 header 后,它开始工作!非常感谢。

最佳答案

您需要添加一个 readinessProbe(只需复制您的 livenessProbe)。

GCE L7 Ingress Docs 中有解释.

Health checks

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 公开的端口相同。在你的情况下这很好,因为你只有一个端口,如果你添加另一个端口,你可能会遇到麻烦。

关于docker - kubernetes 不健康的入口后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39294305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com