how to use Jsonpath to format output in Kubernetes.

In this post I will be showing how to use jsonpath to display key/value from resource specifications. I have a pod running and we will be using jsonpath to return the name of the pod and also container image name.

Jacksparrow:~ babatundeolu-isa$ kubectl get deployment
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     2         2         2            2           21m
Jacksparrow:~ babatundeolu-isa$ kubectl get pods
NAME                     READY     STATUS    RESTARTS   AGE
nginx-65899c769f-r7tgm   1/1       Running   0          25m
nginx-65899c769f-svf8d   1/1       Running   0          25m
Jacksparrow:~ babatundeolu-isa$ kubectl get pods -o=jsonpath={.items..metadata.name} | cut -f1- -d' '
nginx-65899c769f-r7tgm nginx-65899c769f-svf8d

Leave a Reply

Your email address will not be published. Required fields are marked *