...

/

Declarative vs. Imperative Configuration

Declarative vs. Imperative Configuration

Understand the difference between declarative and imperative configurations when using GitOps.

GitOps principles specify that our description of the system must be declarative, but what does that look like? To better understand declarative configuration, let’s compare it with its alternative, imperative configuration.

Imperative configuration

To draw an analogy, think about the instructions provided with a piece of furniture that tells you how to assemble it. The instructions are like imperative configurations because they define a set of steps that are followed one after the other. With each step, commands described in the instructions are performed and, by the end of the instructions, there is (hopefully) a new piece of furniture assembled.

Those who work in technical roles are probably familiar with imperative style configurations, which often come in the form of scripts that specify a sequence of commands executed on the command line. The example below demonstrates this approach using a shell script to install Docker:

Press + to interact
#!/bin/bash
export DEBIAN_FRONTEND="noninteractive"
#Update Packages
apt-get update
#Install Prerequisite Software
apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
#Docker GPG Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
#Add Docker to Sources
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-cache policy docker-ce
#Install Docker
apt-get install -y docker-ce

A graphical user interface (GUI) can also be used to perform imperative configurations. When performed in this manner, we will often be reading from ...