Liveness & Readiness Probe
Tips and Tricks
For simulated Practice problems visit KillerCoda.
-
create a pod
vids
with imagenginx
. Add a readiness probe to the container to execls
command on it.Solution
```bash # generate pod yaml k run vids --image=nginx --dry-run=client -o yaml > pod.yaml
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: vids name: vids spec: containers: - image: nginx name: vids readinessProbe: exec: command: - ls resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {}
</p> </details>
-
create a pod
aided
with imagenginx
expose port80
on the container. Add a readiness probe to make http get request on port 80.Solution
```bash # generate pod yaml k run aided --image=nginx --dry-run=client -o yaml
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: aided name: aided spec: containers: - image: nginx name: aided ports: - containerPort: 80 readinessProbe: httpGet: path: / port: 80 resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {}
</p> </details>
-
create a pod
baldr
with imagebusybox
executesleep 3600
command on the container. Add a liveness probe to execute commandenv
& add initial delay of5
seconds to it.Solution
```bash # generate pod yaml k run baldr --image=busybox --dry-run=client -o yaml > pod.yaml
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: baldr name: baldr spec: containers: - image: busybox name: baldr command: ["sh","-c","sleep 3600"] livenessProbe: exec: command: - env initialDelaySeconds: 5 resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {}
</p> </details>
-
create a pod
frigg
with imagenginx
expose port80
on the container. Add a liveness probe on container with initial delay of5
seconds & at a period of3
seconds with failure threshold set to8
.Solution
```bash # generate pod yaml k run frigg --image=nginx --dry-run=client -o yaml > pod.yaml
apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: frigg name: frigg spec: containers: - image: nginx name: frigg ports: - containerPort: 80 livenessProbe: httpGet: path: / port: 80 initialDelaySeconds: 5 periodSeconds: 3 failureThreshold: 8 resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {}
</p> </details>