kubelet如何使用livelinessProbe exec命令完成logstash容器

问题描述

我有一个多容器应用程序,它是应用程序(执行 cronjob)+ logstash。 Cronjob 容器执行 java 进程,并在完成后在共享文件系统即 /usr/share/example/config/pod/done 写入文件。 Logstash 容器(docker logstash 镜像)启动用于弹性搜索的 API 端点,并从主容器读取日志并发送给 elasticSearch。因为,一旦作业完成,cronjob 容器就会完成,但 logstash 容器继续运行,因为它不知道它现在必须停止运行,所以我尝试使用 livelinessProbe exec 块来通知 logstash 容器退出容器。

name: logstash
image: docker.elastic.co/logstash/logstash:7.10.2
imagePullPolicy: IfNotPresent
livenessProbe:
  exec:
    command:
    - /bin/sh
    - -c
    - |
      if [ -f /usr/share/logstash/config/pod/done ]; then
        echo "file exists"
        exit 0
      else
        echo "file doesn't exists"
      fi
  failureThreshold: 3
  initialDelaySeconds: 5
  periodSeconds: 5
  successthreshold: 1
  timeoutSeconds: 1

我尝试了上面的代码块,但注意到这些 livelinessProbe 命令没有被执行,我的 logstash 容器一直在运行,这使我的 pod 处于“未准备好”状态。

如果有人可以帮助我了解如何从 livelinessProbe 执行命令,以便它向我的 logstash 容器发出停止运行的信号,我将不胜感激?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)