Declarative Infrastructure
You'll learn why GitOps relies on describing the desired end state rather than listing step-by-step instructions.
The Core Idea
Declarative infrastructure means you specify what you want rather than how to get there. Instead of writing a script that says "create server, then install package, then start service," you write a configuration that says "I want a server with this package running this service." The system figures out how to make that happen.
Think of it like ordering at a restaurant: declarative is saying "I want a Caesar salad," while imperative is giving the chef step-by-step instructions on how to wash lettuce, chop romaine, and mix dressing.
Why GitOps Requires This Approach
GitOps stores your entire infrastructure state in Git. When you commit a change, automated systems must reconcile the current state with the desired state in your repository.
Imperative scripts have problems:
- They assume a starting point (what if someone ran them twice?)
- They don't handle drift (manual changes outside the script)
- They can't be safely re-applied
- Git diff shows commands, not actual state changes
Declarative specifications solve this:
- Describe the target state clearly
- Can be applied repeatedly (idempotent)
- Systems can detect and correct drift automatically
- Git diff shows exactly what changed in your infrastructure
- Rollback means reverting to previous state definition
For example, a declarative config says replicas: 3. The GitOps operator sees you currently have 2 replicas and creates one more. If you revert the commit, it sees you want 2 again and removes one.
Key Takeaway: GitOps depends on declarative specifications because they represent state as version-controlled truth that systems can continuously reconcile, enabling automatic drift detection, safe re-application, and true infrastructure-as-code.