微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Kubernetes:如何使用具有管道的 Exec 编写 livenessprobe 和 readinessprobe

如何解决Kubernetes:如何使用具有管道的 Exec 编写 livenessprobe 和 readinessprobe

我正在使用 Exec 探针添加活性探针和就绪探针。
我的配置是这样的:

readinessProbe:
    exec:
      command: "/usr/bin/jps -l | grep QueueProcess"
    periodSeconds: 10 
    failureThreshold: 2
    successthreshold: 2

当上述方法不起作用时。我修改了这个并尝试过:

readinessProbe:
     exec:
       command: ["/usr/bin/jps","-l","|","grep","QueueProcess"]
     periodSeconds: 10 
     failureThreshold: 2
     successthreshold: 2

在运行 kubectl describe pod 时,得到以下输出

  normal   Created           37s                  kubelet             Created container app1
  normal   Started           37s                  kubelet             Started container app1
  Warning  Unhealthy         6s (x3 over 26s)     kubelet             Readiness probe Failed: invalid argument count
usage: jps [-help]
       jps [-q] [-mlvV] [<hostid>]

DeFinitions:
    <hostid>:      <hostname>[:<port>]

我尝试了另一个应用程序,我在其中运行 grpcurl调用健康检查:

readinessProbe:
    exec:
      command: ["grpcurl","-plaintext","-protoset","/app/HealthCheck.protoset","localhost:8123","service.HealthCheckService/GetHealthCheck","jq",".","200"]
    periodSeconds: 10 
    failureThreshold: 2
    successthreshold: 2

在运行 kubectl describe pod 时,我得到:

  normal   Created           23s                kubelet             Created container app2
  normal   Started           23s                kubelet             Started container app2
  Warning  Unhealthy         3s (x2 over 13s)   kubelet             Readiness probe Failed: Too many arguments.
Try 'grpcurl -help' for more details.

这两个都失败了。 问题是,如何编写一个 Exec probe,其中包含一个管道(或多个管道)?

我使用的是 EKS v1.18。
(以上两个配置属于不同的应用。)

解决方法

您需要实际使用外壳,因为这是外壳功能。 sh -c "foo | bar" 之类的。还要记住,所有相关命令都需要在目标图像中可用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。