For an exercise, I wrote the following job to get the name, type, namespace and uid of all pods in the cluster
apiVersion: batch/v1
kind: Job
metadata:
name: get-info
spec:
template:
spec:
containers:
- name: get-info
image: busybox
command: ['sh', '-c', 'kubectl get all -o custom-columns=name:.metadata.name,type:.kind,namespace:.metadata.namespace,uid:.metadata.uid > ./data.json']
restartPolicy: Never
I'm not sure why, but the job never gets completed. The command itself works fine directly on the CLI, but the created pods always get an error after their creation.
How do I get it to work, and for future reference how do I debug such a problem?
Thanks
edit: Perhaps it's my approach that's incorrect. I'm supposed to create a workload that outputs the above into JSON. Is Job maybe not the correct resource to do this?
I tried logging the pods, but it failed. Upon using get pods I saw that every created pod had the status ERROR and ready 0/1.