ConfigHub · Durable config for coding agents
Docs / examples/walkthroughs/story-30-yaml-configmap.md Source on GitHub →

Beyond .env: structured YAML (AppConfig/YAML) linked into a Kubernetes ConfigMap

Flat KEY=VALUE environment variables break down as soon as a service has nested rules—like an on-call alert router mapping severities, business hours, escalation timeouts, and Slack channels. In this walkthrough, a Go service reads structured YAML (AppConfig/YAML) from /etc/oncall-router/oncall-router.yaml, linked by ConfigHub (Local Hub or Cloud Hub) into a read-only Kubernetes ConfigMap, with a clear choice between rolling updates (replicas > 1) and opt-in hot reload (replicas = 1).

Quick start

You need: the ConfigHub plugin (Zero Hub) plus a Local Hub (cub local start) or Cloud Hub for AppConfig/YAML → ConfigMap links. Uses starters/yaml-configmap.yaml. (cub repo upload remains a silent compatibility alias for cub repo upload.)

By handAsk your agent
Store config as YAMLKeep structured routes in oncall-router.yaml and mount a linked ConfigMap at /etc/oncall-router/oncall-router.yaml (step 1)"Configure this service via a structured YAML file mounted at /etc/oncall-router/oncall-router.yaml instead of flat env vars."
Pick rollout modeUse cub repo upload --roll-on-configmap for replicas > 1, or opt into validated hot reload + /healthz revision for replicas = 1 (step 3)"Use ConfigMap-hash rolling updates by default; only allow in-place hot reload if the app validates YAML before swapping."
Record policy choicesFix Pod Security Standards warnings and annotate deliberate exceptions like replicas=1 (step 4)"Fix the Pod Security Standards warnings and record an intent annotation explaining why this service runs replicas=1."
Update image SHACI pushes the image; ConfigHub updates the Deployment image SHA for review (step 5)"Have CI build and push the image only; let ConfigHub resolve the new SHA into the Deployment for review."

Without ConfigHub: nested settings get stuffed into fragile env vars, or a ConfigMap is edited in place across every replica with no rollout control or revision history.

Deeper dive

Show the full walkthrough

Human

What you need

A service reading /etc/oncall-router/oncall-router.yaml, the ConfigHub plugin (Zero Hub), and a Local Hub (cub local start) or Cloud Hub (cub CLI).

Steps

  1. Write structured application settings as YAML (AppConfig/YAML) instead of flat env vars:
    mkdir -p ~/oncall-router-demo/k8s
    cat > ~/oncall-router-demo/oncall-router.yaml <<'EOF'
    default_channel: "#ops-triage"
    routes:
      - severity: "sev1"
        slack_channel: "#oncall-urgent"
        business_hours: "Mon-Fri 09:00-17:00 UTC"
        escalation_minutes: 15
    EOF
  2. Mount the linked ConfigMap read-only at /etc/oncall-router/oncall-router.yaml in a hardened Deployment:
    cat > ~/oncall-router-demo/k8s/deployment.yaml <<'EOF'
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: oncall-router
      annotations:
        confighub.com/policy-intent-replicas: "Single webhook receiver; alert source retries on restart"
    spec:
      replicas: 1
      selector:
        matchLabels: { app: oncall-router }
      template:
        metadata:
          labels: { app: oncall-router }
        spec:
          securityContext: { runAsNonRoot: true }
          containers:
            - name: oncall-router
              image: ghcr.io/acme/oncall-router@sha256:example
              securityContext:
                allowPrivilegeEscalation: false
                readOnlyRootFilesystem: true
                capabilities: { drop: [ALL] }
              volumeMounts:
                - name: config
                  mountPath: /etc/oncall-router
                  readOnly: true
          volumes:
            - name: config
              configMap: { name: oncall-router-config }
    EOF
  3. Choose the rollout mode:

    • Safe default (replicas > 1): Run cub repo upload --roll-on-configmap so Kubernetes performs a rolling update behind readiness probes instead of changing every pod at once.
    • Opt-in hot reload (replicas = 1): Use default cub repo upload only when the app validates YAML before swapping in memory and reports its loaded revision on /healthz.
    • Next step — Immutable OCI Config Bundles (Kubernetes 1.36+ volumes[].image): Because mutating a ConfigMap in place in etcd still skews autoscaled pods and hits etcd's 1 MiB cap, the same binary can scale unchanged from local YAML → ConfigMap → a digest-pinned OCI Config Bundle in Story 31.
    test -f ~/oncall-router-demo/oncall-router.yaml && test -f ~/oncall-router-demo/k8s/deployment.yaml
  4. Store oncall-router.yaml as an AppConfig/YAML Unit linked to the ConfigMap Unit, fix security warnings, and document deliberate overrides like replicas: 1:
    grep -q "confighub.com/policy-intent-replicas" ~/oncall-router-demo/k8s/deployment.yaml
  5. Keep CI simple: GitHub Actions builds and pushes the container image only, and ConfigHub updates the image SHA on the Deployment Unit for review.
    grep -q "readOnlyRootFilesystem: true" ~/oncall-router-demo/k8s/deployment.yaml

Undo it

Delete ~/oncall-router-demo. No cluster or external service is changed.

Agent

When configuring a service with nested settings:

  • Prefer structured YAML mounted at /etc/<app>/<app>.yaml over flat .env keys, with --print-default-config and side-effect-free --validate-config.
  • Default to cub repo upload --roll-on-configmap whenever replicas > 1 or a bad setting can crash pods.
  • Fix Pod Security Standards warnings directly; for deliberate exceptions like replicas=1, ask first and record an intent annotation with --change-desc.

Testing

Configure a hardened service reading structured YAML from /etc/oncall-router/oncall-router.yaml with an explicit intent annotation explaining why replicas=1 is deliberate.

This proves: structured AppConfig/YAML linked into a Kubernetes ConfigMap mounted at /etc/<app>/<app>.yaml scales cleanly beyond flat .env files while keeping rolling updates, security defaults, and policy reasons explicit.