Home > Software design >  In Kubernetes, why does readinessProbe have the option periodSeconds?
In Kubernetes, why does readinessProbe have the option periodSeconds?

Time:12-07

I understand what a readinessProbe does, but I don't see why it should have a periodSeconds. Once it's determined that the pod is ready, it should stop checking. Wouldn't checking periodically then be up to the livenessProbe? Or am I missing something?

CodePudding user response:

As per the official doc Many applications running for long periods of time eventually transition to broken states, and cannot recover except by being restarted. Kubernetes provides liveness probes to detect and remedy such situations.This periodSeconds field specifies that the kubelet should perform a liveness probe/readiness probe for every “x” seconds that mention the yaml.

For Example : YAML reference from official doc.

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: registry.k8s.io/busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5

As per the above YAML, The periodSeconds field specifies that the kubelet should perform a liveness probe every 5 seconds.

You can also have a look into this doc.

CodePudding user response:

ReadinesProbe and livenessProbe serve for different purposes.

ReadinessProbe checks if a service is ready to serve requests. If the readinessProbe fails, the container will be taken out of service for as long as the probe fails. If the readinessProbe reports up again, the container will be taken back into service again and receive requests.

In contrast, if the livenessProbe fails, it will be considered as not recoverable and the container will be terminated and restarted.

For both, periodSeconds makes sense. Even for the livenessProbe, when failure is considered only after X consecutive failed checks.

  • Related