Creating ConfigMaps from literals in Kubernetes - Performance & Efficiency
When creating ConfigMaps from literals in Kubernetes, it is useful to understand how the time to create them grows as you add more literals.
We want to see how the number of literals affects the work Kubernetes does to create the ConfigMap.
Analyze the time complexity of the following command.
kubectl create configmap example-config \
--from-literal=key1=value1 \
--from-literal=key2=value2 \
--from-literal=key3=value3
This command creates a ConfigMap named example-config with three key-value pairs provided directly as literals.
- Primary operation: Processing each literal key-value pair to add it to the ConfigMap.
- How many times: Once for each literal provided in the command.
As you add more literals, Kubernetes processes each one individually to build the ConfigMap.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Processes 10 literals |
| 100 | Processes 100 literals |
| 1000 | Processes 1000 literals |
Pattern observation: The work grows directly with the number of literals; doubling literals doubles the work.
Time Complexity: O(n)
This means the time to create the ConfigMap grows linearly with the number of literals you provide.
[X] Wrong: "Adding more literals won't affect the creation time much because it's just one command."
[OK] Correct: Each literal is processed separately, so more literals mean more work and longer creation time.
Understanding how input size affects command execution helps you explain efficiency and resource use clearly, a useful skill in real-world DevOps tasks.
What if we changed from literals to loading data from a file? How would the time complexity change?