Industry observers note that YAML has been the standard way to write Kubernetes manifests for years. Every example, tutorial, and configuration file you come across is written in it. The problem isn't that YAML is a bad format. It's that YAML gives you a lot of choices, and not all of them are equally good for writing Kubernetes manifests. Some features make files harder to read, some are easy to misuse and others can lead to surprising behavior.

Industry observers note that the interesting part is that Kubernetes doesn't actually need most of those features. It only relies on a small subset of YAML. This led to a simple question: if Kubernetes only needs a small part of YAML, why not standardize on that part and avoid the rest? Instead of introducing a upcoming configuration language, SIG CLI introduced KYAML, a stricter, more consistent way to write YAML.

KYAML is a strict subset (or "dialect") of standard YAML, designed to be parseable by the existing ecosystem without any changes, as proposed in KEP 5295. It does not introduce a latest format or a new parser. It just narrows the scope of choices you make when writing YAML, so everyone ends up making the same ones.

According to recent reports, think of it less like a new language and more like an agreed-upon style. Everything valid in KYAML is valid YAML.

Standard YAML has a few well-known traps and JSON is not without its own.

It has been revealed that whitespace sensitivity. Indentation defines structure in YAML, which means a wrongly indented file can remain syntactically valid while representing a different object than intended. This gets especially painful with templating tools like Helm, where you are manipulating indentation from outside the YAML context.

It has been revealed that silent type coercion. String quoting is optional in YAML, which sounds convenient until it is not. Some values that look like strings get coerced into other types without warning. The classic example is the "Norway Bug".

In standard YAML, NO is parsed as a boolean false, not the string "NO" and it has caught more than a few people off guard.

According to recent reports, JSON is not the answer either. It lacks comment support, is strict about trailing commas, and requires every key to be quoted, none of which makes for a good config writing experience.

KYAML addresses all of these by making structure and types explicit:.

YAML calls this flow style, as opposed to the conventional block style most people use. KYAML sits halfway between JSON and YAML, more explicit than default YAML, friendlier than JSON.

Here is the same Pod manifest written in both formats for comparison.

Recent findings suggest that notice the double-quoted string values, the braces around every mapping, the brackets around the list and the trailing commas. The additional syntax makes the document structure explicit instead of relying on indentation.

There are different ways to get KYAML output.

Since Kubernetes 1.34, kubectl supports KYAML as a native output format.

According to recent reports, there are at the moment no looks to make KYAML the default output format. If you prefer using KYAML by default, you can configure your preferred default with kuberc. For more details, see the kuberc documentation.

sigs.k8s.io/yaml ships a yamlfmt tool that can convert files to KYAML.

Running it against a file prints the KYAML version to stdout. It also accepts a directory, in which case it converts and prints every file in that directory. So you'll need to redirect the output to a file (or files) if you want the conversion to stick.

It can also show you a diff instead of a full conversion:.

For converting existing files, Google's yamlfmt added a dedicated kyaml formatter in v0.21.0.

Install via Go, or grab a binary from the releases page:.

It is also available as a pre-commit hook and as a Docker image for CI pipelines.

Add a .yamlfmt config to your project root:.

Preview the output without modifying your file:.

To convert an entire directory:.

The kyaml formatter takes no additional configuration and does not share options with the default formatter so mixing them will cause an error.

For more on the available modes and flags, check the command usage docs.

Industry observers note that every valid KYAML file is a valid YAML file. So whatever you write in KYAML, your existing tools, your kubectl, your CI pipelines, none of them need to change. You can even pass KYAML as input to any version of kubectl, not just 1.34+, because at the end of the day it is just YAML.

Sources indicate that KYAML is not strictly necessary. You can keep writing block-style YAML and things will work. But it is a deliberate choice to make your configs less error-prone and more consistent especially across a team or a larger repo.

It is less of a migration and more of a better habit.

📌 Read also:

→ Read original article