All Articles

kubectl-neat: Krew plugin to clean up Kubernetes resources

Issue

It is a common need to extract the YAML files from the cluster once Kubernetes resources are created the way we want them to. Still, if you type oc get secret mgmt-backup-secret -n cp4i-apic -o yaml, you always get a lot of unnecessary garbage (some people call this rubbish too - hello UK friends!). Too many guides include notes to remove the metadata fields creationTimestamp, resourceVersion, selfLink, uid, and especially managedFields. Is there a better way?

Why is there a managedFields element in every YAML? That’s a good question, here is the answer I found that talks about why it was introduced.

Solution

kubectl (and therefore, oc) support plugins, and there is a plugin called kubectl-neat that focuses on making your YAMLs look like they used to before creating the resources in your cluster.

  1. Install Krew
  2. Install kubectl-neat
  3. Run oc get secret mgmt-backup-secret -n cp4i-apic -o yaml | oc neat
  4. Enjoy clean YAMLs.

And yes, it also works with -o json