【问题标题】:How to define a liveness command如何定义一个 liveness 命令
【发布时间】:2018-01-20 17:11:55
【问题描述】:

下面的 livenessProbe(提取自 an example)运行良好。

livenessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy

但是,我的 livenessProbe 无法正常工作。(pod 不断重启)。 YAML 在下面

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness-test
  name: liveness
spec:
  containers:
  - name: liveness
    args:
    - /bin/bash
    - -c
    - /home/my_home/run_myprogram.sh; sleep 20
    image: liveness:v0.6
    securityContext:
      privileged: true
    livenessProbe:
      exec:
        command:
        - /home/my_home/check.sh
      initialDelaySeconds: 10
      periodSeconds: 5

/home/my_home/check.sh(在运行进程数为1或0时重新启动pod)低于,这是预先测试的。

#!/bin/sh
if [ $(ps -ef | grep -v grep | grep my-program | wc -l) -lt 2 ]; then
  exit 1
else
  exit 0
fi

【问题讨论】:

    标签: kubernetes kubernetes-health-check


    【解决方案1】:

    此问题与Golang Command API 有关。 我将 livenessProbe 更改如下

    livenessProbe:
      exec:
        command:
        - /bin/sh
        - -c
        - /home/test/check.sh
    

    【讨论】:

    • 上述方法有效,但是如果我们在 sidecar 容器中使用相同的方法,它会指出: Liveness probe failed: OCI runtime exec failed: exec failed: container_linux.go:345: started container process caused "exec: \ “/bin/sh /opt/test/check.sh\”:stat /bin/sh /opt/test/check.sh:没有这样的文件或目录“:未知。你能提出什么问题吗?
    猜你喜欢
    • 2018-05-10
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2022-01-24
    相关资源
    最近更新 更多