如何在 Kubernetes 中设置 liveness/readiness 探测的频率

How to set the frequency of a liveness/readiness probe in Kubernetes

liveness/readiness 探针中的探针频率可以自定义吗?

此外,在将 pod 从服务负载均衡器中删除之前,就绪性探测失败了多少次?是否可定制?

探测频率由 Kubelet 上的 sync-frequency 命令行标志控制,默认为每 10 秒同步一次 pod 状态。

我不知道有什么方法可以自定义在 pod 被视为未准备好服务流量之前所需的失败探测次数。

如果这些功能中的任何一个对您很重要,请随时 open an issue explaining what your use case is or send us a PR! :)

您可以轻松自定义探针故障阈值和频率,所有参数均已定义here。 例如:

      livenessProbe:
        failureThreshold: 3
        httpGet:
          path: /health
          port: 9081
          scheme: HTTP
        initialDelaySeconds: 180
        timeoutSeconds: 10
        periodSeconds: 10
        successThreshold: 1

该探测器将在 3 分钟后第一次 运行,每 10 秒将 运行,并且 pod 将在连续 3 次失败后重新启动。

要自定义 liveness/readiness 探测频率和其他参数,我们需要在与该 pod 关联的 yaml 的容器元素中添加 liveness/readiness 元素。 yaml文件的一个简单示例如下:

apiVersion: v1
kind: Pod
metadata:
  name: liveness-exec
spec:
  containers:
  - name: liveness-ex
    image: ubuntu
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy;sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5

initialDelaySeconds 参数确保在容器启动 5 秒后检查活动探测器,periodSeconds 确保每 5 秒检查一次。有关更多参数,您可以转到 link : https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/