Liveness and Readiness Probes

Probes: Allow you to customize how Kubernetes determines the status of your containers.

Liveness probe: Indicates whether the container is running properly, and governs when the cluster will automatically stop or restart the container.

  • If the containers crash and stop running, Kubernetes is automatically going to detect that it will restart the container, but sometimes you need a little bit of customization that you may need to detect to wheater the container is healthy.

Readiness probe: Indicates whether the container is ready to service requests, and governs whether requests will be forwarded to the pod.

  • It is similar to Liveness probe, but while Liveness probe detects the current health status of the pod, Readiness probe detects whether or not the pod to ready to receive the request.
  • * A lot of containers take time to start up even once the container is running it may take a little bit of time before the container is actually ready to start process requests from the users.

Liveness and readiness probes can determine container status by doing things like running a command or making an http request.

Liveness

apiVersion: v1
kind: Pod
metadata:
  name: my-liveness-pod
spec:
  containers:
    - name: myapp-container
      image: busybox
      command: ["sh", "-c", "echo Hello, Kubernetes! && sleep 36"]
      livenessProbe:
        exec:
          command:
            - echo
            - testing
        initialDelaySeconds: 5
        periodSeconds: 5
  • After 36 seconds, complete the container, however, because of LivenessProbe it will restart the container.
NAME                                READY   STATUS    RESTARTS   AGE
my-liveness-pod                     1/1     Running   2          2m
  • The number of RESTARTS will continually increase.

Readiness

apiVersion: v1
kind: Pod
metadata:
  name: my-readiness-pod
spec:
  containers:
  - name: myapp-container
    image: nginx
    readinessProbe:
      httpGet:
        path: /
        port: 80
      initialDelaySeconds: 5
      periodSeconds: 5

Leave a Reply

Your email address will not be published.

ANOTE.DEV