Mastering KYAML: Pretty-Print Your Kubernetes YAML Like a Pro
In the world of Kubernetes, YAML is the backbone of configuration. However, the conventional YAML can lead to silent errors due to its reliance on whitespace and type coercion. KYAML addresses these issues by enforcing a strict structure that makes your configurations clearer and more reliable.
KYAML is a strict subset of standard YAML designed to be easily parsed by existing tools. It eliminates ambiguity by always quoting value strings, using braces for maps, and brackets for lists. This means you won’t run into unexpected type changes that can break your deployments. To use KYAML, you can enable it in your kubectl commands with the -o kyaml option. For Kubernetes versions 1.35 and above, this feature is enabled by default, but you can also set the environment variable KUBECTL_KYAML=true for earlier versions. For example, you can run kubectl get deployment my-app -o kyaml to output your deployment in KYAML format. If you want to format existing YAML files, tools like yamlfmt can convert them easily with commands like yamlfmt -o=kyaml my-deployment.yaml.
In production, using KYAML can significantly reduce the chances of configuration errors. It’s particularly useful when working with complex deployments where clarity is crucial. However, keep in mind that while KYAML improves readability, it may not be necessary for simpler configurations. Always evaluate your team's needs and the complexity of your YAML files before fully committing to this format.
Key takeaways
- →Enable KYAML output in kubectl with the -o kyaml option for clearer configurations.
- →Use yamlfmt to convert existing YAML files to KYAML format effortlessly.
- →Understand that KYAML prevents silent type coercion by always quoting value strings.
Why it matters
In production, clear and structured YAML reduces the risk of configuration errors that can lead to downtime or failed deployments. KYAML's strict formatting helps teams maintain consistency and clarity in their Kubernetes configurations.
Code examples
# Kubernetes 1.35+ (beta; feature enabled by default, still requires -o kyaml CLI param)
kubectl get deployment my-app -o kyamlyamlfmt -o=kyaml my-deployment.yamlkubectl get deployment my-app -o kyaml > my-app.yamlWhen NOT to use this
The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.
Want the complete reference?
Read official docsIndustry-standard certifications built by the people behind Linux and Kubernetes. Earn the CKA — the gold standard Kubernetes administrator cert. OpsCanary readers get 30% off year-round with code OPSCANARY3.
Get CKA certified →Unlocking Insights at Platform Engineering Day: KubeCon + CloudNativeCon 2026
Join the conversation at Platform Engineering Day, where real-world experiences shape the future of platform engineering. Dive into end-user stories and case studies that reveal how practitioners tackle challenges in evolving platforms.
Navigating NIS2 and DORA Ownership in Kubernetes Teams
Understanding who owns NIS2 and DORA regulations on your Kubernetes platform team is crucial for compliance and security. The traceability chain involves specific roles across risk, legal, and security teams, alongside your platform and application teams. Get ready to clarify responsibilities and streamline your compliance efforts.
CiliumCon Returns: Scaling eBPF Networking at KubeCon 2026
CiliumCon is back, and it's crucial for anyone involved in Kubernetes networking. With Cilium as the de facto CNI, understanding its eBPF foundation is key to managing workloads at scale. Don't miss out on the insights that could elevate your cloud-native architecture.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.