spec on top in one, metadata buried in the middle of the next, and in review you scroll forever to find what you’re after. k8s-yaml-fmt brings order to the mess.
This small Python tool sorts the fields of every resource exactly the way you know them from kubectl, the official examples, and everyday Kubernetes work — not alphabetically, but idiomatically. Set it up once and every manifest in your repo looks the same, keeping your diffs small and readable.
apiVersion,kind,metadata,spec— always right where you expect them- Knows the right ordering for workloads, services, RBAC resources, and more
- Keeps your YAML comments and handles multi-document files
- Custom resource kinds? Just add them in your project configuration
Two ways to run it:
k8s-yaml-fmt deployment.yamlFormat a single file or a whole directory on demand.
repos:
- repo: https://github.com/metawave/k8s-yaml-fmt
rev: v0.1.0
hooks:
- id: k8s-yaml-fmtEvery commit keeps your manifests tidy — automatically.