| Users/Services | ConfigMaps/Secrets Count | Access Frequency | Storage Size | Update Frequency |
|---|---|---|---|---|
| 100 users / 10 services | ~10 ConfigMaps, ~5 Secrets | Low to moderate | Small (KBs) | Rare |
| 10,000 users / 100 services | ~100 ConfigMaps, ~50 Secrets | Moderate | Medium (MBs) | Occasional |
| 1,000,000 users / 1,000 services | ~1,000 ConfigMaps, ~500 Secrets | High | Large (100s MBs) | Frequent |
| 100,000,000 users / 10,000 services | ~10,000 ConfigMaps, ~5,000 Secrets | Very High | Very Large (GBs) | Continuous |
ConfigMaps and Secrets in Microservices - Scalability & System Analysis
The first bottleneck is the API server and etcd storage that hold ConfigMaps and Secrets. As the number and size of ConfigMaps and Secrets grow, etcd's storage and read/write throughput limits are reached first. This causes delays in configuration updates and retrievals by microservices.
- Horizontal scaling: Add more API server instances behind a load balancer to distribute requests.
- etcd clustering: Use a properly sized etcd cluster with enough nodes and resources to handle increased storage and QPS.
- Caching: Implement local caching of ConfigMaps and Secrets in microservices to reduce frequent API calls.
- Secret management tools: Integrate external secret managers (e.g., HashiCorp Vault) to offload secret storage and rotation.
- Sharding: Partition ConfigMaps and Secrets by namespaces or service groups to reduce load on single etcd cluster.
- Compression and size limits: Keep ConfigMaps and Secrets small and compress data to reduce storage and network load.
- Requests per second: Each microservice may request ConfigMaps/Secrets on startup and periodically. For 1,000 services, assuming 1 request per minute, ~17 QPS; for 10,000 services, ~167 QPS.
- Storage: If average ConfigMap/Secret size is 10 KB, 10,000 ConfigMaps total ~100 MB; 100,000 ConfigMaps ~1 GB.
- Bandwidth: Assuming 167 QPS and 10 KB per request, ~1.67 MB/s network bandwidth needed for config data.
- etcd throughput: etcd can handle ~10,000 QPS but performance degrades with large data sizes and many keys.
Start by explaining the role of ConfigMaps and Secrets in microservices. Then discuss how they are stored and accessed (etcd, API server). Identify the bottleneck as etcd storage and API server throughput. Suggest caching and external secret managers as solutions. Finally, mention partitioning and compression to optimize storage and network usage.
Your etcd cluster handles 1,000 QPS for ConfigMap and Secret requests. Traffic grows 10x. What do you do first and why?
Answer: First, add more API server instances and scale the etcd cluster horizontally to handle increased QPS. Also, implement caching in microservices to reduce load on etcd.
Practice
ConfigMap in a microservices environment?Solution
Step 1: Understand ConfigMap role
A ConfigMap is designed to hold configuration data that is not sensitive, such as environment variables or config files, separate from the application code.Step 2: Differentiate from Secrets
Secrets are used for sensitive data like passwords, not ConfigMaps.Final Answer:
To store non-sensitive configuration data separately from application code -> Option BQuick Check:
ConfigMap = Non-sensitive config [OK]
- Confusing ConfigMaps with Secrets
- Thinking ConfigMaps encrypt data
- Assuming ConfigMaps manage network or health
Solution
Step 1: Recall Kubernetes Secret creation syntax
The correct command useskubectl create secret genericwith--from-literalto create a secret from a literal key-value pair.Step 2: Eliminate incorrect options
kubectl create configmap mysecret --from-literal=password=12345 uses configmap instead of secret, kubectl secret create mysecret --from-file=password.txt uses wrong command syntax, kubectl create secret mysecret --password=12345 uses invalid flag.Final Answer:
kubectl create secret generic mysecret --from-literal=password=12345 -> Option AQuick Check:
Secret creation uses 'kubectl create secret generic' [OK]
- Using configmap command instead of secret
- Wrong flags like --password
- Confusing file and literal input
API_KEY inside the container?
env:
- name: API_KEY
valueFrom:
secretKeyRef:
name: mysecret
key: api_keySolution
Step 1: Understand env var from secretKeyRef
The environment variableAPI_KEYis set from a Secret namedmysecret, specifically the keyapi_key.Step 2: Clarify what value is assigned
The value assigned is the secret data stored under that key, not the literal string or empty.Final Answer:
The value stored under key 'api_key' in the Secret named 'mysecret' -> Option CQuick Check:
secretKeyRef pulls secret value by key [OK]
- Assuming it uses the key name as string
- Confusing ConfigMap with Secret
- Thinking it defaults to empty if key missing
Solution
Step 1: Identify common Secret mount errors
Mounting a Secret as a volume requires the Secret to exist with the exact name referenced.Step 2: Evaluate other options
ConfigMap keys missing affect ConfigMaps, not Secrets. Using configMapKeyRef instead of secretKeyRef is for env vars, not volumes. Volume mount path errors cause different errors.Final Answer:
The Secret does not exist or has a different name than specified -> Option AQuick Check:
Secret volume mount fails if Secret missing [OK]
- Mixing ConfigMap and Secret references
- Ignoring Secret existence before mount
- Confusing env var refs with volume mounts
Solution
Step 1: Separate sensitive and non-sensitive data
Best practice is to keep sensitive data like credentials in Secrets and non-sensitive configs in ConfigMaps.Step 2: Use environment variables for flexibility
Mounting both as environment variables allows microservices to access configs securely without code changes.Final Answer:
Store all credentials in a Secret and non-sensitive configs in ConfigMaps; mount both as environment variables -> Option DQuick Check:
Secrets for sensitive, ConfigMaps for safe config [OK]
- Putting secrets in ConfigMaps unencrypted
- Embedding credentials in code
- Using Secrets for non-sensitive data
Ready to prove it?
Pass the test and this pattern moves unknown
