Introduction to Kubernetes liveness probe
The Kubernetes liveness probe is defined as, the liveness probe has been utilized to realize that when to restart the container and it also indicates that is it implemented as per the needs, it means it can be used to specify whether the container is running or not if the liveness probe has been failing then the kubelet can destroy the container then the container is conquered to reset its policy which means that the kubelet is accountable for destroying the container and beginning the new one if the container does not gives a liveness probe then its default state is a success.
What is Kubernetes liveness probe?
The liveness probe in Kubernetes can be used to identify the situation that the container is working or not and then it can also able to configure the file, the liveness probe allows Kubernetes that to check the application is working or not, the kubelet agent which can run on every node that can use the liveness probe for making sure that the container which is running is running as expected or not, if any content is not so long sending the request then kubelete can reset the container.
For example, if the container is not responding and will not able to create the progress due to the halt hence the liveness probe can identify the fault.
How to Use Kubernetes liveness probe?
Kubernetes can able to support three techniques for executing liveness probe that is running a command inside a container another is to construct an HTTP request against a container or starting TCP socket in case of a container, a number of parameters have been arranged for commanding the bearing of the probe, such as to check how frequently for implementing the probe, also can check the behavior that how can it hold-up for a long time following the probe which is considered to stop, and it also check that at how many times the probe can stop previous to allow, it can be used to check the is restarted or not.
The liveness probe has been used to identify if a container is running or not and also check is it executed or not, in which the kubelet is there to which can accountable for deadly the container and starting up a new container if the liveness probe is not identified then the default state is a success.
If the application will not give the response then it cannot provide advance details due to the halt so the liveness probe has acknowledged the burst state hence the kubelet amended and then reset the container, surprisingly the application move the defect which may cause the halt and then it resets the to make available the container availability which can also identify the defects and fix them later.
Kubernetes liveness probe settings
The Kubernetes has a liveness probe for observing and rectifying the situations and the configuration file of it has a single container in a pod which also has the period-seconds field which can define the kubelet should execute a liveness probe for every 5 seconds, the probes can be configured in many ways, we can identify that they should run whatever the success and doorways are and also to check that for how long time it will wait for a response, for the setting of it we have to define the probe which can check the liveness that can be done in threeway by setting HTTP, commands and the TCP, those can be used for setting the liveness.
- The HTTP is the best simple type of the liveness probe, if our application is not an HTTP server then we have to generate the lightweight HTTP server inside the application for responding to the liveness probe.
For checking the health of HTTP we have commanded as given below,
‘kubectl apply -f https://k7s.io/exmp/pods/probe/http-liveness.yaml’
- The Kubernetes can able to run the commands inside our container for defining a liveness command if that command will come back with code zero then we can say that the container is healthy otherwise it is unhealthy, this probe is very useful if we do not want to run the HTTP server but we need to run the HTTP command to check that the application is healthy or unhealthy.
A pod can be generated by using the command.
‘kubectl apply -f https://k8p.io/examps/pods/probe/exec-liveness.yaml’
- For the setting of the liveness probe we also need to define a TCP liveness probe which is also a type of probe, it uses a TCP socket, in the configuration of it the kubelet can try to crack socket into our container on a particular port, if the connection has been started then it considered to be healthy.
We can able to verify the probe by using the command,
‘kubectl describe pod goproxy’
Kubernetes liveness probe Examples
- name: liveness
- touch /tmp/healthy; sleep 25; rm -rf /tmp/healthy; sleep 500
In this example, we have described the single container pod with the ‘initialDelaySeconds’ and also the ‘periodseconds’ keys can advise the kubelet to execute a liveness probe for every 6 seconds at the first time.
- name: gpprbxy
- containerPort: 8080
In this example, the HTTP check and TCP check both are similar in which the liveness probe has been used and the kubelet can be used for configuration.
In this article we conclude that the liveness probe in Kubernetes has been used to recognize whether the container is running or not in which we have also seen the purpose of using, setting of liveness, and also discuss the example, hence this article we help us to understand the concept of liveness probe in Kubernetes.
This is a guide to Kubernetes liveness probe. Here we discuss the introduction, What is Kubernetes liveness probe? Example and Kubernetes liveness probe settings. You may also have a look at the following articles to learn more –
- Kubernetes Daemonset
- Kubernetes Replication Controller
- Kubernetes hostpath
- Kubernetes Environment Variables