DEV Community

Cover image for kubectl neat: remove Kubernetes YAML clutter
Harshit Luthra
Harshit Luthra

Posted on Edited on Originally published at harshit.cloud

kubectl neat: remove Kubernetes YAML clutter

Originally published at harshit.cloud on 2024-12-10.


Today I discovered kubectl neat - a plugin that removes all the clutter from Kubernetes YAML output.

the problem

When you run kubectl get pod my-pod -o yaml, you get tons of noise:

metadata:
  creationTimestamp: "2024-01-01T00:00:00Z"
  managedFields:
    - apiVersion: v1
      fieldsType: FieldsV1
      fieldsV1:
        # 200 lines of garbage
Enter fullscreen mode Exit fullscreen mode

the solution

Install kubectl-neat:

kubectl krew install neat
Enter fullscreen mode Exit fullscreen mode

Now run:

kubectl get pod my-pod -o yaml | kubectl neat
Enter fullscreen mode Exit fullscreen mode

Clean, readable YAML with just the stuff you care about.

bonus

Make it even easier:

alias kgn='kubectl get -o yaml | kubectl neat'
Enter fullscreen mode Exit fullscreen mode

Now kgn pod my-pod gives you clean output instantly.

Saves the copy-paste-and-strip routine every time I pull a Kubernetes config.

The reason this matters beyond tidiness: when you are reading a pod's status to work out why it is crash-looping, forty lines of managedFields between you and lastState.terminated.exitCode is forty lines of noise. See CrashLoopBackOff: five causes and how to tell them apart for what to do with the field once you can see it, and kubectl JSONPath for pulling it out without neat at all.

Top comments (0)