CKA ConfigMaps and Secrets 1 — Questions and Answers
Question 1: Which kubectl command creates a ConfigMap named 'app-config' with a literal key-value pair 'ENV=production'?
- kubectl create configmap app-config --from-literal=ENV=production (Correct answer)
- kubectl create configmap app-config --literal ENV=production
- kubectl apply configmap app-config --key=ENV --value=production
- kubectl new configmap app-config ENV=production
Correct answer: kubectl create configmap app-config --from-literal=ENV=production
The --from-literal flag is the correct way to pass key=value pairs directly on the command line when creating a ConfigMap.
Question 2: How do you expose all key-value pairs from a ConfigMap named 'app-config' as environment variables in a Pod?
- Use envFrom with configMapRef specifying the ConfigMap name (Correct answer)
- Use env with configMapKeyRef for each individual key
- Mount the ConfigMap as a volume and source the file
- Use valueFrom with configMapRef in the container spec
Correct answer: Use envFrom with configMapRef specifying the ConfigMap name
The envFrom field with configMapRef injects all ConfigMap keys as environment variables at once, without listing them individually.
Question 3: A ConfigMap is mounted as a volume in a Pod. After the ConfigMap is updated, what happens to the files inside the running Pod?
- The files are eventually updated automatically by the kubelet (Correct answer)
- The Pod must be restarted for changes to take effect
- The files are updated immediately and synchronously
- The volume becomes read-only and cannot reflect changes
Correct answer: The files are eventually updated automatically by the kubelet
When a ConfigMap is mounted as a volume, the kubelet periodically syncs the projected files, so changes propagate eventually without a Pod restart.
Question 4: Which kubectl command creates a ConfigMap from all files in a directory named 'configs/'?
- kubectl create configmap my-config --from-file=configs/ (Correct answer)
- kubectl create configmap my-config --from-dir=configs/
- kubectl create configmap my-config --directory=configs/
- kubectl create configmap my-config --files=configs/
Correct answer: kubectl create configmap my-config --from-file=configs/
The --from-file flag accepts either a single file path or a directory path; when given a directory, it creates one key per file.
Question 5: What is the maximum data size allowed in a single Kubernetes ConfigMap?
- 1 MiB (Correct answer)
- 10 MiB
- 512 KiB
- Unlimited
Correct answer: 1 MiB
Kubernetes enforces a 1 MiB (1,048,576 byte) limit on ConfigMap data to avoid overwhelming the etcd storage backend.
Question 6: How do you reference a single key 'DB_HOST' from a ConfigMap named 'db-config' as an environment variable in a container?
- Use env with valueFrom.configMapKeyRef specifying the ConfigMap name and key (Correct answer)
- Use envFrom with configMapRef and a keySelector field
- Use env with configMapRef and specify the key as a prefix
- Use volumes with configMap and the key as a subPath
Correct answer: Use env with valueFrom.configMapKeyRef specifying the ConfigMap name and key
To inject a specific key from a ConfigMap as an env var, use the env field with valueFrom.configMapKeyRef referencing the name and key.
Question 7: What field do you set on a ConfigMap to prevent any future modifications to its data?
- immutable: true (Correct answer)
- readOnly: true
- locked: true
- frozen: true
Correct answer: immutable: true
Setting immutable: true on a ConfigMap prevents any updates to its data or binaryData fields, which also improves performance by eliminating watch overhead.
Which kubectl command creates a ConfigMap named 'app-config' with a literal key-value pair 'ENV=production'?