首页 > 解决方案 > Liveness Probe 被计时

问题描述

我正在使用 Jenkins 和 Kubernetes 来执行此操作。

由于我的 loadBalancer 需要一个健康的 pod,我不得不将 livenessProbe 添加到我的 pod 中。

我对 Pod 的配置:

apiVersion: v1
kind: Pod
metadata:
labels:
  component: ci
spec:
  # Use service account that can deploy to all namespaces
  serviceAccountName: default
  # Use the persisnte volume
  containers:
  - name: gcloud
    image: gcr.io/cloud-builders/gcloud
    command:
    - cat
    tty: true
  - name: kubectl
    image: gcr.io/cloud-builders/kubectl
    command:
    - cat
    tty: true
  - name: liveness
    image: k8s.gcr.io/busybox
    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

发生的问题是当我想部署代码(CD over Jenkins)时,它涉及到

/tmp/健康;

命令,它已超时。

我得到的错误响应如下所示:

java.io.IOException: Failed to execute shell script inside container [kubectl] of pod [wobbl-mobile-label-qcd6x-13mtj]. Timed out waiting for the container to become ready!

当我输入kubectl get events时 ,我得到以下响应:

Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory

关于如何解决这个问题的任何提示?

我已阅读此文档以了解其活性,并从那里获取了它的配置。

标签: jenkinskubernetesgoogle-compute-enginegoogle-kubernetes-engine

解决方案


从您所指的链接可以看出。该示例旨在帮助您了解活性探针的工作原理。我从这个链接下面的例子

他们故意删除 /tmp/healthy 文件后

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/busybox
    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

它的作用是在创建容器时创建 /tmp/healthy 文件。5 秒后,活性探针启动并检查 /tmp/healthy 文件,此时容器确实存在 /tmp/healthy 文件。30 秒后,它会删除文件,并且 liveness 探测无法找到 /tmp/healthy 文件并重新启动容器。此过程将继续进行,并且每 30 秒后,liveness probe 将无法通过健康检查。

如果你只添加

  • 触摸/tmp/健康

活性探针应该可以正常工作


推荐阅读