【问题标题】:Kubernetes - Readiness probe not working for deploymentKubernetes - 准备探测不适用于部署
【发布时间】:2019-08-07 02:05:22
【问题描述】:

谁能告诉我部署的 yaml 文件有什么问题。当我删除就绪探测时,我可以在kubectl get deployments 中看到我的部署可用。但是使用就绪探测,它仍然不可用,如下所示。

NAME           DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
neg-demo-app   1         1         1            0           2m33s

下面是我的yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: neg-demo-app # Label for the Deployment
  name: neg-demo-app # Name of Deployment
spec: # Deployment's specification
  minReadySeconds: 60 # Number of seconds to wait after a Pod is created and its status is Ready
  selector:
    matchLabels:
      run: neg-demo-app
  template: # Pod template
    metadata:
      labels:
        run: neg-demo-app # Labels Pods from this Deployment
    spec: # Pod specification; each Pod created by this Deployment has this specification
      containers:
      - image: container_name  # Application to run in Deployment's Pods
        name: hostname # Container name
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
      terminationGracePeriodSeconds: 60 # Number of seconds to wait for connections to terminate before shutting down Pods

【问题讨论】:

  • 请提供更多信息。如果添加了就绪探测,pod 事件是什么?
  • 你的容器在/healthz端点上返回200吗?

标签: kubernetes google-compute-engine readinessprobe


【解决方案1】:

我认为你已经添加了

minReadySeconds: 60 # Number of seconds to wait after a Pod is created and its status is Ready

minReadySeconds 是一个可选字段,用于指定最小值 新创建的 Pod 准备就绪的秒数 没有任何容器崩溃,可以考虑 可用的。此默认值为 0(Pod 将被视为可用 准备好后)。

So your newly created app pod have to be ready for minReadySeconds 60 seconds to be considered as available.


initialDelaySeconds: Number of seconds after the container has started before liveness or readiness probes are initiated.

所以 initialDelaySeconds 在 minReadySeconds 之前。

container in the pod has started at 5 seconds. Readiness probe will be initiated at 5+initialDelaySeconds seconds. Assume Pod become ready at 7 seconds(7 > 5+initialDelaySeconds). So this pod will be available after 7+minReadySeconds seconds.

请尝试在 rediness 探针和 liveness 探针中添加initialDelaySeconds,否则请尝试删除minReadySeconds

【讨论】:

  • 如果 301 在 rediness 探针末端,则与 200-300 无关。如果您可以进入 pod 并尝试 curl:localhost:8080/healthz 或使用 kubectl describe 检查 pod 的描述,则可能存在应用程序方面的问题。
  • 谢谢。我的应用程序没有响应该端点。但是我的入口服务处于不健康状态。我已经为此打开了另一个问题,如果你可以请看一下。 stackoverflow.com/questions/57396949/…
猜你喜欢
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
  • 1970-01-01
  • 2021-08-02
  • 1970-01-01
  • 1970-01-01
  • 2018-11-27
  • 2023-03-18
相关资源
最近更新 更多