📖 Scenario: You are managing a Kubernetes cluster for a small web application. You need to store configuration settings like the application mode and log level using ConfigMaps. This helps keep your app settings separate from the code.
🎯 Goal: Create a ConfigMap using literal values to store application configuration settings. Then, display the ConfigMap details to verify your work.
📋 What You'll Learn
Create a ConfigMap named app-config with two literals: mode=production and log_level=info
Use the kubectl create configmap command with the --from-literal option
Display the created ConfigMap using kubectl get configmap app-config -o yaml
💡 Why This Matters
🌍 Real World
ConfigMaps are used in Kubernetes to separate configuration from application code, making apps easier to manage and update without rebuilding images.
💼 Career
Knowing how to create and manage ConfigMaps is essential for Kubernetes administrators and DevOps engineers to configure applications dynamically.
Progress0 / 4 steps
1
Create ConfigMap with literals
Use the kubectl create configmap command to create a ConfigMap named app-config with the literals mode=production and log_level=info.
Kubernetes
Hint
Remember to use kubectl create configmap with --from-literal for each key-value pair.
2
Add a label to the ConfigMap
Add a label env=production to the ConfigMap creation command by including the --labels option.
Kubernetes
Hint
Use --labels=env=production to add a label during creation.
3
Retrieve the ConfigMap details
Use the command kubectl get configmap app-config -o yaml to display the full details of the app-config ConfigMap.
Kubernetes
Hint
Use kubectl get configmap app-config -o yaml to see the ConfigMap content in YAML format.
4
Display the ConfigMap output
Run the command kubectl get configmap app-config -o yaml and show the output that includes the literals mode: production and log_level: info.
Kubernetes
Hint
The output should show the ConfigMap data with keys mode and log_level and their values.
Practice
(1/5)
1. What does the kubectl create configmap command with the --from-literal option do?
easy
A. Lists all ConfigMaps in the current namespace
B. Deletes an existing ConfigMap by specifying literal values
C. Updates a ConfigMap with values from a file
D. Creates a ConfigMap with key-value pairs directly from command line literals
Solution
Step 1: Understand the command purpose
The kubectl create configmap command is used to create a new ConfigMap resource in Kubernetes.
Step 2: Role of --from-literal
The --from-literal option allows adding key-value pairs directly from the command line as literals, without needing a file.
Final Answer:
Creates a ConfigMap with key-value pairs directly from command line literals -> Option D
Quick Check:
Creating ConfigMap from literals = Creates a ConfigMap with key-value pairs directly from command line literals [OK]
kubectl create configmap app-config --from-literal=mode=production --from-literal=debug=false uses --from-literal=mode=production and --from-literal=debug=false, which is the correct syntax.
Final Answer:
kubectl create configmap app-config --from-literal=mode=production --from-literal=debug=false -> Option A
Quick Check:
Correct literal syntax uses '=' after --from-literal [OK]
Hint: Use '=' immediately after --from-literal for each key=value pair [OK]
Common Mistakes:
Omitting '=' after --from-literal
Passing multiple literals without repeating --from-literal