liveBook · Manning

Declarative programming

As explained in Road to Kubernetes

Declarative programming is a programming style that specifies the desired result or state rather than the step-by-step procedure for achieving it.

Declarative programming states the desired result or state instead of prescribing every step needed to reach it. The tool handles the procedure, so you focus on what should exist and reuse the configuration across applications, servers, and hosts. section 1.1 section 4.1.1

A deployment request can describe the target state in plain language:

  • Use a Python application with Python 3.10. section 1.1
  • Run it on ports 80 and 443 and allow internet traffic. section 1.1
  • Use example.com without specifying the server-by-server procedure. section 1.1

YAML makes declarative configuration readable at a glance. A GitHub Actions workflow declares its name, trigger, operating system, job, and steps; GitHub Actions decides how to execute that requested workflow. Python and JavaScript, by contrast, generally describe how data flows and what the application must do. section 4.1.1

From workflow to machine configuration

A workflow can run on every push or through a manual trigger, use ubuntu-latest, check out the repository, and execute an echo command. Ansible applies the same desired-state idea to machines through YAML playbooks: it installs Python, Node.js, NGINX, and Supervisor dependencies, configures services, and starts, restarts, or reloads them over SSH. section 4.1.1 section 4.2

Listing 4.2 Hello World with GitHub Actions
name: Hello World
on:
  workflow_dispatch:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Hello World
      run: echo "Hello World"

Inspect a minimal declarative GitHub Actions workflow with triggers, a runner, checkout, and a command. section 4.1.1

How Road to Kubernetes covers it

How deep it goes
Explains the output-versus-steps distinction and demonstrates YAML workflows and Ansible playbooks, without detailing tool internals.
Examples
Uses deployment statements, a GitHub Actions workflow, and Ansible configuration for Python, Node.js, NGINX, and Supervisor.
What it assumes
Builds from plain-language deployment goals and introduces YAML, workflows, manifests, Dockerfiles, and playbooks without assuming operations expertise.
What you can do after
Apply it via YAML-based GitHub Actions workflows and Ansible playbooks to automate deployments and machine configuration.
How it connects
Connects declarative programming with YAML, imperative programming, Kubernetes, Docker, GitHub Actions, Ansible, and infrastructure as code.

Also explained in

Compare how 14 books explain declarative programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.