KYAML formatter and validator — converts YAML to Kubernetes YAML (KYAML), a safer and less ambiguous subset of YAML introduced in Kubernetes v1.34 (KEP-5295).
KYAML is a strict subset of YAML designed specifically for Kubernetes. Any KYAML document is valid YAML, but KYAML eliminates common pitfalls:
- Double-quoted strings — no more implicit type coercion (
NO→false) - Flow-style syntax — uses
{}for maps and[]for lists, making it whitespace-insensitive - Comments — unlike JSON, KYAML supports comments
- Trailing commas — allowed for cleaner diffs
go install github.com/loewenthal-corp/kyaml/cmd/kyaml@latestOr download a binary from the releases page.
Convert YAML files to KYAML:
# Format a file (print to stdout)
kyaml format deployment.yaml
# Format and write back
kyaml format -w deployment.yaml
# Format all YAML files in a directory
kyaml format -w ./manifests/
# Format from stdin
cat service.yaml | kyaml formatThe fmt alias also works:
kyaml fmt -w .Check if files are already valid KYAML:
# Validate a file
kyaml validate deployment.yaml
# Validate all YAML files in a directory
kyaml validate ./manifests/Exit code is 1 if any file is not valid KYAML.
Input (service.yaml):
apiVersion: v1
kind: Service
metadata:
name: my-service
labels:
app: web
spec:
type: ClusterIP
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: webOutput (kyaml format service.yaml):
---
{
apiVersion: "v1",
kind: "Service",
metadata: {
name: "my-service",
labels: {
app: "web",
},
},
spec: {
type: "ClusterIP",
ports: [{
port: 80,
protocol: "TCP",
targetPort: 8080,
}],
selector: {
app: "web",
},
},
}task do # Run all quality checks
task test # Run tests
task build # Build binary
task install # Install to ~/go/bin