Silly Kubectl Trick #8: Data Extraction With JSON Path

kubectl can pull a lot of data about our deployments and pod.  Most of the time, we humans are the recipients of that information, and kubectl obliges by nicely formatting things in pretty tables.

Shell
 




x


1
$ kubectl get pods
2
NAME                        READY   STATUS    RESTARTS   AGE
3
frontend-64d9f4f776-9fzp8   3/3     Running   0          14s
4
frontend-64d9f4f776-flx58   3/3     Running   0          15s
5
frontend-64d9f4f776-lftdc   3/3     Running   0          15s
6
frontend-64d9f4f776-mrhq6   3/3     Running   0          15s


Ah yes, I see the pod is now called "... FIXME ..."

In my experience, the very next command that I run  needs that auto-generated Pod ID, something like kubectl logs or kubectl exec.  The first couple of times, you'll use the pasteboard – highlight the pod name with your mouse, Cmd-C, and you're off to the races.  By the third, fourth, or fiftieth time, however, you'll be wishing for a better way.