K8S哲学 - probe 探针

探针分类:

liveness probe

readiness probe

startup probe

  1. Liveness Probe:用于检查容器是否还在运行。如果 Liveness Probe 失败,Kubernetes 会杀死容器,然后根据你的重启策略来决定是否重新启动容器。常见的做法是使用与 Readiness Probe 相同的低成本 HTTP 端点,但是设置更高的 failureThreshold,这样可以确保在 Pod 被强制杀死之前,它会被观察到为 not-ready 一段时间。

  2. Readiness Probe:用于检查容器是否准备好接受流量。一个 Pod 被认为是 ready 的,当且仅当它的所有容器都是 ready 的。这个信号的一个用途是控制哪些 Pod 被用作 Service 的后端。当一个 Pod 不是 ready 的,它会从 Service 的负载均衡器中移除。

  3. Startup Probe:用于检查容器应用程序是否已经启动。如果配置了这样的探针,那么在它成功之前,Liveness Probe 和 Readiness Probe 不会开始,确保这些探针不会干扰应用程序的启动。这可以用于对慢启动的容器进行 Liveness 检查,避免它们在启动并运行之前被 kubelet 杀死。

探测方式

HTTPGetAction

TCPSocketAction

ExecAction

每种探针都可以使用以下三种方式之一进行检查:

  • HTTP GET:对容器的一个 HTTP 服务器发起一个 GET 请求。如果服务器返回的状态码在 200 到 399 之间,那么探针就是成功的。

  • TCP Socket:尝试打开容器的一个 TCP 端口。如果端口已经打开,那么探针就是成功的。

  • Exec:在容器中执行一个命令。如果命令返回 0,那么探针就是成功的。

 

ERROR: The Pod "app" is invalid: spec.containers[0].livenessProbe.successThreshold: Invalid value: 3: must be 1

对于 Liveness 探针,successThreshold 的值必须为 1。这是因为 Liveness 探针只需要一次成功的探测就能确定容器是存活的。所以,你需要将 successThreshold 的值改为 1。

apiVersion: v1
kind: Pod
metadata:
  name: 'app'
  labels: 
    name: 'zs'
    age: '18'
spec:
 containers:
  - name: 'probe-po'
    image: nginx:1.14.2
    livenessProbe:
      httpGet:
        path: /index.html
        port: 80
      initialDelaySeconds: 5
      periodSeconds: 5
      timeoutSeconds: 5
      failureThreshold: 3
      successThreshold: 1
    

这时 如果将 index.html 改成 index1.html 

 livenessProbe 采用 tcpSocket

apiVersion: v1
kind: Pod
metadata:
  name: 'app'
  labels: 
    name: 'zs'
    age: '18'
spec:
 containers:
  - name: 'probe-po'
    image: nginx:1.14.2
    livenessProbe:
      # httpGet:
      #   path: /index1.html
      #   port: 80
      # initialDelaySeconds: 5
      # periodSeconds: 5
      # timeoutSeconds: 5
      # failureThreshold: 3
      # successThreshold: 1
        tcpSocket:
         port: 80
        periodSeconds: 5
        successThreshold: 1
        failureThreshold: 3

              
    

livenessProbe 采用 exec

apiVersion: v1
kind: Pod
metadata:
  name: 'app'
  labels: 
    name: 'zs'
    age: '18'
spec:
 containers:
  - name: 'probe-po'
    image: nginx:1.14.2
    livenessProbe:
      # httpGet:
      #   path: /index1.html
      #   port: 80
      # initialDelaySeconds: 5
      # periodSeconds: 5
      # timeoutSeconds: 5
      # failureThreshold: 3
      # successThreshold: 1

        # tcpSocket:
        #  port: 89
        # periodSeconds: 5
        # successThreshold: 1
        # failureThreshold: 3
        exec:
          command: ['cat', '/usr/share/nginx/html/index.html']
            # - cat
            # - /usr/share/nginx/html/index.html
        successThreshold: 1
        failureThreshold: 3
        timeoutSeconds: 3
        periodSeconds: 3
              
    

改成 index1.html

配置 livenessProbe readinessProbe startupProbe

apiVersion: v1
kind: Pod
metadata:
  name: 'app'
  labels: 
    name: 'zs'
    age: '18'
spec:
 containers:
  - name: 'probe-po'
    image: nginx:1.14.2
    livenessProbe:
      # httpGet:
      #   path: /index1.html
      #   port: 80
      # initialDelaySeconds: 5
      # periodSeconds: 5
      # timeoutSeconds: 5
      # failureThreshold: 3
      # successThreshold: 1

        # tcpSocket:
        #  port: 89
        # periodSeconds: 5
        # successThreshold: 1
        # failureThreshold: 3
        exec:
          command: ['cat', '/usr/share/nginx/html/index1.html']
            # - cat
            # - /usr/share/nginx/html/index.html
        successThreshold: 1
        failureThreshold: 3
        timeoutSeconds: 3
        periodSeconds: 3
    readinessProbe: 
      httpGet: 
        path: /index.html
        port: 80
      failureThreshold: 3
      successThreshold: 1 
      timeoutSeconds: 3
      periodSeconds: 3
    startupProbe: 
       httpGet:
        path: /index.html
        port: 80
       failureThreshold: 3
       successThreshold: 1
       timeoutSeconds: 3
       periodSeconds: 3
      
        
              
    

 

相关推荐

  1. K8S 哲学 - yaml文件

    2024-04-20 13:58:03       11 阅读
  2. <span style='color:red;'>k</span><span style='color:red;'>8</span><span style='color:red;'>s</span><span style='color:red;'>探针</span>

    k8s探针

    2024-04-20 13:58:03      37 阅读
  3. k8s探针

    2024-04-20 13:58:03       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-20 13:58:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-20 13:58:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-20 13:58:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-20 13:58:03       18 阅读

热门阅读

  1. ubuntu20.04手动编译opencv 4.9.0遇到的问题汇总

    2024-04-20 13:58:03       38 阅读
  2. C#Tcp简单使用

    2024-04-20 13:58:03       14 阅读
  3. python爬虫之POST和GET方法总结(6)

    2024-04-20 13:58:03       9 阅读
  4. Docker的使用技巧

    2024-04-20 13:58:03       14 阅读
  5. vue3:自定义组件使用v-model

    2024-04-20 13:58:03       13 阅读
  6. python中的设计模式:单例模式

    2024-04-20 13:58:03       13 阅读
  7. windows用bat脚本将nginx安装为服务

    2024-04-20 13:58:03       11 阅读
  8. python应用

    2024-04-20 13:58:03       11 阅读