Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

Liveness Probe

 

What happens if the application in the pod is running but it can’t serve its main purpose, for whatever reason? Also applications that run for a long time might transition to broken states, and if this is the case the last thing you want is a call reporting a problem in an application that could be easily fixed with restarting the pod. Liveness probes are a Kubernetes feature made specifically for this kind of situation. Liveness probes send a pre-defined request to the pod on a regular basis then restart the pod if the request fails. The most commonly used liveness probe is HTTP GET request, but it can also open the TCP socket or even issue a command.

Next is an HTTP GET request probe example, where the initialDelaySeconds is the waiting time before the first try to HTTP GET request to port 80, then it will run the probe every 20 seconds as specified in periodSeconds. If this fails the pod will restart automatically. You have the option to specify the path, which here is just the main website. Also you can send the probe with a customized header. Take a quick look:

Now let’s launch this pod then log in to it to terminate the process that handles the HTTP GET request:

You can see that the pod was automatically restarted, and you can also see the reason for that restart in the event:

This is a TCP socket probe example. A TCP socket probe is similar to the HTTP GET request probes, but it will open the TCP socket:

The command is like HTTP GET and TCP socket probes. But the probe will execute the command in the container: