Skip to main content
  1. Work/

k8s-yaml-fmt

Kubernetes logo
Know the feeling? Every Kubernetes file looks different — 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
SOPS-encrypted files are left untouched — your secrets stay exactly as they are.

Two ways to run it:

k8s-yaml-fmt deployment.yaml

Format 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-fmt

Every commit keeps your manifests tidy — automatically.