Several probes of k8s

Refer to the official documentation: https://kubernetes.io/zh/docs/concepts/workloads/pods/pod-lifecycle/#container-probes

liveness probe - livenessProbe

Indicates whether the container is running. If the liveness probe fails, the kubelet will kill the container and the container will decide the future according to its restart policy. If the container does not provide a liveness probe, the default state is Success.


Defining Probe Survival Commands

Reference: Defining Probe Live Commands

Inspection mechanism


exec liveness check example

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
    - name: liveness
      image: k8s.gcr.io/busybox
      args:
        - /bin/sh
        - -c
        - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600

      # 配置存活探针
      livenessProbe:
        # 在容器内执行指定命令,如果命令退出时返回码为 0 则认为诊断成功。
        exec:
          command:
            - cat
            - /tmp/healthy
        # 容器初始化延迟秒数(多少秒后开始检查存活)
        initialDelaySeconds: 5
        # 多少秒执行一次存活指令
        periodSeconds: 5

httpGet liveness check example

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
    - name: liveness
      image: k8s.gcr.io/liveness
      args:
        - /server

      # 配置存活探针
      livenessProbe:
        # 执行httpget请求
        httpGet:
          # 请求的路径
          path: /healthz
          # 请求的端口
          port: 8080
          # 添加自定义请求头
          httpHeaders:
            # 添加字段
            - name: Custom-Header
              # 添加字段的值
              value: Awesome
        # 容器初始化延迟秒数
        initialDelaySeconds: 3
        # 多少秒检查一次存活
        periodSeconds: 3

Readiness Probe - readinessProbe

Indicates whether the container is ready to serve requests. If the readiness probe fails, the endpoint controller removes the Pod's IP address from the endpoint list of all services that match the Pod. The state value of the ready state before the initial delay defaults to Failure. If the container does not provide a readiness probe, the default state is Success.


tcpSocket readiness probe and liveness probe example

tcpSocketThe principle is a bit like telnet ip地址 端口号, check whether the port is open.

apiVersion: v1
kind: Pod
metadata:
  name: goproxy
  labels:
    app: goproxy
spec:
  containers:
    - name: goproxy
      image: k8s.gcr.io/goproxy:0.1
      ports:
        - containerPort: 8080

      # 配置就绪探针
      readinessProbe:
        # 使用tcp端口检查方式配置就绪探针
        tcpSocket:
          # 检查8080端口是否开放
          port: 8080
        # 容器初始化延迟秒数
        initialDelaySeconds: 5
        # 多少秒执行一次就绪检查
        periodSeconds: 10

      # 配置存活探针
      livenessProbe:
        # 使用tcp端口检查方式配置存活探针,类似于telnet
        tcpSocket:
          # 检查8080端口是否开放
          port: 8080
        # 容器初始化延迟秒数
        initialDelaySeconds: 15
        # 多少秒执行一次存活检查
        periodSeconds: 20

startup probe - startupProbe

Indicates whether the application in the container has been started. If a startup probe is provided, all other probes are disabled until this probe succeeds. If the startup probe fails, the kubelet will kill the container and the container will restart according to its restart policy. If the container does not provide a startup probe, the default state is Success.


Guess you like

Origin blog.csdn.net/omaidb/article/details/121802883