Declarative model used by K8s

The declarative model in Kubernetes is a management approach where you define the desired state of your system—the "what"—and let Kubernetes handle the "how" to achieve and maintain that state. This is the core architectural principle that enables Kubernetes to provide features like self-healing, automated scaling, and repeatable deployments.

Core Concepts of the Declarative Model

  • Desired State: You specify the end goal (e.g., "run three replicas of this web server") in a configuration file, typically a YAML manifest.

  • Control Loop (Reconciliation): Kubernetes constantly compares the actual state (what is currently running) with the desired state (your manifest). If they don't match, it takes corrective action automatically.

  • Self-Healing: If a container crashes or a node fails, the declarative system detects the discrepancy and automatically restarts or reschedules components to restore the desired state.


Declarative vs. Imperative

Unlike the declarative approach, the imperative approach involves giving step-by-step commands (e.g., kubectl run ... or kubectl scale ...).


Key Components

  • Manifests: Structured files (YAML or JSON) that describe resources like Deployments, Services, and ConfigMaps.

  • Controllers: Background processes (like the Deployment Controller) that act as the brains for reconciliation.

  • GitOps Tools: Popular tools like Argo CD and Flux extend the declarative model by automatically syncing a cluster's state with a Git repository