← Back to Home
☸️

Config, Secrets & Scaling

The production essentials: configuration, health checks, and automatic scaling.

⏱11 min readπŸ“šDevOps Fundamentals

Your app needs configuration (URLs, feature flags) and secrets (passwords, API keys) β€” and it should never bake these into the image. It also needs to stay healthy and scale with demand. This lesson covers the production essentials that make a Deployment truly robust.


🎯 Learning Objectives

By the end of this lesson you will:


ConfigMaps β€” Configuration Outside the Image

A ConfigMap holds non-sensitive configuration as key-value pairs:

yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
LOG_LEVEL: "info"
FEATURE_NEW_UI: "true"

Inject it into a Pod as environment variables:

yaml
spec:
containers:
  - name: app
    image: myapp:1.0
    envFrom:
      - configMapRef:
          name: app-config

πŸ’‘ Why separate config from code?

The same image should run in dev, staging, and production β€” only the config changes. Keeping config out of the image means one build promotes cleanly through every environment.


Secrets β€” Sensitive Values

A Secret works like a ConfigMap but is meant for sensitive data (passwords, tokens, keys):

bash
kubectl create secret generic db-secret \
--from-literal=DB_PASSWORD='s3cr3t'

⚠ Secrets are base64, not encrypted by default

Kubernetes Secrets are only base64-encoded in etcd, not truly encrypted out of the box. For real security, enable encryption at rest for etcd and restrict access with RBAC, or use an external secrets manager (Vault, cloud KMS).

Inject a Secret the same way you inject config:

yaml
env:
- name: DB_PASSWORD
  valueFrom:
    secretKeyRef:
      name: db-secret
      key: DB_PASSWORD

Health Probes

Kubernetes needs to know if your app is alive and ready. Two probes tell it:

Probe Question it answers On failure
livenessProbe Is the app still alive? Restart the container
readinessProbe Is the app ready for traffic? Remove it from the Service until ready
yaml
livenessProbe:
httpGet:
  path: /healthz
  port: 3000
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
  path: /ready
  port: 3000
periodSeconds: 5

πŸ’‘ Readiness enables zero-downtime deploys

During a rolling update, traffic is only sent to Pods that pass their readiness probe. A new Pod that’s still starting up won’t receive requests until it’s genuinely ready.


Autoscaling with the HPA

The Horizontal Pod Autoscaler adds or removes Pods automatically based on metrics like CPU usage:

bash
kubectl autoscale deployment web \
--cpu-percent=70 --min=2 --max=10
bash β€” 80Γ—24
student@devops:~$kubectl get hpa

When average CPU crosses 70%, the HPA scales up toward 10 Pods; when load drops, it scales back down toward 2. This requires resource requests to be set on the containers so the HPA has a baseline to measure against.


πŸ§ͺ Hands-on Lab

πŸ“

Configure, Secure, and Autoscale

  1. Create a ConfigMap with a LOG_LEVEL and inject it into your Deployment
  2. Create a Secret for a database password and mount it as an env var
  3. Add an HPA that scales between 2 and 8 Pods at 70% CPU

🧠 Knowledge Check

Knowledge Check

Where should a database password be stored for a Pod?

Knowledge Check

What does a readiness probe control?


πŸ’Ό Interview Preparation

Interview Q&A

How would you make a Kubernetes app production-ready?


Summary

You’ve completed the Kubernetes track: architecture, Pods and Deployments, Services and Ingress, and now config, secrets, probes, and autoscaling. You can deploy and operate a resilient app on a cluster. Next, we provision the infrastructure itself as code with Terraform.

Up Next

Introduction to Terraform

You've mastered this lesson. Continue your journey to becoming a DevOps Engineer.

Start Next Lesson→