What if you could turn new features on or off instantly without touching your code or restarting anything?
Why Feature flags in Kubernetes? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you want to test a new feature in your app running on Kubernetes. You have to change the code, rebuild the container, update the deployment, and hope nothing breaks. If you want to turn the feature off, you repeat the whole process.
This manual way is slow and risky. Every change means downtime or bugs. You can't quickly switch features on or off for different users or environments. It feels like juggling many balls and dropping some.
Feature flags in Kubernetes let you control features without changing code or redeploying. You toggle features on or off by changing simple settings. This makes testing, rolling out, or rolling back features fast and safe.
kubectl set image deployment/myapp myapp=myapp:v2 kubectl rollout restart deployment/myapp
kubectl patch configmap feature-flags -p '{"data":{"newFeature":"enabled"}}'You can safely test and release features anytime, anywhere, with zero downtime and full control.
A team wants to try a new payment option only for 10% of users. Using feature flags in Kubernetes, they enable it just for that group without affecting others or redeploying.
Manual feature changes cause delays and risks.
Feature flags let you toggle features instantly without redeploying.
This improves safety, speed, and flexibility in managing app features.
Practice
Solution
Step 1: Understand feature flags concept
Feature flags allow toggling features on or off without modifying the application code.Step 2: Relate to Kubernetes usage
In Kubernetes, feature flags help control app behavior dynamically, often via ConfigMaps or environment variables.Final Answer:
To enable or disable application features without changing code -> Option DQuick Check:
Feature flags = toggle features without code change [OK]
- Confusing feature flags with cluster management
- Thinking feature flags manage pods or nodes
- Mixing feature flags with monitoring tools
Solution
Step 1: Identify resource types
Pods run containers, Services expose them, Ingress manages external access, ConfigMaps store configuration data.Step 2: Match feature flags storage
Feature flags are configuration data, so ConfigMaps are the right resource to store them.Final Answer:
ConfigMap -> Option CQuick Check:
Feature flags stored in ConfigMap [OK]
- Choosing Pod instead of ConfigMap
- Confusing Service or Ingress with config storage
- Thinking feature flags are stored in Secrets
apiVersion: v1 kind: ConfigMap metadata: name: feature-flags data: FEATURE_X_ENABLED: "true" FEATURE_Y_ENABLED: "false"
What will be the value of FEATURE_Y_ENABLED when accessed as an environment variable in a pod?
Solution
Step 1: Read ConfigMap data values
The ConfigMap sets FEATURE_Y_ENABLED to the string "false" explicitly.Step 2: Understand environment variable mapping
When injected as env vars, values are strings exactly as in ConfigMap, so FEATURE_Y_ENABLED will be "false".Final Answer:
false -> Option AQuick Check:
ConfigMap value "false" = env var "false" [OK]
- Assuming boolean false instead of string "false"
- Thinking missing keys return null or undefined
- Confusing string values with boolean types
- name: FEATURE_Z_ENABLED
valueFrom:
configMapKeyRef:
name: feature-flags
key: FEATURE_Z_ENABLEDIf the ConfigMap 'feature-flags' does not have the key FEATURE_Z_ENABLED, what will happen when the pod starts?
Solution
Step 1: Understand configMapKeyRef behavior
If the specified key is missing in the ConfigMap, Kubernetes treats it as an error.Step 2: Effect on pod startup
The pod will fail to start because the environment variable cannot be resolved from the ConfigMap key.Final Answer:
Pod will fail to start with an error -> Option AQuick Check:
Missing ConfigMap key causes pod start failure [OK]
- Assuming empty string or null is set silently
- Thinking pod ignores missing keys
- Confusing with optional environment variables
Solution
Step 1: Understand percentage-based feature flags
To enable a feature for a subset of users, the flag must support partial enablement, not just true/false.Step 2: Evaluate options
Store a percentage value in ConfigMap and let the app decide feature enablement per user stores a percentage in ConfigMap; the app reads it and enables the feature for that percent of users dynamically.Final Answer:
Store a percentage value in ConfigMap and let the app decide feature enablement per user -> Option BQuick Check:
Percentage flags need app logic with ConfigMap value [OK]
- Using boolean flags for partial user enablement
- Relying on Secrets for feature flags
- Thinking traffic routing replaces feature flags
