Guides
Kubernetes ConfigMaps आणि Secrets उदाहरणांसह
By Ravindra Bagale, DevOps trainer · LinkedIn · Published: · Last updated:
ConfigMap non-secret, Secret sensitive, envFrom/volume inject, rollout restart.
Friends, ConfigMap is settings, Secret is sensitive — both inject without rebuilding the image. Chala mitrano — restart pods after you change them.
मित्रांनो, ConfigMap settings, Secret sensitive — image rebuild नको. Chala mitrano — बदलानंतर pods restart.
मित्रों, ConfigMap settings, Secret sensitive — image rebuild नहीं। Chala mitrano — बदल के बाद pods restart।
Quick answer
Hold this vertical picture:
- ConfigMap.
- Secret (demo).
- Pod template ref.
- apply+restart.
- RBAC.
Language: English · मराठी · हिंदी
Config vs Secret
Image पासून config वेगळे का
एक image, अनेक env.
Why: LOG_LEVEL साठी rebuild.
What: CM+Secret.
How: apply.
Example 1: ConfigMap from literals
Type this:
printf '%s\n' 'kubectl create configmap app-config --from-literal=LOG_LEVEL=info --from-literal=FEATURE_X=on --dry-run=client -o yaml' > /tmp/cm-cmd.txt && cat /tmp/cm-cmd.txt
You will see:
kubectl create configmap app-config --from-literal=LOG_LEVEL=info --from-literal=FEATURE_X=on --dry-run=client -o yaml
What it means: Dry-run prints YAML without changing the cluster.
Example 2: ConfigMap YAML
Type this:
printf '%s\n' 'apiVersion: v1' 'kind: ConfigMap' 'metadata:' ' name: app-config' 'data:' ' LOG_LEVEL: info' ' FEATURE_X: "on"' > /tmp/cm.yaml && cat /tmp/cm.yaml
You will see:
What it means: Non-secret settings live here.
Example 12: Difference one-liner
Type this:
printf '%s\n' 'ConfigMap = non-secret config; Secret = sensitive values (still protect etcd/RBAC)'
You will see:
ConfigMap = non-secret config; Secret = sensitive values (still protect etcd/RBAC)
What it means: Interviews ask this exact line.
Concept 1: Secrets
Passwords.
Why: git मध्ये plain = audit fail.
What: secretKeyRef.
How: base64 ≠ encryption.
Example 3: Secret YAML (demo values only)
Type this:
printf '%s\n' 'apiVersion: v1' 'kind: Secret' 'metadata:' ' name: app-secret' 'type: Opaque' 'stringData:' ' DB_PASSWORD: demo-only-not-real' > /tmp/sec.yaml && grep kind /tmp/sec.yaml
You will see:
What it means: stringData lets you type plain text; API stores base64. Still not for git with real passwords.
Example 5: secretKeyRef one key
Type this:
printf '%s\n' 'env:' ' - name: DB_PASSWORD' ' valueFrom:' ' secretKeyRef:' ' name: app-secret' ' key: DB_PASSWORD' > /tmp/secref.txt && cat /tmp/secref.txt
You will see:
What it means: Mount only the keys the process needs.
Example 9: Never commit real secrets
Type this:
printf '%s\n' 'ok: use sealed-secrets or an external secret store in real teams'
You will see:
ok: use sealed-secrets or an external secret store in real teams
What it means: Plain Secret YAML in git is a finding at Accenture audits.
Example 10: base64 demo (not for real passwords)
Type this:
printf '%s' 'demo' | base64
You will see:
What it means: Opaque secrets store base64 — encoding is not encryption.
Concept 2: Inject
envFrom/volume.
Why: चुकीचा path.
What: app जे वाचते.
How: get/describe.
Example 4: envFrom ConfigMap
Type this:
printf '%s\n' 'envFrom:' ' - configMapRef:' ' name: app-config' > /tmp/envfrom.txt && cat /tmp/envfrom.txt
You will see:
What it means: All keys become environment variables in the container.
Example 6: Volume mount ConfigMap file
Type this:
printf '%s\n' 'volumeMounts:' ' - name: cfg' ' mountPath: /etc/app' 'volumes:' ' - name: cfg' ' configMap:' ' name: app-config' > /tmp/volcm.txt && head -3 /tmp/volcm.txt
You will see:
What it means: Some apps read files under /etc instead of env.
Example 7: get and describe
Type this:
printf '%s\n' 'kubectl get cm app-config && kubectl describe secret app-secret'
You will see:
kubectl get cm app-config && kubectl describe secret app-secret
What it means: describe on Secret hides values — good default.
Concept 3: Rotate
Restart शिवाय जुने env.
Why: Live edit गोंधळ.
What: rollout restart.
How: RBAC.
Example 8: Rollout after change
Type this:
printf '%s\n' 'kubectl rollout restart deploy/web'
You will see:
kubectl rollout restart deploy/web
What it means: Pods do not always reload env until restarted.
Example 11: Immutable tip
Type this:
printf '%s\n' 'immutable: true # optional lock so nobody patches live'
You will see:
immutable: true # optional lock so nobody patches live
What it means: Flipkart-style safety for rare config.
Example 12: Difference one-liner
Type this:
printf '%s\n' 'ConfigMap = non-secret config; Secret = sensitive values (still protect etcd/RBAC)'
You will see:
ConfigMap = non-secret config; Secret = sensitive values (still protect etcd/RBAC)
What it means: Interviews ask this exact line.
Config/Secret card
1 CM 2 Secret 3 inject 4 restart 5 no real passwords in git
Suppose: old config
Restart.
Suppose: secret in git
Rotate.
Ravindra Bagale's Tip
At Infosys, interviewers ask base64 vs encryption. Say: Secrets are encoded, RBAC and encryption-at-rest protect them.
Infosys मध्ये base64 vs encryption विचारतात. सांगा: Secrets encoded; RBAC आणि encryption-at-rest संरक्षण.
Infosys में base64 vs encryption पूछते हैं। कहें: Secrets encoded; RBAC और encryption-at-rest सुरक्षा।
Check yourself (quiz)
Q1. CM?
non-secret
Q2. Secret?
sensitive
Q3. base64?
encoding
Q4. Change?
restart
Q5. envFrom?
all keys
Q6. Git password?
never
Reading tracking
Mark this guide when you finish. Your browser remembers it on this device.
CM/Secret → inject → restart.
Did you understand? Let us try it once more.
Frequently asked questions
ConfigMap vs Secret?
Non-secret vs sensitive.
Is base64 safe?
No — it is encoding only.
Why restart?
Env vars are set at container start.
GitOps with secrets?
Sealed-secrets or external operators.
envFrom vs valueFrom?
All keys vs one key.
immutable?
Blocks live patches for safety.