Skip to content

Latest commit

 

History

History
85 lines (55 loc) · 1.91 KB

10. Liveness(HealthCheck) in Kubernetes.md

File metadata and controls

85 lines (55 loc) · 1.91 KB

Kubernetes — Liveness

Pods and Container are running but application is might dead because of some reason. To Detect and resolve problem with application we need to use Liveness (Healthcheck)

Liveness probes are used to control the health of an application running inside a Pod’s container.

Liveness probe checks the container health as we tell it do, and if for some reason the liveness probe fails, it restarts the container.

User can execute 2 types of Liveness

1. Running a command in container periodically

2. periodic check on HTTP Request

Liveness Probe source Thanks to (https://wideops.com/)

Liveness command example

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

We are creating a container with name liveness, and as the container initialise we use the following command:

to create a file healthy at path /tmp/healthy, and delete it after 30 seconds.

- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600

This commands tell the liveness probe to open file at path /tmp/healthy, and if it can’t the liveness probe will fail and container will restart.

exec:
  command:
  - cat
  - /tmp/healthy
  

This is the delay which tells kubelet to wait for 3 seconds before performing the first probe

initialDelaySeconds: 3

This field specifies that kubelet should perform a probe every 5 seconds.

periodSeconds: 5