Health probe

Kubernetes comes with two types of probes
livenessProbe and readinessProbe


The livenessProbe checks the health of the container in the following three ways

  • Through the HTTP get request, the expected response code is 200-399
  • TCP socket connection succeeded
  • Exec calls the command with exit code 0

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 30

Containers that fail to pass the livenessProbe check will be restarted and will only be restarted
The check methods of the ready probe are the same as HTTP, command and TCP, but the readinessProbe will not restart the container, but prevent the container from receiving requests

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 30
        readinessProbe:
          httpGet:
            path: /
            port: 801
            scheme: HTTP
          initialDelaySeconds: 30
Send a Message