Skip to content

Kubernetes container probes

Kubernetes container probes are diagnostic mechanisms performed by the kubelet to determine the state of containers running within a Pod. These probes enable self-healing and traffic management by allowing the cluster to detect and react to unresponsive or uninitialized applications.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]

Kubernetes supports four types of handlers (actions) used to perform the diagnostics, and three specific types of probes that dictate how the system reacts to the results.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]

Probe Handlers (Detection Methods)

The handler defines the specific action taken to perform the check. kubelet supports four diagnostic methods:

  • Exec Action: Executes a specified command inside the container. The diagnostic is considered successful if the command exits with status code 0.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]
  • TCPSocket Action: Performs a TCP check against the container's IP address on a specified port. The diagnostic is successful if the port is open.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]
  • HTTPGet Action: Performs an HTTP GET request against the container's IP address on a specified port and path. The diagnostic is successful if the response status code is between 200 and 399.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]
  • gRPC Action: Available from v1.24, this performs a check using gRPC on the container's IP address. It requires a specific port to be configured.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]

Types of Probes

The probe type determines the behavior and consequences of the diagnostic result.

Liveness Probe

The liveness probe indicates whether the container is running normally.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md] If this probe fails, the kubelet terminates the container, and the container is subjected to the Pod's [[restartPolicy]] to be restarted.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md] This mechanism is primarily used to catch deadlocks or situations where the application is running but unable to make progress.

Readiness Probe

The readiness probe indicates whether the container is ready to serve traffic.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md] If this probe fails, the Endpoint Controller removes the Pod's IP address from the list of matching Service Endpoints.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md] This ensures that network traffic is not routed to the Pod until it is fully prepared to handle it.

Startup Probe

The startup probe indicates whether the application within the container has started.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md] If a startup probe is configured, all other probes are disabled until the startup probe succeeds, allowing slow-starting containers time to initialize without being killed by the liveness probe.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md] If this probe fails, the kubelet terminates the container, which is then handled according to the restart policy.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]

Configuration

Probes are configured within the spec.containers section of a Pod definition. Key configuration fields include:

  • initialDelaySeconds: The time to wait after the container starts before initiating the first probe.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]
  • periodSeconds: The frequency at which the probe is performed.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]
apiVersion: v1
kind: [Pod](<./pod.md>)
metadata:
  name: 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

Sources

  • 400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md