Kubernetes CKA sample exam question 103 with answer

Question
List all deployments running in ALL namespaces. ONLY display deployment name, namespace name and image name of the FIRST container. Save the output to /tmp/all-deployments.txt
Output should look similar to the sample shown below:

NAME	NAMESPACE	IMAGE_NAME
app1	default		nginx
Answer
In order to display output with non-default columns, you can use custom-columns as output format and then define column names. Each column name has some value based on the question being asked.
Tip: You can display the output in YAML format and then take a note of path of the specific item you want to display.
So the kubectl query will be:
kubectl get deployments -A -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,IMAGE:.spec.template.spec.containers[0].image > /tmp/all-deployments.txt