JSON Path Query on Ultimate CKA exam

I have a query related to this task

please set the context to cluster1 by running:

kubectl config use-context cluster1

There is a script located at /root/pod-cka26-arch.sh on the student-node. Update this script to add a command to filter/display the label with value component of the pod called kube-apiserver-cluster1-controlplane (on cluster1) using jsonpath

The answer given was

kubectl --context cluster1 get pod -n kube-system kube-apiserver-cluster1-controlplane -o jsonpath=‘{.metadata.labels.component}’

My question is do, since we are already setting the context to cluster1 as part of the question, do we need to mention again the context in the kubectl command as part of label value extraction ? when i gave this one alone, the answer was showing wrong.

kubectl get pod -n kube-system kube-apiserver-cluster1-controlplane -o jsonpath=‘{.metadata.labels.component}’

You do indeed!

The question asks you to write a script. Your script will be run by the grader when you press End Exam.

What if, in the meantime answering later questions you ran kubectl config use-context to set a different cluster, e.g. cluster2?

When the grader runs the script you created, it would run on cluster2 (because you didn’t use --context) which does not have the same setup as cluster1 and you would get the question marked wrong.

1 Like