Readiness and Liveliness

Pod Lifecycle

A pod has a Status and some Conditions

POD Status

flowchart LR C-- Container Created --> S CP-- No Nodes Available -->S S-- No Nodes Available -->CP[Container Pending State] S-- Looking for available Node --> W0[Worker Node 0] S-- Looking for available Node --> W1[Worker Node 1] S-- Looking for available Node --> W2[Worker Node 2] subgraph Master-node-0 C[Container] S[Scheduler] end S-- Node Available --> p22 subgraph Worker-node-0 W0-->p00[Pod0] W0-->p01[Pod1] W0-->p02[Pod2] end subgraph Worker-node-1 W1-->p10[Pod3] W1-->p11[Pod4] W1-->p12[Pod5] end subgraph Worker-node-2 W2-->p20[Pod6] W2-->p21[Pod7] p22[Pod8] end
stagePod StatusDesc
Pod CreatedPendingWaiting For Scheduler
Pod ScheduledContainer CreatingImages Pulled and Container Starts
Container RunningRunningContainer Ready and Running

kubectl describe pod {podname} will give reason for why its stuck

Pod Conditions

Pod ConditionsTrueFalse
PodScheduledPod is ScheduledPod is Created Waiting for Scheduler
InitializedPod is InitializedPod Creating
ContainersReadyAll Containers are ReadyContainers still strating up
ReadyPod is ready and containers healthypod is not ready containers unhealthy

What does healthy mean?

Readiness Probes

A test to make sure the container is ready to accept traffic and serve the application

 1apiVersion: 
 2kind: Pod
 3metadata:
 4  name: simple-webapp-color
 5spec:
 6  containers:
 7    - name: simple-webapp-color
 8      image: simple-webapp-color
 9      ports:
10        - containerPort: 8080
11
12      readinessProbe:
13        httpGet:
14          path: /api/ready
15          port: 8080

There arer 3 kinds of readiness probes

HTTP Test

1readinessProbe:
2  httpGet:
3    path: /api/ready
4    port: 8080
5  initialDelaySeconds: 10
6  periodSeconds: 5 # How often
7  failureThreshold: 8 #attempts

TCP TEST

1readinessProbe:
2  tcpSocket:
3    port: 8080
4  initialDelaySeconds: 10
5  periodSeconds: 5 # How often
6  failureThreshold: 8 #attempts

Exec Command

1readinessProbe:
2  exec:
3    command:
4      - cat
5      - /app/is_ready
6  initialDelaySeconds: 10
7  periodSeconds: 5 # How often
8  failureThreshold: 8 #attempts

Liveness Probe

 1apiVersion: 
 2kind: Pod
 3metadata:
 4  name: simple-webapp-color
 5spec:
 6  containers:
 7    - name: simple-webapp-color
 8      image: simple-webapp-color
 9      ports:
10        - containerPort: 8080
11
12      livenessProbe:
13        httpGet:
14          path: /api/ready
15          port: 8080

There arer 3 kinds of readiness probes

HTTP Test

1livenessProbe:
2  httpGet:
3    path: /api/ready
4    port: 8080
5  initialDelaySeconds: 10
6  periodSeconds: 5 # How often
7  failureThreshold: 8 #attempts

TCP TEST

1livenessProbe:
2  tcpSocket:
3    port: 8080
4  initialDelaySeconds: 10
5  periodSeconds: 5 # How often
6  failureThreshold: 8 #attempts

Exec Command

1livenessProbe:
2  exec:
3    command:
4      - cat
5      - /app/is_ready
6  initialDelaySeconds: 10
7  periodSeconds: 5 # How often
8  failureThreshold: 8 #attempts