Secrets & ConfigMaps – CKA Practice Questions
20 hands-on questions for CKA exam preparation.
Question 1: Create ConfigMap from Literal
Task:
- Create ConfigMap
app-settingswith:APP_ENV=productionLOG_LEVEL=debug
- Verify with
kubectl describe configmap app-settings
Question 2: Create ConfigMap from File
Task:
- Create a file
app.properties:database.host=mysql.default.svc database.port=3306 - Create ConfigMap
db-configfrom this file - Verify the content is stored correctly
Question 3: Create Secret from Literal
Task:
- Create Secret
db-credentialswith:username=dbadminpassword=S3cr3tP@ss
- Verify secret exists (don't expose data)
Question 4: Decode Secret Value
Task:
- Get the password from
db-credentialssecret - Decode the base64 value
Question 5: ConfigMap as Environment Variables
Task:
- Create ConfigMap
env-configwithAPP_MODE=test - Create Pod
env-podusingbusyboxthat:- Loads ALL keys from
env-configas env vars - Runs
envcommand to print environment
- Loads ALL keys from
Question 6: Secret as Environment Variables
Task:
- Create Secret
api-secretwithAPI_KEY=abc123xyz - Create Pod
api-podthat loads the secret as environment variable - Verify:
kubectl exec api-pod -- env | grep API
Question 7: Specific Key as Environment Variable
Task:
- Create ConfigMap
multi-configwith keys:KEY1=value1,KEY2=value2,KEY3=value3 - Create Pod that loads ONLY
KEY2as env var namedMY_KEY
Question 8: Mount ConfigMap as Volume
Task:
- Create ConfigMap
nginx-configwith content:server { listen 8080; root /var/www; } - Create Pod that mounts this ConfigMap at
/etc/nginx/conf.d - Verify file exists:
kubectl exec <pod> -- cat /etc/nginx/conf.d/default.conf
Question 9: Mount Secret as Volume
Task:
- Create Secret
tls-certswith:cert.pem=<certificate content>key.pem=<key content>
- Mount Secret at
/etc/ssl/certsin Pod - Verify files exist with correct permissions
Question 10: Mount Specific Keys Only
Task:
- Create ConfigMap
app-fileswith keys:config.json,settings.yaml,readme.txt - Mount ONLY
config.jsonat/app/config.jsonusingitemsandsubPath
Question 11: Create TLS Secret
Task:
- Generate self-signed certificate:bash
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout tls.key -out tls.crt -subj "/CN=myapp.local" - Create TLS secret
myapp-tlsfrom these files
Question 12: Mount Multiple ConfigMap Keys with Different Paths
Task:
- Create ConfigMap
web-assetswith three keys:index.htmlwith HTML content "Welcome"style.css=body { margin: 0; }app.js=console.log('ready');
- Create Pod that mounts:
index.htmlto/var/www/html/index.htmlstyle.cssto/var/www/css/main.cssapp.jsto/var/www/js/app.js
- Use
subPathfor each file
Question 13: ConfigMap Volume with Custom File Permissions
Task:
- Create ConfigMap
scriptswith keystartup.shcontaining a simple bash script - Mount this ConfigMap at
/scriptswith file mode0755(executable) - Verify:
kubectl exec <pod> -- ls -la /scripts/startup.sh
Question 14: Mount Secret and ConfigMap in Same Directory
Task:
- Create ConfigMap
public-configwithapp.conf=server_name=app - Create Secret
private-configwithdb.conf=password=secret123 - Mount both at
/etc/app/(ConfigMap files and Secret files together) - Verify both files exist in the same directory
Question 15: Selective Key Mounting with Items
Task:
- Create ConfigMap
multi-envwith keys:dev.properties,prod.properties,test.properties - Mount ONLY
prod.propertiesto/config/environment.propertiesusingitemsandsubPath - Ensure other keys are NOT mounted
Question 16: Secret Subpath with Different Filenames
Task:
- Create Secret
credentialswith keys:db-user=admindb-pass=secretapi-token=xyz123
- Mount only
api-tokento/app/secrets/token.txtusingsubPath - Verify other secret keys are NOT mounted
Question 17: Combined ConfigMap and Secret in Pod
Task: Create Pod with:
- ConfigMap
app-cmwithAPP_NAME=myapp - Secret
app-secretwithDB_PASS=secret - Load ConfigMap as env vars
- Mount Secret at
/etc/secrets
Question 18: ConfigMap for Config File with Multi-line Content
Task: Create ConfigMap with multi-line JSON config and mount in Pod
Question 19: Secret with File Permissions
Task:
- Create Secret
secure-secretwithpassword=topsecret - Mount in Pod at
/secretswith mode0400(read-only owner) - Verify permissions:
kubectl exec <pod> -- ls -la /secrets
Question 20: Troubleshoot Missing ConfigMap
Scenario: Pod broken-app is stuck in CreateContainerConfigError:
yaml
spec:
containers:
- name: app
image: nginx
envFrom:
- configMapRef:
name: missing-configTask:
- Identify the issue using
kubectl describe pod - Create the missing ConfigMap
- Verify Pod starts
Quick Reference
| Task | Command |
|---|---|
| Create ConfigMap | kubectl create configmap <name> --from-literal=k=v |
| Create Secret | kubectl create secret generic <name> --from-literal=k=v |
| Create TLS Secret | kubectl create secret tls <name> --cert=c --key=k |
| Decode Secret | kubectl get secret <name> -o jsonpath='{.data.key}' | base64 -d |
| Patch ConfigMap | kubectl patch configmap <name> -p '{"data":{"k":"v"}}' |