Declarative Configuration with YAML
You'll learn how to define your desired Kubernetes cluster state using YAML manifests rather than imperative commands.
What Is Declarative Configuration?
Instead of telling Kubernetes how to create resources step-by-step (imperative), you describe what you want the final state to look like (declarative). You write YAML files that specify resources—Pods, Services, ConfigMaps, etc.—and Kubernetes makes it so.
Think of it like ordering furniture: imperative is calling the store and explaining each assembly step over the phone; declarative is showing them a picture and saying "make it look like this."
How It Works
You create YAML manifest files containing resource definitions. Each manifest includes:
- apiVersion: Which Kubernetes API to use
- kind: Resource type (Pod, Service, Deployment)
- metadata: Name, labels, namespace
- spec: Desired state details
You apply these files using kubectl apply -f manifest.yaml. Kubernetes reads your desired state and reconciles the actual cluster state to match. If you modify the YAML and reapply, Kubernetes updates resources accordingly—no need to delete and recreate manually.
Why Declarative Wins
Declarative configuration is versioned (store in Git), repeatable (same YAML = same result), and auditable (clear history of changes). It's the foundation of GitOps workflows where your repository becomes the source of truth for cluster state.
Instead of remembering sequences of kubectl create and kubectl expose commands, you maintain clean YAML files that document exactly what's running. When something breaks, you can diff files, roll back commits, and reproduce environments reliably.
Key Takeaway:
Declarative YAML manifests let you describe your desired Kubernetes state as version-controlled files, which Kubernetes automatically reconciles—enabling reproducible, auditable infrastructure-as-code.