OpsCanary
kubernetesPractitioner

Mastering KYAML: Pretty-Print Your Kubernetes YAML Like a Pro

5 min read Kubernetes BlogAug 11, 2026Reviewed for accuracy
Share
PractitionerHands-on experience recommended

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

shell
# Kubernetes 1.35+ (beta; feature enabled by default, still requires -o kyaml CLI param)
kubectl get deployment my-app -o kyaml
shell
yamlfmt -o=kyaml my-deployment.yaml
shell
kubectl get deployment my-app -o kyaml > my-app.yaml

When 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 docs

Test what you just learned

Quiz questions written from this article

Take the quiz →
Linux FoundationSponsor

Industry-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 →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.