DEVOPS / A CONCEPT NOTE

Declarative vs Imperative

describing vs commanding

~65 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

Declarative states WHAT the infrastructure should look like (e.g. Kubernetes, Terraform), while Imperative states HOW to build it using a series of steps (e.g. bash scripts, CLI commands).

02 / FOLLOW THE MECHANISM

How reconciliation flows

  1. Declarative spec

    user specifies: 'I want 3 replicas' in a config file.

  2. Reconciliation Engine

    system constantly checks the live state and corrects deviations automatically.

  3. Imperative script

    runs command: 'launch server' then 'install packages'.

  4. Errors handle

    imperative fails if a step breaks halfway; declarative recovers automatically.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

declaratively apply a configuration state

kubectl apply -f deployment.yaml

EXAMPLE 02 · REFERENCE

imperatively command pod creation

kubectl create deployment my-app --replicas=3

Explore command anatomy in the CLI lab