Kubernetes日志显示健康的应用程序,但ReadinessProbe失败

cnh2zyt3  于 2023-04-29  发布在  Kubernetes
关注(0)|答案(1)|浏览(661)

我的目标

将React应用部署到Kubernetes集群并从我的Web浏览器访问它。

设置

我正在将一个React应用打包到Docker容器中。在Docker容器中,我运行npm build,然后使用npm包serve提供静态文件。
然后,我使用Helm提取Docker镜像并将其部署到EKS集群。此时,我的日志显示容器是RunningAlive(请参阅下面的日志)。
问题
在EKS集群上,有一个Ingress,它将入站流量定向到服务(又名我的Docker容器)。然而,当我将浏览器指向主机URL时,我收到503错误。
我的理解是,流量是这样流动的:

(Inbound traffic) -> ingress.example.com:80 -> (docker container:8080)

我已经三次检查了我的清单上的端口Map。Yaml,但我完全迷路了。

日志

Kubernetes日志似乎显示部署是活跃的。..

Invoked Entrypoint..
generating cert and key for your application...
> web-app-2@0.1.0 start:prod /
> HOST=0.0.0.0 serve -s build -l 8080
INFO  Accepting connections at http://localhost:8080
HTTP  4/26/2023 7:56:12 PM 2600:1f18:664d:c501:48e1:f54e:7ced:a524 GET /health
HTTP  4/26/2023 7:56:12 PM 2600:1f18:664d:c501:48e1:f54e:7ced:a524 Returned 200 in 18 ms
HTTP  4/26/2023 7:56:17 PM 2600:1f18:664d:c501:48e1:f54e:7ced:a524 GET /health
HTTP  4/26/2023 7:56:17 PM 2600:1f18:664d:c501:48e1:f54e:7ced:a524 GET /health
HTTP  4/26/2023 7:56:17 PM 2600:1f18:664d:c501:48e1:f54e:7ced:a524 Returned 200 in 3 ms
HTTP  4/26/2023 7:56:17 PM 2600:1f18:664d:c501:48e1:f54e:7ced:a524 Returned 200 in 3 ms
// and so on...

但是运行kubectl describe表明就绪探测失败,尽管/health端点返回200 OK

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  41m                default-scheduler  Successfully assigned NAMESPACE/health-react-react-webapp-cbdbc576c-wjk7p to ip-123-123-123-123.ec2.internal
  Normal   Pulling    41m                kubelet            Pulling image IMAGE_NAME
  Normal   Pulled     41m                kubelet            Successfully pulled image IMAGE_NAME in 153.428514ms
  Normal   Created    41m                kubelet            Created container react-webapp
  Normal   Started    41m                kubelet            Started container react-webapp
  Warning  Unhealthy  41m (x2 over 41m)  kubelet            Readiness probe failed: Get "http://[IPV6_ADDRESS]:8080/health": dial tcp [IPV6_ADDRESS]:8080: connect: connection refused

我的manifest.yaml(由helm install --debug生成)

NAME: health-react
LAST DEPLOYED: Wed Apr 26 16:30:28 2023
NAMESPACE: REDACTED
STATUS: pending-install
REVISION: 1

MANIFEST:
---
# Source: react-webapp/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: health-react-react-webapp
  labels:
    helm.sh/chart: react-webapp-0.1.0
    app.kubernetes.io/name: react-webapp
    app.kubernetes.io/instance: health-react
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm
---
# Source: react-webapp/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
  name: health-react-react-webapp
  namespace: NAMESPACE
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      targetPort: 8080
      protocol: TCP
  selector:
    app.kubernetes.io/name: react-webapp
    app.kubernetes.io/instance: health-react
    type: ClusterIP
---
# Source: react-webapp/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: health-react-react-webapp
  labels:
    helm.sh/chart: react-webapp-0.1.0
    app.kubernetes.io/name: react-webapp
    app.kubernetes.io/instance: health-react
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: react-webapp
      app.kubernetes.io/instance: health-react
  template:
    metadata:
      labels:
        app.kubernetes.io/name: react-webapp
        app.kubernetes.io/instance: health-react
    spec:
      imagePullSecrets:
        - name: ricky-cred
      serviceAccountName: health-react-react-webapp
      securityContext:
        {}
      containers:
        - name: react-webapp
          securityContext:
            {}
          image: "REDACTED"
          imagePullPolicy: Always
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
          resources:
            {}
---
# Source: react-webapp/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: health-react-react-webapp
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  namespace: NAMESPACE
spec:
  ingressClassName: 
  rules:
    - host: ingress.example.com
      http:
        paths:
          - path: /virtualization-web(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: health-react-react-webapp
                port:
                  number: 80
hec6srdp

hec6srdp1#

你描述的是两个不同的问题,所以让我们一个接一个地解决它们。

问题1:不健康的Pod

正如您从日志中发现的那样,您的pod实际上没有问题。在describe的输出中看到的是过去所有探测的结果,所以如果一个探测失败,您将在那里看到,特别是如果它是最近的一个探测。所以在你的例子中,你可以看到两个探测器在最后41米失败了。这不是您的pod的当前状态。下面是一个例子,我的pod过去有问题,但现在很好:

Events:
  Type     Reason          Age                   From     Message
  ----     ------          ----                  ----     -------
  Normal   Pulling         4h12m (x15 over 18h)  kubelet  Pulling image "quay.io/rira12621/single-arch-amd64"
  Normal   Created         4h12m (x15 over 18h)  kubelet  Created container single-wrong-arch
  Normal   Started         4h12m (x15 over 18h)  kubelet  Started container single-wrong-arch
  Normal   Pulled          4h12m                 kubelet  Successfully pulled image "quay.io/rira12621/single-arch-amd64" in 1.696594293s (1.696604668s including waiting)
  Warning  FailedMount     83s                   kubelet  MountVolume.SetUp failed for volume "kube-api-access-qcgg7" : failed to sync configmap cache: timed out waiting for the condition
  Normal   SandboxChanged  82s                   kubelet  Pod sandbox changed, it will be killed and re-created.
  Normal   Pulling         81s                   kubelet  Pulling image "quay.io/rira12621/single-arch-amd64"
  Normal   Pulled          79s                   kubelet  Successfully pulled image "quay.io/rira12621/single-arch-amd64" in 2.186910459s (2.18691371s including waiting)
  Normal   Created         79s                   kubelet  Created container single-wrong-arch
  Normal   Started         79s                   kubelet  Started container single-wrong-arch

再往上一点,输出当前状态:

Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True

第2期:连接失败

你需要仔细检查你的配置。这是一个混合和匹配。
除非我读错了你的描述,否则你的pod的端口规格是错误的:

ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
          readinessProbe:
            httpGet:
              path: /health
              port: 8080

根据示意图,您的应用程序也在监听8080上的常规流量,而不是80。

相关问题