My latest and most complete articles are in the pumpkin slow say www.pkslow.com, welcome to tea!

1 Functions of the probe

In Kubernetes container lifecycle management, there are three types of probes, first of all, it is important to know that the probes belong to the container, not the Pod:

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

The Liveness probe knows when to restart a container, and if it is found to be unhealthy, it kills and creates a new container from scratch.

The Readniess probe can know whether to access the container or not, and if it is found to be unhealthy, it will not route requests to that container.

The Startup probe knows when the application container is started. If such detectors are configured, you can control the container to perform viability and readiness checks after successful startup to ensure that these live, ready detectors do not affect application startup. This can be used to detect the viability of slow-start containers to prevent them from being killed before they are up and running.

2 Configuration Example

2.1 live Liveness

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
Copy the code

2.1.2 HTTP

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
Copy the code

2.1.3 TCP way

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
Copy the code

2.2 ready Readiness

Similar to Liveness:

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

2.3 Protect slow start containers with start detectors

Thanks to startup probes, the application will have up to 5 minutes (30 * 10 = 300s) to complete its startup. Once a probe is successfully initiated, the survival probe task takes over the probe of the container and can quickly respond to container deadlocks. If the probe is never started successfully, the container is killed after 300 seconds and the Pod status is set according to the restartPolicy.

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
Copy the code

3 Springboot application configuration

Springboot 2.3 has added probes. The specific paths are as follows:

Survival: / physical/health/liveness

Ready: / physical/health/readiness

Add the actuator and use the following properties to enable the corresponding functions:

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
Copy the code

Welcome to pay attention to the wechat public number “Pumpkin slow Talk”, will continue to update for you…

Read more and share more; Write more. Organize more.