

Step 0: Set the correct Kubernetes context
If you're given a specific context (k8s in this case), you must switch to it:
kubectl config use-context k8s
## Skipping this can cause you to work in the wrong cluster/namespace and cost you marks.
Step 1: Identify the namespace of the pod foo
First, check if foo is running in a specific namespace or in the default namespace.
kubectl get pods --all-namespaces | grep foo
Assume the pod is in the default namespace if no namespace is mentioned.
Step 2: Confirm pod foo exists and is running
kubectl get pod foo
You should get output similar to:
NAME READY STATUS RESTARTS AGE
foo 1/1 Running 0 1h
If the pod is not running, logs may not be available.
Step 3: View logs and filter specific error lines
We're looking for log lines that contain:
unable-to-access-website
Command:
kubectl logs foo | grep "unable-to-access-website"
Step 4: Write the filtered log lines to a file
Redirect the output to the required path:
kubectl logs foo | grep "unable-to-access-website" > /opt/KULM00201/foo
# This creates or overwrites the file /opt/KULM00201/foo with the filtered logs.
# You may need sudo if /opt requires elevated permissions. But in most exam environments, you're already the root or privileged user.
Step 5: Verify the output file (optional but smart)
Check that the file was created and has the correct content:
cat /opt/KULM00201/foo
# Final Answer Summary:
kubectl config use-context k8s
kubectl logs foo | grep "unable-to-access-website" > /opt/KULM00201/foo