Kubernetes Operations Documents

This Weblog Just Created For Kubernetes Operations Challenges

Checking Pod with liveness probe in Kubernetes


With liveness probe Kubernetes can check a container is still alive.
Following example is a HTTP Get liveness probe.

apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
  - name: app
    image: k8sops-pod-example
    ports:
    - containerPort: 80
    # Following lines were added
    livenessProbe:
      httpGet:
        path: /
        port: 80
    initialDelaySeconds: 15

Kubernetes can probe a container using one of the three mechanisms:

  • HTTP Get
  • TCP Socket
  • Exec

initialDelaySeconds Kubernetes with this option will wait 15 seconds before executing the first probe.
You can create a file with .yml extension and paste the above yml manifest and use kubectl to create a simple Nginx Pod resource with liveness probe support.

kubectl apply -f liveness-example.yml

You can also create the above resource directly from the site content.

kubectl apply -f https://k8sops.ir/session6/liveness-example.yml
Last updated on 14 Jan 2023
Published on 14 Jan 2023