Linux Foundation CKAD Exam - Topic 2 Question 40 Discussion
Refer to Exhibit.Set Configuration Context:[student@node-1] $ | kubectlConfig use-context k8sContextA pod is running on the cluster but it is not responding.TaskThe desired behavior is to have Kubemetes restart the pod when an endpoint returns an HTTP 500 on the /healthz endpoint. The service, probe-pod, should never send traffic to the pod while it is failing. Please complete the following:* The application has an endpoint, /started, that will indicate if it can accept traffic by returning an HTTP 200. If the endpoint returns an HTTP 500, the application has not yet finished initialization.* The application has another endpoint /healthz that will indicate if the application is still working as expected by returning an HTTP 200. If the endpoint returns an HTTP 500 the application is no longer responsive.* Configure the probe-pod pod provided to use these endpoints* The probes should use port 8080
A) Explanation:
Solution:
To have Kubernetes automatically restart a pod when an endpoint returns an HTTP 500 on the /healthz endpoint, you will need to configure liveness and readiness probes on the pod.
First, you will need to create a livenessProbe and a readinessProbe in the pod's definition yaml file. The livenessProbe will check the /healthz endpoint, and if it returns an HTTP 500, the pod will be restarted. The readinessProbe will check the /started endpoint, and if it returns an HTTP 500, the pod will not receive traffic.
Here's an example of how you can configure the liveness and readiness probes in the pod definition yaml file:
apiVersion: v1
kind: Pod
metadata:
name: probe-pod
spec:
containers:
- name: probe-pod
image: <image-name>
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /started
port: 8080
initialDelaySeconds: 15
periodSeconds: 10
failureThreshold: 3
The httpGet specifies the endpoint to check and the port to use. The initialDelaySeconds is the amount of time the pod will wait before starting the probe. periodSeconds is the amount of time between each probe check, and the failureThreshold is the number of failed probes before the pod is considered unresponsive.
You can use kubectl to create the pod by running the following command:
kubectl apply -f <filename>.yaml
Once the pod is created, Kubernetes will start monitoring it using the configured liveness and readiness probes. If the /healthz endpoint returns an HTTP 500, the pod will be restarted. If the /started endpoint returns an HTTP 500, the pod will not receive traffic.
Please note that if the failure threshold is set to 3, it means that if the probe fails 3 times consecutively it will be considered as a failure.
The above configuration assumes that the application is running on port 8080 and the endpoints are available on the same port.
Twana
10 months agoVelda
10 months agoSharee
10 months agoSarah
10 months agoNana
11 months agoQuentin
11 months agoThomasena
11 months agoRuthann
11 months agoGilma
11 months agoJame
11 months agoCecily
11 months agoJaime
11 months agoQuentin
12 months agoIrma
12 months agoKarma
12 months agoTegan
12 months agoWillodean
12 months agoCaprice
1 year agoSharee
1 year agoDaren
1 year agoArlene
1 year agoFiliberto
1 year agoArleen
1 year agoDominque
1 year agoColette
1 year agoTracey
1 year agoPortia
1 year agoAnnmarie
1 year agoHorace
1 year agoArlette
1 year agoVincenza
1 year agoKate
1 year agoShaunna
1 year agoShawnee
1 year agoLynelle
1 year agoShawnee
1 year ago