liveBook · Manning

Configuration as code

As explained in Kubernetes for Developers

Configuration as code is a practice of representing system configuration in files that are managed like source code.

Configuration as code represents system configuration in files managed like source code. For Kubernetes, declarative YAML makes deployments repeatable, reviewable, and easier to reproduce across staging and production. section 11.0 section 11.5

Apply the practice by:

  • Storing Kubernetes object definitions in Git rather than changing the live cluster directly. section 11.2 section 11.5
  • Reviewing configuration changes like code changes, helping catch operational mistakes before rollout and enabling history inspection or rollback. section 11.2
  • Organizing files by namespace or environment so similar staging and production systems can be maintained and reproduced. section 11.0 section 11.2
  • Automating rollout with a deployment pipeline or continuous reconciliation, while keeping sensitive values in restricted Kubernetes Secrets. section 11.5

A maintenance task as configuration

Instead of running python3 add_tasks.py with kubectl exec inside an existing Pod, define a Kubernetes Job. The Job creates its own Pod, resource allocation, environment variables, retry limit, and completion status, making the task repeatable and suitable for review and rollout through Git. section 10.2.1

Listing 10.9 Chapter10/10.2.1_Job/job_addwork.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: addwork
spec:
  backoffLimit: 2
  template:
    spec:
      containers:
      - name: pi-container
        image: docker.io/wdenniss/pi_worker:2    #1
        command: ["python3",  "add_tasks.py"]    #2
        env:
        - name: REDIS_HOST
          value: redis-0.redis-service
        - name: PYTHONUNBUFFERED
          value: "1"
      restartPolicy: Never

Inspect a complete Job manifest showing the image, command, environment variables, retry limit, and non-restarting completion policy. section 10.2.1

How Kubernetes for Developers covers it

How deep it goes
Explains repository organization, review, rollout, reconciliation, and Secrets, with a worked Job manifest rather than exhaustive configuration reference.
Examples
Demonstrates staging and production repositories plus a Kubernetes Job that runs python3 add_tasks.py in its own Pod.
What it assumes
Assumes basic Kubernetes objects and YAML familiarity while explaining why declarative files replace imperative kubectl operations.
What you can do after
Apply configuration through Git, code review, deployment pipelines, GitOps reconciliation, and repeatable Kubernetes Jobs.
How it connects
Connects version control, code review, Kubernetes namespaces, GitOps, deployment pipelines, and Kubernetes Secrets.

Also explained in

Compare how 3 books explain configuration as code →

Related concepts

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