A ConfigMap is a Kubernetes object used to store non-confidential configuration data in key-value pairs. It helps separate configuration from container images, making apps easier to manage.
Click to reveal answer
beginner
How do you create a ConfigMap from a single file?
Use the command: kubectl create configmap my-config --from-file=path/to/file This creates a ConfigMap named 'my-config' with the file content as a value.
Click to reveal answer
intermediate
What happens when you create a ConfigMap from multiple files?
Each file becomes a key in the ConfigMap, and the file content becomes the value. Use: kubectl create configmap my-config --from-file=dir/ to include all files in a directory.
Click to reveal answer
intermediate
Can you create a ConfigMap from literal values and files at the same time?
Yes, you can combine options: kubectl create configmap my-config --from-file=path/to/file --from-literal=key=value This mixes file content and direct key-value pairs.
Click to reveal answer
beginner
Why use ConfigMaps instead of hardcoding config inside containers?
ConfigMaps let you change app settings without rebuilding images. This makes updates faster and safer, like changing a recipe without baking a new cake.
Click to reveal answer
Which command creates a ConfigMap from a directory of files?
kubectl create configmap app-config --from-file=settings.conf -> Option A
Quick Check:
Correct syntax uses --from-file=filename [OK]
Hint: Use --from-file=filename after configmap name [OK]
Common Mistakes:
Using -f instead of --from-file
Placing filename without --from-file flag
Wrong command order or flags
3. Given the command kubectl create configmap my-config --from-file=app.properties, what will be the key name inside the ConfigMap if the file is named app.properties?
medium
A. app
B. my-config
C. app.properties
D. configmap
Solution
Step 1: Understand key naming in ConfigMaps from files
When creating a ConfigMap from a file without specifying a key, the filename is used as the key.
Step 2: Apply to given filename
Since the file is named app.properties, the key inside the ConfigMap will be app.properties.
Final Answer:
app.properties -> Option C
Quick Check:
Filename = key name in ConfigMap [OK]
Hint: Filename becomes key if no key specified [OK]
Common Mistakes:
Assuming ConfigMap name is the key
Using partial filename as key
Confusing key with ConfigMap name
4. You run kubectl create configmap test-config --from-file=config.txt but get an error saying the file does not exist. What is the most likely cause?
medium
A. The ConfigMap name is invalid
B. The file config.txt is not in the current directory
C. You need to use --from-env-file instead
D. kubectl command does not support --from-file
Solution
Step 1: Check file existence requirement
The --from-file flag requires the file to exist in the current directory or given path.
Step 2: Identify cause of error
If the file is missing or path is wrong, kubectl will error that the file does not exist.
Final Answer:
The file config.txt is not in the current directory -> Option B
Quick Check:
File must exist where command runs [OK]
Hint: Check file path and existence before creating ConfigMap [OK]
Common Mistakes:
Assuming ConfigMap name causes file error
Using wrong flag instead of --from-file
Ignoring file location or path
5. You have two config files: db.conf and app.conf. You want to create a single ConfigMap named multi-config containing both files as keys. Which command should you use?
hard
A. kubectl create configmap multi-config --from-file=db.conf --from-file=app.conf
B. kubectl create configmap multi-config --from-file=db.conf,app.conf
C. kubectl create configmap multi-config --from-file=./db.conf ./app.conf
D. kubectl create configmap multi-config -f db.conf -f app.conf
Solution
Step 1: Understand multiple file syntax
To add multiple files, use multiple --from-file flags, one per file.