linux - 如何否定要在 Kubernetes livenessProbe 中使用的退出代码状态?

标签 linux kubernetes grep centos livenessprobe

如何否定要在 Kubernetes 中使用的退出代码状态livenessProbe ?
我将使用 grep命令,我想在下面做一个检查。

  • 返回退出值 0,如果 grep没有命中
  • 返回退出值 1,如果 grep成功了

  • 由于通常情况下,如果有命中,grep 将返回 0,我可以否定这个,如下所示?
    !$(cat filet.txt | grep keyword)
    

    最佳答案

    是的,你可以试试
    例子 :

        livenessProbe:
      exec:
        command:
        - /bin/bash
        - -c
        - cat filet.txt | grep keyword
      initialDelaySeconds: 10
      periodSeconds: 10
    
    如果有帮助,您应该结帐
    -v, --invert-match
              Invert the sense of matching, to select non-matching lines.
    
    你也可以试试-c
    echo 'Test' | grep -c T
    
    1
    echo 'Test' | grep -c N
    
    0
    外壳脚本
    #!/bin/sh
    if [ $(echo 'Test' | grep -c T) ]; then
      exit 1
    else
      exit 0
    fi
    
    最简单的方法是编写 shell 脚本并根据需要管理事件的退出代码 0 或 1,并且基于该事件将重新启动 pod。
    livenessProbe:
      exec:
        command:
        - /bin/sh
        - -c
        - /home/test/health.sh
    

    关于linux - 如何否定要在 Kubernetes livenessProbe 中使用的退出代码状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69293621/

    相关文章:

    linux - 使用grep在文件中查找多个字符串

    linux - AWK : matching two files by first column doesn't work

    c - C 中的动态 execlp

    c - 段错误(核心转储)错误 C linux 套接字

    kubernetes - 使用gitRepo的Kubernetes卷用于特定文件

    amazon-web-services - Prometheus警报管理器不发送警报k8s

    docker - Kubernetes 与 Docker : What Does It Really Mean?

    bash - 从 grep 中获取空白字符到数组中

    awk - 外壳脚本: How to split line?

    linux - int execle(const char *path, const char *arg, ..., char * const envp[]);