High Availability
Module
Healthchecks are a way of checking the health of some resource.
Overview
At the end of this module, you will :
Learn to monitor resources
Learn to format it in a declarative mode
Learn the different type of scalability
Prerequisites
Create the directory data/highavailability
in your home folder to manage the YAML file needed in this module.
mkdir ~/data/highavailability
Liveness / Readiness Probe
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.
Sometimes, applications are temporarily unable to serve traffic. For example, an application might need to load large data or configuration files during startup, or depend on external services after startup. In such cases, the Pods must not be killed and no data has to be send. Kubernetes provides readiness probes to detect and mitigate these situations. A pod with containers reporting that they are not ready does not receive traffic through Kubernetes Services.
Readiness probes are configured similarly to liveness probes.
Command Check
This health check uses a command to attempt to get command return status. If the probe get a response from the specific path, the container is considered healthy, if it can't it is considered a failure.
Exercise n°1
Create an Pods based on the busybox Docker image to run a command and check his liveness.
apiVersion: v1
kind: Pod
metadata:
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: 5
periodSeconds: 5
readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
Create a resource based on the previous yaml file definition.
kubectl apply -f data/highavailability/01_pods.yaml
HTTP Request
This health check uses HTTP Request to attempt to get a website path on a specified port. If the probe get a response from the specific path, the container is considered healthy, if it can't it is considered a failure.
Exercise n°1
Create a Pods based on nginx Docker image and configure his liveness and readiness to check the HTTP response of the base path of the default nginx website on port 80.
apiVersion: v1
kind: Pod
metadata:
name: liveness-http
spec:
containers:
- name: nginx
image: nginx
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
periodSeconds: 3
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
periodSeconds: 3
Create a resource based on the previous yaml file definition.
kubectl apply -f data/highavailability/02_pods.yaml
TCP Request
This healthcheck uses TCP Socket to attempt to open a socket to a container on a specified port. If a connection is established, the container is considered healthy, if it can't it is considered a failure.
Exercise n°1
Create a Pods based on nginx Docker image and configure his liveness and readiness to check the TCP response of the base path of the default nginx website on port 80.
apiVersion: v1
kind: Pod
metadata:
name: liveness-tcp
spec:
containers:
- name: nginx
image: nginx
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 5
periodSeconds: 10
Create a resource based on the previous yaml file definition.
kubectl apply -f data/highavailability/03_pods.yaml
Module exercise
The purpose of this section is to manage each steps of the lifecycle of an application to better understand each concepts of the Kubernetes course.
The main objective in this module is to understand how to make everything highly available on a Kubernetes cluster.
For more information about the application used all along the course, please refer to the Exercise App > Voting App link in the left panel.
Based on the principles explain in this module, try by your own to handle this steps. The development of a yaml file is recommended.
The file developed has to be stored in this directory : ~/data/votingapp/13_highavailability
Update the database Deployment to :
Ensure the liveness of the PostgreSQL service based on port 5432
Ensure the readiness of the PostgreSQL service
Update the redis Deployment to :
Ensure the liveness of the Redis service based on port 6379
Ensure the readiness of the Redis service
Update the result Deployment to :
Ensure the liveness of the application based on the HTTP get of path /
Update the vote Deployment to :
Ensure the liveness of the application based on the HTTP get of path /
External documentation
Those documentations can help you to go further in this topic :
Kubernetes official documentation on building a large cluster
Kubernetes official documentation to configure readiness and liveness probe
Last updated
Was this helpful?