kubernetes 不健康的入口后端

kubernetes unhealthy ingress backend

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

我的应用程序重定向到 / (returns a 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 中删除自定义 headers 后,它开始工作了!非常感谢。

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

我遇到了同样的问题。按照 Tex 的提示,但继续看到该消息。事实证明,我必须等待几分钟才能进入以验证服务健康状况。如果有人正在经历同样的事情并完成了 readinessProbelinvenessProbe 等所有步骤,只需确保您的入口指向的服务是 NodePort等待几分钟,直到黄色警告图标变为绿色。另外,检查 StackDriver 上的日志以更好地了解发生了什么。

在更新我的入口 readinessProbe.

后,我也遇到了完全相同的问题

我可以看到标记为 一些后端服务处于未知状态 黄色的入口状态。 等了30多分钟,还是没有反映出来。

超过 24 小时后,更改得到反映并且状态变为绿色。 我没有为此获得任何官方文档,但似乎是 GCP Ingress 资源中的错误。

我认为值得注意的是,这是文档中一个非常重要的限制:

Changes to a Pod's readinessProbe do not affect the Ingress after it is created.

添加 readinessProbe 后,我基本上删除了入口 (kubectl delete ingress <name>),然后再次应用我的 yaml 文件重新创建它,不久之后一切又恢复正常了。

这些答案中的每个人都对我有所帮助。

此外,http 探测需要 return 200 状态。愚蠢的是,我的是 returning 一个 301。所以我只是添加了一个简单的“ping”端点,所有都是 well/healthy。

如果您不想更改 pod 规范,或者不希望依赖 GKE 的魔力来拉出您的 readinessProbe,您也可以像这样配置 BackendConfig 来显式配置健康检查。

如果您想为 readinessProbe 使用脚本(GKE 入口运行状况检查不支持),这也很有用。

请注意您的 Service 定义中的 BackendConfig needs to be explicitly referenced

---
apiVersion: v1
kind: Service
metadata:
  name: my-service
  namespace: my-namespace
  annotations:
    cloud.google.com/neg: '{"ingress":true}'
    cloud.google.com/backend-config: '{"default": "my-backendconfig"}'
spec:
  type: ClusterIP
  ports:
    - name: health
      port: 1234
      protocol: TCP
      targetPort: 1234
    - name: http
      ...
  selector:
    ...
---
apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: my-backendconfig
  namespace: my-namespace
spec:
  healthCheck:
    checkIntervalSec: 15
    port: 1234
    type: HTTP
    requestPath: /healthz