Google Kubernetes Ingress 健康检查总是失败

Google Kubernetes Ingress health check always failing

我已经在端口 80 上配置了一个通过 apache 公开的 Web 应用程序 pod。我无法配置服务 + 入口以从 Internet 访问。问题是后端服务总是报告为不健康。

Pod 配置:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    name: webapp
  name: webapp
  namespace: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: webapp
  template:
    metadata:
      labels:
        name: webapp
    spec:
      containers:
      - image: asia.gcr.io/my-app/my-app:latest
        name: webapp
        ports:
        - containerPort: 80
          name: http-server

服务配置:

apiVersion: v1
kind: Service
metadata:
  name: webapp-service
spec:
  type: NodePort
  selector:
    name: webapp
  ports:
    - protocol: TCP
      port: 50000
      targetPort: 80

入口配置:

kind: Ingress
metadata:
  name: webapp-ingress
spec:
  backend:
    serviceName: webapp-service
    servicePort: 50000

这导致后端服务报告为不健康。

健康检查设置:

Path: /
Protocol: HTTP
Port: 32463
Proxy protocol: NONE

其他信息:我尝试了一种不同的方法,将部署公开为具有外部 IP 的负载平衡器,并且效果很好。尝试使用 NodePort + Ingress 时,此问题仍然存在。

使用 GKE,在创建入口时会自动创建负载均衡器的运行状况检查。由于 HC 是自动创建的,因此防火墙规则也是如此。

由于您没有配置 readinessProbe,LB 已创建默认 HC(您列出的那个)。要正确调试,您需要隔离故障点。

首先,确保您的广告连播正常提供流量;

kubectl exec [pod_name] -- wget localhost:80

如果应用程序内置了 curl,您可以使用它来代替 wget。 如果应用程序既没有 wget 也没有 curl,请跳到下一步。

  1. 获得以下输出并跟踪输出:

    kubectl get po -l name=webapp -o wide
    kubectl get svc webapp-service

您需要保留服务和 pod clusterIPs

  1. 通过 SSH 连接到集群中的一个节点并且 运行 sudo toolbox bash

  2. 安装curl:

apt-get install curl`

  1. 测试 pods 以确保它们正在为集群内的流量提供服务:

curl -I [pod_clusterIP]:80

这需要 return 200 响应

  1. 测试服务:

curl -I [service_clusterIP]:80

如果 pod 未 return 发出 200 响应,则容器无法正常工作或 pod 上的端口未打开。

如果 pod 正在运行但服务没有运行,则由 kube-proxy 管理的 iptables 中的路由存在问题,这将是集群的问题。

最后,如果 pod 和服务都在工作,则负载均衡器健康检查存在问题,也是 Google 需要调查的问题。