-
Create a pod that exposes an endpoint /health, responding with an HTTP 200 status code
Save the following file as
hc.yaml
cat > hc.yaml <<EOF apiVersion: v1 kind: Pod metadata: name: hc spec: containers: - name: simpleservice image: mhausenblas/simpleservice:0.5.0 ports: - containerPort: 9876 livenessProbe: initialDelaySeconds: 2 periodSeconds: 5 httpGet: path: /health port: 9876 EOF
Pay attention to
livenessProbe
section. -
Deploy the pod
kubectl create -f hc.yaml
-
Describe the pod; it should be considered healthy
kubectl describe pod hc
-
Now we launch a bad pod, that is, a pod that has a container that randomly (in the time range 1 to 4 sec) does not return a 200 code Save the following file as
bad-hc.yaml
cat > bad-hc.yaml <<EOF apiVersion: v1 kind: Pod metadata: name: bad-hc spec: containers: - name: simpleservice image: mhausenblas/simpleservice:0.5.0 ports: - containerPort: 9876 env: - name: HEALTH_MIN value: "1000" - name: HEALTH_MAX value: "4000" livenessProbe: initialDelaySeconds: 2 periodSeconds: 5 httpGet: path: /health port: 9876 EOF
-
Deploy the pod
kubectl create -f bad-hc.yaml
-
Check events at the bad pod
kubectl describe pod bad-hc
You should see that bad pod was restarted several times.
-
Delete the pods
kubectl delete pod hc bad-hc
-
Create a pod
readiness.yaml
with a readinessProbe that kicks in after 10 secondscat > readiness.yaml <<EOF apiVersion: v1 kind: Pod metadata: name: readiness spec: containers: - name: simpleservice image: mhausenblas/simpleservice:0.5.0 ports: - containerPort: 9876 readinessProbe: initialDelaySeconds: 10 httpGet: path: /health port: 9876 EOF
-
Deploy the pod
kubectl create -f readiness.yaml
-
Looking at the events of the pod. You should see that, eventually, the pod is ready to serve traffic
kubectl describe pod readiness
-
Delete the pod
kubectl delete pod readiness
- Deploy a pod that runs nginx and uses port 80 and root path for the health check. Ensure that pod is healthy.
- Change health check configuration to make pod unhealthy.
- Observe whether kubernetes tries to restart the unhealthy pod.
- Modify
hc.yaml
to use a TCP socket handler instead of HTTP GET handler. Reference link - Deploy the pod and see if the pod is considered healthy.
Next: Deployments