Module 7 · Project 07 · Run the App on Kubernetes · Lesson 25 of 48

Config, secrets, probes and resources

Make the app production-shaped: namespaces, ConfigMaps and Secrets, liveness and readiness probes, CPU and memory requests and limits, and an Ingress for outside traffic.

In this lesson · about 30 minutes

  • Pass settings and secrets to Pods without baking them into images
  • Explain liveness vs readiness probes
  • Set requests and limits, and route outside traffic with an Ingress

Namespaces

A namespace is a folder inside the cluster. Put each app (or each team, or dev and staging) in its own: kubectl create namespace notes. Names only need to be unique inside a namespace, and permissions and quotas can be set per namespace.

ConfigMaps and Secrets

The same image should run in every environment (build once, deploy many, from Project 05). Settings come from outside:

apiVersion: v1
kind: ConfigMap
metadata: { name: notes-config, namespace: notes }
data:
  LOG_LEVEL: info
  DB_HOST: notes-db
---
apiVersion: v1
kind: Secret
metadata: { name: notes-secrets, namespace: notes }
type: Opaque
stringData:
  DB_PASSWORD: change-me      # in real life, create it from a secret manager, never commit it

# in the Deployment's container:
          envFrom:
            - configMapRef: { name: notes-config }
            - secretRef:    { name: notes-secrets }

Kubernetes Secrets are only base64-encoded by default, not encrypted. Restrict who can read them, turn on encryption at rest, and in production feed them from a manager such as AWS Secrets Manager or Vault (with a tool like External Secrets).

Probes: is it alive, and is it ready?

          livenessProbe:
            httpGet: { path: /healthz, port: 3000 }
            periodSeconds: 10
          readinessProbe:
            httpGet: { path: /ready, port: 3000 }
            periodSeconds: 5
  • Liveness: "is the process stuck?" If it fails, Kubernetes restarts the container.
  • Readiness: "can it take traffic right now?" If it fails, the Pod is removed from the Service until it passes. A Pod still loading data, or one that has lost its database, stops getting requests without being killed.

Without a readiness probe, a Pod gets traffic the moment its container starts, before the app is listening. That's the errors you saw in the simulator when you turned the probe off.

Requests and limits

          resources:
            requests: { cpu: 100m, memory: 128Mi }   # what the scheduler reserves
            limits:   { cpu: 500m, memory: 256Mi }   # the hard ceiling

100m means 100 millicores, a tenth of a CPU. The scheduler places Pods on nodes with enough requested capacity. Going over the CPU limit slows the container down; going over the memory limit gets it killed (OOMKilled). Always set both: without them one greedy Pod can starve a whole node, and the autoscaler in the next lesson can't do its maths.

Ingress: the front door

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: { name: notes, namespace: notes }
spec:
  ingressClassName: nginx
  tls:
    - hosts: [notes.example.com]
      secretName: notes-tls
  rules:
    - host: notes.example.com
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend: { service: { name: notes-api, port: { number: 80 } } }
          - path: /
            pathType: Prefix
            backend: { service: { name: notes-web, port: { number: 80 } } }

An Ingress routes outside HTTP(S) traffic to Services by host name and path. An ingress controller (such as ingress-nginx, or the AWS Load Balancer Controller) does the actual work, and cert-manager can get free TLS certificates for it.

Sorting drill

Liveness or readiness?

Which probe should catch each problem?

  • The app is deadlocked and will never answer again
  • The app is still warming its cache after starting
  • The database is briefly unreachable
  • A memory leak has frozen the event loop
  • The Pod is shutting down during a rollout

0 of 5 sorted

Hands-on lab (simulated terminal)

Lab: deploy and inspect

A practice cluster (kind or minikube on your laptop) and the manifests above in a folder called k8s.

Step 1 of 5. Type each command and press Enter. Nothing runs on your computer.

Lab: deploy and inspect

1. Create the notes namespace.

you@laptop:~/notes$

Check your understanding0 of 3 correct

Question 1

1.A readiness probe fails. What does Kubernetes do?

Question 2

2.A container goes over its memory limit. What happens?

Question 3

3.Why use a ConfigMap instead of putting settings in the image?

Key terms

Say the meaning to yourself, then tap a card to check.

Quiz score: 0 of 3

Tip: answer every quiz question correctly first.

Written by Noviq Academy in its own words. The labs are simulations: no real servers are touched. When you build the projects yourself, use a practice virtual machine or a free-tier cloud account you control, watch your cloud spending, and never run cleanup or delete commands on a machine you care about. Tool names belong to their owners; versions and output are shown for learning and may differ slightly from yours. Read-aloud and the whiteboard voice use your device's built-in voices.