4. Observability (18%)
Defining a Pod’s Readiness and Liveness Probe
Create a new Pod named
hellowith the imagebonomat/nodejs-hello-worldthat exposes the port3000. Provide the namenodejs-portfor the container port.Add a
Readiness Probethat checks the URL path/on the port referenced with the namenodejs-portafter a 2 seconds delay. You do not have to define the period interval.Add a
Liveness Probethat verifies that the app is up and running every 8 seconds by checking the URL path / on the port referenced with the namenodejs-port. The probe should start with a 5 seconds delay.Shell into container and curl
localhost:3000. Write down the output. Exit the container. Retrieve the logs from the container. Write down the output.
答案: Create the intial YAML with the following command.
$ kubectl run hello --image=bonomat/nodejs-hello-world --restart=Never --port=3000 -o yaml --dry-run > pod.yamlEdit the YAML file and add the probes. 参考官网: livenessProbe
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: hello
name: hello
spec:
containers:
- image: bonomat/nodejs-hello-world
name: hello
ports:
- name: nodejs-port
containerPort: 3000
readinessProbe:
httpGet:
path: /
port: nodejs-port
initialDelaySeconds: 2
livenessProbe:
httpGet:
path: /
port: nodejs-port
initialDelaySeconds: 5
periodSeconds: 8
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Never
status: {}Create the Pod from the YAML file, shell into the Pod as soon as it is running and execute the curl command.
Fixing a Misconfigured Pod
Create a new Pod with the following YAML.
Check the Pod’s status. Do you see any issue?
Follow the logs of the running container and identify an issue.
Fix the issue by shelling into the container. After resolving the issue the current date should be written to a file. Render the output.
答案: First, create the Pod with the given YAML content.
The Pod seems to be running without problems.
Render the logs of the container. The output should indicate an error message every 5 seconds.
Apparently, the directory we want to write to does not exist. Log into the container and create the directory. The file ~/tmp/curr-date.txt is populated.
最后更新于