Liveness, Readiness, and Startup probes for containers in Kubernetes Pod

1 function of probe

Container life in Kubernetes sql tutorial In cycle management, there are three kinds of probes. First of all, you should know that these probes are java basic course Belonging to a container, not a Pod:

  • Survival probe: Liveness
  • Ready probe: Readiness
  • Start probe: Startup

The Liveness probe can tell when to weigh python basic tutorial Open the container. If the container is found to be unhealthy, it will be killed and a new container will be created.

The Readniess probe can know whether to access the container. If it is found that the container is unhealthy, it will not route the request to the container.

The Startup probe can know when the application container is started. If this kind of detector is configured, the container can be controlled to conduct survivability and readiness inspection after successful Startup to ensure that these detectors are alive and ready c# tutorial The manager does not affect the startup of the application. This can be used to detect the viability of slow start containers to prevent them from being killed before starting operation.

2 configuration example

2.1 survival

2.1.1 command mode

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:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5

2.1.2 HTTP mode

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/liveness
    args:
    - /server
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3

2.1.3 TCP mode

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:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 10
    livenessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 15
      periodSeconds: 20

2.2 Readiness

Similar to Liveness:

readinessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy
  initialDelaySeconds: 5
  periodSeconds: 5

2.3 use start detector vb.net tutorial Protect slow start container

Thanks to the startup probe, the application will have up to 5 minutes (30 * 10 = 300s) to complete its startup. Once the detection is started successfully once, the survival detection task will take over the detection of the container, and can respond quickly to the container deadlock. If the probe is not started successfully, the container will be killed after 300 seconds, and the Pod state will be set according to the restart policy.

ports:
- name: liveness-port
  containerPort: 8080
  hostPort: 8080

livenessProbe:
  httpGet:
    path: /healthz
    port: liveness-port
  failureThreshold: 1
  periodSeconds: 10

startupProbe:
  httpGet:
    path: /healthz
    port: liveness-port
  failureThreshold: 30
  periodSeconds: 10

3. Configuration of springboot application

Springboot # 2.3 adds a probe. The specific path is as follows:

Survival: / Actor / health / liveness

Ready: / Actor / health / readiness

You need to add an actor and open the corresponding function through attribute configuration:

management.endpoints.web.exposure.include="*"
management.health.livenessState.enabled=true
management.health.readinessState.enabled=true
management.endpoint.health.probes.enabled=true
management.endpoint.health.probes.show-details=always

Added by jstgermain on Wed, 19 Jan 2022 14:23:18 +0200