Health Check Probes and it’s importance in Kubernetes

Last Update : 21 December, 2023 | Published : 28 April, 2023 | 2 Min Read

Health check probes, a Kubernetes concept to determine if a container in a pod is running and serving traffic or not, aka healthy or not. 😃

Types of Probes

  • Liveness Probe - To check whether the container is running and is used to restart the container.
  • Readiness Probe - To check whether the container is ready to serve traffic and is used to stop sending traffic.
  • Startup Probe - To check whether the container has started up for the first time and is used to restart the container.

Why you may need Startup Probes?

Legacy Applications may contain slow starting containers that needs added time on their initialization, to address this problem we configure the startup probes.
If my application takes 3 mins to finish startup during worst case scenario, then we configure the startupProbe to reflect this as below.

startupProbe: 
 httpGet: 
  path: /healthz
  port: 8080
 failureThreshold: 30
 periodSeconds: 6

How 3 mins you ask 😕, failureThreshold * periodSeconds = 30 * 6 = 180 secs = 3 min. 🤓

How to configure Liveness and Readiness Probes?

Health check probes are defined in the deployment configuration file of your application under pod’s template spec field.

apiversion: myDemoApplication/v1
kind: Deployment
metadata:
  name: demo-deployment
spec:
  replicas: 1
  selector:
 matchLabels:
   app: my-demo-app
  template:
    metadata:
      labels: 
      app: my-demo-app
    spec:
      containers:
   - name: demo-app-container
     image: demo-app-container:latest
     ports:
     - containerPort: 8080
     livenessProbe:
        httpGet:
            path: /healthz
            port: 8080
         initialDelaySeconds: 15
         periodSeconds: 20
        readinessProbe:
         httpGet:
            path: /ready
            port: 8080
         initialDelaySeconds: 5 
         periodSeconds: 10

In the above sample deployment file, the liveness probe and the readiness probe is defined using an HTTP GET request to the /healthz and /ready endpoint respectively on port 8080. You can also define a TCP or gRPC livelness probes as well.

initialDelaySeconds and periodSeconds are only couple of fields that is defined for probes in this sample-deployment.yaml. We can use other fields like timeoutSeconds, successThreshold, failureThreshold and terminationGracePeriodSeconds. To learn what each field signifies you can refer here .

Conclusion

If you want to ensure the stability and reliability of your application in Kubernetes consider defining the health check probes. Configuring them can help you to monitor the health of your application and take necessary actions in case if something goes wrong, which inturn leads to having a smooth operating, high availability application in a Kubernetes environment.

Related posts

Looking for Cloud-Native Implementation?

Finding the right talent is pain. More so, keeping up with concepts, culture, technology and tools. We all have been there. Our AI-based automated solutions helps eliminate these issues, making your teams lives easy.

Contact Us