Kubernetes : Configure Liveness and Readiness Probes

1) httpGet livenessProbe: restartPolicy: Always

nano myLiveness-Pod.yamlapiVersion: v1
kind: Pod
metadata:
name: myliveness-pod
spec:
containers:
- image: httpd:2.4
imagePullPolicy: IfNotPresent
name: myliveness-container
command: ['sh', '-c', 'echo Container 1 is Running ; sleep 3600'] ports:
- name: liveness-port
containerPort: 80
hostPort: 8080
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 2
periodSeconds: 10
kubectl create -f myLiveness-Pod.yamlpod/myliveness-pod created
kubectl describe pod/myliveness-podName:               myliveness-pod
Status: Running
Containers:
myliveness-container:
Image: httpd:2.4
Port: 80/TCP
Host Port: 8080/TCP
State: Running
Started: Wed, 16 Jan 2019 07:37:02 +0200
Ready: True
Restart Count: 0
Liveness: http-get http://:80/ delay=2s timeout=1s period=10s #success=1 #failure=3
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 3s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 3s kubelet, minikube Created container
Normal Started 3s kubelet, minikube Started container
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 0 12s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 0 22s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 0 33s
kubectl describe pod/myliveness-podName:               myliveness-pod
Start Time: Wed, 16 Jan 2019 07:37:01 +0200
Status: Running
Containers:
myliveness-container:
State: Running
Started: Wed, 16 Jan 2019 07:37:02 +0200
Ready: True
Restart Count: 0
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 37s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 36s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 36s kubelet, minikube Created container
Normal Started 36s kubelet, minikube Started container
Warning Unhealthy 9s (x3 over 29s) kubelet, minikube Liveness probe failed: Get http://172.17.0.6:80/: dial tcp 172.17.0.6:80: connect: connection refused
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 62s default-scheduler Successfully assigned default/myliveness-pod to minikube
Warning Unhealthy 34s (x3 over 54s) kubelet, minikube Liveness probe failed: Get http://172.17.0.6:80/: dial tcp 172.17.0.6:80: connect: connection refused
Normal Pulled 4s (x2 over 61s) kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 4s (x2 over 61s) kubelet, minikube Created container
Normal Started 4s (x2 over 61s) kubelet, minikube Started container
Normal Killing 4s kubelet, minikube Killing container with id docker://myliveness-container:Container failed liveness probe.. Container will be killed and recreated.
kubectl exec myliveness-pod -i -t -- /bin/sh
# httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6. Set the 'ServerName' directive globally to suppress this message
# httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6. Set the 'ServerName' directive globally to suppress this message
httpd (pid 15) already running
# exit
kubectl get poNAME             READY   STATUS    RESTARTS   AGE
myliveness-pod 1/1 Running 1 104s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 1 2m19s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 1 2m27s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 1 2m34s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 1 2m45s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 1 2m59s
kubectl delete -f myLiveness-Pod.yaml --force --grace-period=0pod "myliveness-pod" force deleted

2) httpGet livenessProbe: restartPolicy: Never

nano myLiveness-Pod.yamlapiVersion: v1
kind: Pod
metadata:
name: myliveness-pod
spec:
containers:
- image: httpd:2.4
imagePullPolicy: IfNotPresent
name: myliveness-container
command: ['sh', '-c', 'echo Container 1 is Running ; sleep 3600'] ports:
- name: liveness-port
containerPort: 80
hostPort: 8080
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 2
periodSeconds: 2

restartPolicy: Never
kubectl create -f myLiveness-Pod.yamlpod/myliveness-pod created
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 8s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 8s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 8s kubelet, minikube Created container
Normal Started 8s kubelet, minikube Started container
Warning Unhealthy 2s (x3 over 6s) kubelet, minikube Liveness probe failed: Get http://172.17.0.6:80/: dial tcp 172.17.0.6:80: connect: connection refused
6 seconds later ..........Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 14s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 14s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 14s kubelet, minikube Created container
Normal Started 14s kubelet, minikube Started container
Warning Unhealthy 8s (x3 over 12s) kubelet, minikube Liveness probe failed: Get http://172.17.0.6:80/: dial tcp 172.17.0.6:80: connect: connection refused
10 seconds later .........Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 25s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 25s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 25s kubelet, minikube Created container
Normal Started 25s kubelet, minikube Started container
Warning Unhealthy 19s (x3 over 23s) kubelet, minikube Liveness probe failed: Get http://172.17.0.6:80/: dial tcp 172.17.0.6:80: connect: connection refused
another 10 seconds later .........Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 34s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 34s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 34s kubelet, minikube Created container
Normal Started 34s kubelet, minikube Started container
Warning Unhealthy 28s (x3 over 32s) kubelet, minikube Liveness probe failed: Get http://172.17.0.6:80/: dial tcp 172.17.0.6:80: connect: connection refused
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 1/1 Running 0 37s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 0/1 Error 0 55s
kubectl get po
NAME READY STATUS RESTARTS AGE
myliveness-pod 0/1 Error 0 67s
kubectl describe pod/myliveness-podName:               myliveness-pod
Start Time: Wed, 16 Jan 2019 07:45:47 +0200
Status: Failed
Containers:
myliveness-container:
State: Terminated
Reason: Error
Exit Code: 137
Started: Wed, 16 Jan 2019 07:45:47 +0200
Finished: Wed, 16 Jan 2019 07:46:23 +0200
Ready: False
Restart Count: 0
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
kubectl delete -f myLiveness-Pod.yaml --force --grace-period=0pod "myliveness-pod" force deleted

3) httpGet livenessProbe: failureThreshold = 1

nano myLiveness-Pod.yamlapiVersion: v1
kind: Pod
metadata:
name: myliveness-pod
spec:
containers:
- image: httpd:2.4
imagePullPolicy: IfNotPresent
name: myliveness-container
command: ['sh', '-c', 'echo Container 1 is Running ; sleep 3600'] ports:
- name: liveness-port
containerPort: 80
hostPort: 8080
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 2
periodSeconds: 2
failureThreshold: 1
kubectl create -f myLiveness-Pod.yamlpod/myliveness-pod createdkubectl get poNAME             READY   STATUS    RESTARTS   AGE
myliveness-pod 1/1 Running 0 6s
desc pod/myliveness-pod|tailEvents:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 64s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 31s (x2 over 64s) kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 31s (x2 over 64s) kubelet, minikube Created container
Normal Started 31s (x2 over 64s) kubelet, minikube Started container
Normal Killing 31s kubelet, minikube Killing container with id docker://myliveness-container:Container failed liveness probe.. Container will be killed and recreated.
Warning Unhealthy 28s (x2 over 62s) kubelet, minikube Liveness probe failed: Get http://172.17.0.6:80/: dial tcp 172.17.0.6:80: connect: connection refused
kubectl get poNAME             READY   STATUS    RESTARTS   AGE
myliveness-pod 1/1 Running 2 68s
desc pod/myliveness-pod|tailEvents:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 86s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 20s (x3 over 86s) kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 20s (x3 over 86s) kubelet, minikube Created container
Normal Started 20s (x3 over 86s) kubelet, minikube Started container
Normal Killing 20s (x2 over 53s) kubelet, minikube Killing container with id docker://myliveness-container:Container failed liveness probe.. Container will be killed and recreated.
Warning Unhealthy 18s (x3 over 84s) kubelet, minikube Liveness probe failed: Get http://172.17.0.6:80/: dial tcp 172.17.0.6:80: connect: connection refused
kubectl get poNAME             READY   STATUS    RESTARTS   AGE
myliveness-pod 1/1 Running 3 108s
kubectl delete -f myLiveness-Pod.yaml --force --grace-period=0pod "myliveness-pod" force deleted

4) tcpSocket livenessProbe

nano myLiveness-Pod.yamlapiVersion: v1
kind: Pod
metadata:
name: myliveness-pod
spec:
containers:
- image: httpd:2.4
imagePullPolicy: IfNotPresent
name: myliveness-container
command: ['sh', '-c', 'echo Container 1 is Running ; sleep 3600'] ports:
- name: liveness-port
containerPort: 80
hostPort: 8080
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 3
periodSeconds: 10
kubectl create -f myLiveness-Pod.yamlpod/myliveness-pod created
kubectl exec myliveness-pod -i -t -- /bin/sh
# httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6. Set the 'ServerName' directive globally to suppress this message
# exit
kubectl delete -f myLiveness-Pod.yaml --force --grace-period=0pod "myliveness-pod" force deleted

5) tcpSocket readinessProbe

nano myLiveness-Pod.yamlapiVersion: v1
kind: Pod
metadata:
name: myliveness-pod
spec:
containers:
- image: httpd:2.4
imagePullPolicy: IfNotPresent
name: myliveness-container
command: ['sh', '-c', 'echo Container 1 is Running ; sleep 3600'] ports:
- name: liveness-port
containerPort: 80
hostPort: 8080

readinessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 3
periodSeconds: 2
kubectl create -f myLiveness-Pod.yamlpod/myliveness-pod created
kubectl get poNAME             READY   STATUS    RESTARTS   AGE
myliveness-pod 0/1 Running 0 3s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 9s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 8s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 8s kubelet, minikube Created container
Normal Started 8s kubelet, minikube Started container
Warning Unhealthy 1s (x3 over 5s) kubelet, minikube Readiness probe failed: dial tcp 172.17.0.6:80: connect: connection refused
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 21s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 20s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 20s kubelet, minikube Created container
Normal Started 20s kubelet, minikube Started container
Warning Unhealthy 1s (x9 over 17s) kubelet, minikube Readiness probe failed: dial tcp 172.17.0.6:80: connect: connection refused
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 31s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 30s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 30s kubelet, minikube Created container
Normal Started 30s kubelet, minikube Started container
Warning Unhealthy 1s (x14 over 27s) kubelet, minikube Readiness probe failed: dial tcp 172.17.0.6:80: connect: connection refused
kubectl get poNAME             READY   STATUS    RESTARTS   AGE
myliveness-pod 0/1 Running 0 36s
kubectl describe pod/myliveness-podName:               myliveness-pod
Status: Running
Containers:
myliveness-container:
State: Running
Started: Wed, 16 Jan 2019 08:42:09 +0200
Ready: False
Restart Count: 0
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 73s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 72s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 72s kubelet, minikube Created container
Normal Started 72s kubelet, minikube Started container
Warning Unhealthy 27s (x22 over 69s) kubelet, minikube Readiness probe failed: dial tcp 172.17.0.6:80: connect: connection refused
kubectl exec myliveness-pod -i -t -- /bin/sh
# httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6. Set the 'ServerName' directive globally to suppress this message
# exit
kubectl describe pod/myliveness-podName:               myliveness-pod
Status: Running
Containers:
myliveness-container:
State: Running
Started: Wed, 16 Jan 2019 08:42:09 +0200
Ready: True
Restart Count: 0
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 99s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 98s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 98s kubelet, minikube Created container
Normal Started 98s kubelet, minikube Started container
Warning Unhealthy 53s (x22 over 95s) kubelet, minikube Readiness probe failed: dial tcp 172.17.0.6:80: connect: connection refused
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m19s default-scheduler Successfully assigned default/myliveness-pod to minikube
Normal Pulled 2m18s kubelet, minikube Container image "httpd:2.4" already present on machine
Normal Created 2m18s kubelet, minikube Created container
Normal Started 2m18s kubelet, minikube Started container
Warning Unhealthy 93s (x22 over 2m15s) kubelet, minikube Readiness probe failed: dial tcp 172.17.0.6:80: connect: connection refused
kubectl delete -f myLiveness-Pod.yaml --force --grace-period=0pod "myliveness-pod" force deleted

Conclusion: Readiness and Liveness Commands

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store