Kubernetes: Create Pod with Liveness Probe

This post shows how to create pods with Liveness probe on Kubernetes cluster by manifest.

What is Liveness Probe

Liveness Probe checks pod’s health.
Liveness Probe returns success or failure. If it returns failure, restart the pod and recreate ther container.

The monitoring by kubelet checks stop of main process. Therefore, pod is not rescheduled if main process is running such as deadlock or infinite loop.

Liveness Probe adapt for the above case because it checks by return from out of pods.

Liveness Probe returns success if:

  • Exec
    Command in a container returns zero.
  • HTTP Get
    HTTP response code is 2xx or 3xx
  • TCP Socket
    TCP session is established

Manifest file

apiVersion: v1
kind: Pod
metadata:
  name: app1
spec:
  containers:
  - image: dockerhubuser/app1
    name: app1-container
    livenessProbe:
      httpGet:
        path: /
        port: 8080
      initialDelaySeconds: 30
      periodSeconds: 5
      successThreshold: 1
      failureThreshold: 3

Refer to the following post about 1 – 8 lines.。
>> Create Pod on Kubernetes cluster by manifest file

Setting for Liveness probe from this line.

    livenessProbe:

The type of probe is httpGet. If you use httpGet, define the path of http request and port number.

      httpGet:
        path: /
        port: 8080

If you use Exec, write the following.
Use command key to execute command.

      exec:
        command: ["test_command", "-command_option"]

If you use TCP socket, write the following.
Use port key to define port number.

      tcpSocket:
        port: 5000

Other parameters are the following.

  initialDelaySeconds: Delay time until first monitoring. (sec)
  periodSeconds      : Monitoring period (sec), Default is 10 seconds
  successThreshold   : Number of times to determine "success"
  failureThreshold   : Number of times to determine "failure"
      initialDelaySeconds: 30
      periodSeconds: 5
      successThreshold: 1
      failureThreshold: 3

That’s about it.