liveBook · Manning

Configmap

As explained in Shipping Go: Develop, deliver, discuss, design, and go again

A configuration map is a Kubernetes resource that stores non-sensitive configuration values separately from the containers that consume them.

A ConfigMap stores non-sensitive configuration as a Kubernetes resource, keeping values separate from the containers that consume them. This is useful when a cluster spans multiple machines and server-level environment variables or configuration files are impractical. section 10.7

Provide a database URL

Create a ConfigMap named hello-api with database_url set to redis-cluster. Applying k8s/hello-api/config.yml with kubectl creates the resource, which a Deployment can expose to its container as DATABASE_URL through configMapKeyRef. section 10.7

Listing 10.8 config.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: hello-api
data:
  database_url: "redis-cluster"     #1

The YAML shows the minimal ConfigMap structure: apiVersion, kind, metadata, and a data entry for database_url. section 10.7

Listing 10.9 deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-api
spec:
  replicas: 1
  selector:
    matchLabels:
        app: hello-api
  template:
    metadata:
      name: hello-api
      labels:
        app: hello-api
    spec:
      containers:
      - name: hello-api
        imagePullPolicy: Never
        image: holmes89/hello-api:v0.3
        ports:
        - containerPort: 8080
          name: hello-api-svc
        env:
        - name: DATABASE_URL         #1
          valueFrom:
            configMapKeyRef:
              name: hello-api
              key: database_url
        - name: DATABASE_PASSWORD    #2
          valueFrom:
            secretKeyRef:
              name: redis-cluster
              key: redis-password
              optional: false

The Deployment connects the container's DATABASE_URL environment variable to the ConfigMap while sourcing DATABASE_PASSWORD from a Secret. section 10.7

How Shipping Go: Develop, deliver, discuss, design, and go again covers it

How deep it goes
Defines a ConfigMap, creates it from YAML, and wires one key into a Deployment; defers sensitive values to Secrets.
Examples
Uses hello-api, database_url, redis-cluster, config.yml, and a Deployment environment-variable reference.
What it assumes
Assumes familiarity with Kubernetes Deployments, containers, YAML manifests, and environment-based application configuration.
What you can do after
Apply via kubectl a YAML ConfigMap and reference its values from a Kubernetes Deployment.
How it connects
Links Kubernetes resources, Deployments, containers, environment variables, and Secrets.

Also explained in

Compare how 8 books explain configmap →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Shipping Go: Develop, deliver, discuss, design, and go again. The section links point to the parts of the book it draws on.