G
GuideDevOps
Lesson 8 of 9

YAML Validation & Linting

Part of the YAML tutorial series.

Overview

Never rely on manual inspection for YAML files. Use automated tools to enforce schema, indentation, and best practices.

Recommended Tools

  • yamllint: A linter that checks for indentation, line length, and syntax issues.
  • yq: A command-line processor (like jq for JSON) that can also validate YAML.
  • Kubeval/Kubeconform: Specifically for validating Kubernetes YAML against K8s schemas.

Example: Using yamllint

yamllint config.yaml

Expected Result (Failure):

config.yaml
  1:1      error    missing document start "---"  (document-start)
  3:5      warning  indentation should be 4 spaces (indentation)

Expected Result (Success):

(no output means success)

By adding these tools to your CI/CD pipeline, you can prevent broken YAML from ever reaching production.