Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Part 1
Use a ConfigMap for ordinary settings and a Secret for sensitive values. Here, DB_URL and DB_USER are treated as non-sensitive, while DB_PASSWORD is sensitive; both resources provide their values to the same application Pod.
database-config.yaml
This manifest creates a ConfigMap named db-config with two text settings: the database URL and username. In this example, neither is sensitive, so they belong here rather than in a Secret.
apiVersion: v1
kind: ConfigMap
metadata:
name: db-config
data:
DB_URL: postgresql://db:5432/app
DB_USER: app_userdatabase-password.yaml
Here, db-credentials is a Secret for the sensitive DB_PASSWORD. stringData lets you write the value in readable form; Kubernetes converts it for storage, but that alone doesn’t protect it from exposure.
apiVersion: v1
kind: Secret
metadata:
name: db-credentials
type: Opaque
stringData:
DB_PASSWORD: example-passwordPod environment references
The app container references both resources with envFrom. db-config supplies DB_URL and DB_USER, while db-credentials supplies DB_PASSWORD. Their keys become environment-variable names; the values stay in the ConfigMap and Secret, rather than being written into the Pod specification.
spec:
containers:
- name: app
image: example/app:1.0
envFrom:
- configMapRef:
name: db-config
- secretRef:
name: db-credentialsAt Pod startup
At startup, the kubelet fetches the referenced ConfigMap and Secret, then sets the Pod’s environment for its container. The application reads DB_URL and DB_USER from the ConfigMap and DB_PASSWORD from the Secret. The values become environment variables; they aren’t written directly into the Pod specification.
Which resource should supply the application's database password?
Let's think this through. Which resource should supply the application's database password? A: The ConfigMap holding the database URL. B: The Secret holding the password. C: The Pod name. Choose an answer, or just think it through. I'll explain in a moment.
- The ConfigMap holding the database URL
- The Secret holding the password
- The Pod name
Which resource should supply the application's database password?
The answer is B: The Secret holding the password. The password is sensitive, so the Pod should reference a Secret for that value. The ConfigMap holds the URL and username because this example assumes they are not sensitive. A Secret still needs access controls.
- The ConfigMap holding the database URL
- The Secret holding the password
- The Pod name
Secret does not mean leak-proof
A Secret’s base64 representation isn’t encryption, so it isn’t leak-proof. Restrict access with RBAC, consider encryption at rest, and keep DB_PASSWORD out of application logs.
- Limit access with RBAC
- Consider encryption at rest
- Avoid logging environment values
One Pod, two configuration sources
Use ConfigMaps for non-sensitive configuration and Secrets for sensitive values. DB_URL and DB_USER come from the ConfigMap; DB_PASSWORD comes from the Secret. Pod references deliver all three as environment variables.

