DEV Community

Madhavam Saxena
Madhavam Saxena

Posted on

Liveness Probes in kubernetes

Suppose you’ve created a service and a deployment with the replica count as ‘n’, this means that there will be at least ‘n’ number of pods running which will be part of the service we create. Now you need to run your application on these pods, but are you sure if the pods and containers are healthy or not?
The answer is NO and to get sure for the same we use livenessprobe. Now this livenessprobe is defined inside the deployment.yml file.

Syntax:

livenessProbe:
httpGet: 
        path: /status
        port: 8080
    periodSeconds: 10
    initalDelaySeconds: 30
Enter fullscreen mode Exit fullscreen mode

Example:

apiVersion: apps/v1
kind: Deployments
metadata:
      name: first-dep
      labels: 
           app: hello-world
spec:
    replicas: 3
    selector:
        matchLabels:
            app: hello-world
    template:
        metadata:
            name: first-pod
            labels: 
                app: hello-world
        spec:
            containers:
                -   name:
                    image:                              
                    livenessProbe:
                        httpGet: 
                            path: /status
                            port: 8080
                        periodSeconds: 10
                        initalDelaySeconds: 30

Enter fullscreen mode Exit fullscreen mode

path: it is used to check if the desired output is being received at defined path
port: it is the port number of the container i.e. port number at which container is exposedRunning.
periodSeconds: This is used to define how often the health check will be performed
initialDelaySeconds: this defined time is used as delay between the two simultaneous health checks.

Top comments (0)