Using liveness probes to ensure your containers are alive

Kubectl watches over your containers. If a container process crashes, Kubelet will take care of it based on the restart policy. But this is not always enough. Your process may not crash, but instead run into an infinite loop or a deadlock. The restart policy might not be nuanced enough. With a liveness probe, you get to decide when a container is considered alive. Here is a pod template for the Hue music service. It has a livenessProbe section, which uses the httpGet probe. An HTTP probe requires a scheme (HTTP or HTTPS, default to HTTP, a host (which defaults to PodIp), a path, and a port). The probe is considered successful if the HTTP status is between 200 and 399. Your container may need some time to initialize, so you can specify an initialDelayInSeconds. The Kubelet will not hit the liveness check during this period:

apiVersion: v1
kind: Pod
metadata:
labels:
app: hue-music
name: hue-music
spec:
containers:
image: the_g1g1/hue-music
livenessProbe:
httpGet:
path: /pulse
port: 8888
httpHeaders:
- name: X-Custom-Header
value: ItsAlive
initialDelaySeconds: 30
timeoutSeconds: 1
name: hue-music

If a liveness probe fails for any container, then the pod's restart policy goes into effect. Make sure your restart policy is not Never, because that will make the probe useless.

There are two other types of probe:

  • TcpSocket: Just check that a port is open
  • Exec: Run a command that returns 0 for success
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset