0
0
Kubernetesdevops~30 mins

Feature flags in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Feature Flags in Kubernetes
📖 Scenario: You are managing a Kubernetes deployment for a web application. You want to control a new feature rollout using feature flags. This means you can turn the feature on or off without changing the application code or redeploying.Feature flags will be stored as environment variables in the deployment manifest. You will create a ConfigMap to hold the feature flag, then update the deployment to use this flag.
🎯 Goal: Build a Kubernetes ConfigMap to store a feature flag, then update a Deployment to use this flag as an environment variable. Finally, check the pod environment to confirm the flag is set.
📋 What You'll Learn
Create a ConfigMap named feature-flags with a key NEW_FEATURE_ENABLED set to "false"
Update the Deployment named web-app to add an environment variable NEW_FEATURE_ENABLED from the ConfigMap
Verify the pod environment variable NEW_FEATURE_ENABLED is set correctly
💡 Why This Matters
🌍 Real World
Feature flags help teams release new features safely by enabling or disabling them dynamically in Kubernetes environments.
💼 Career
DevOps engineers often manage feature flags via ConfigMaps and environment variables to control application behavior without redeploying.
Progress0 / 4 steps
1
Create the ConfigMap for feature flags
Create a Kubernetes ConfigMap named feature-flags with a key NEW_FEATURE_ENABLED set to the string "false". Use the kubectl create configmap command with the literal flag.
Kubernetes
Need a hint?

Use kubectl create configmap feature-flags --from-literal=NEW_FEATURE_ENABLED=false to create the ConfigMap.

2
Add environment variable from ConfigMap to Deployment
Edit the Deployment named web-app to add an environment variable NEW_FEATURE_ENABLED that gets its value from the ConfigMap feature-flags. Use kubectl patch deployment web-app with a JSON patch to add the environment variable under spec.template.spec.containers[0].env.
Kubernetes
Need a hint?

Use a JSON patch to add the environment variable from the ConfigMap to the first container in the deployment.

3
Check the pod environment variable
Get the name of one pod from the web-app deployment using kubectl get pods with a label selector. Then use kubectl exec to run printenv NEW_FEATURE_ENABLED inside the pod to check the environment variable value.
Kubernetes
Need a hint?

Use kubectl get pods -l app=web-app -o jsonpath='{.items[0].metadata.name}' to get the pod name, then kubectl exec to run printenv NEW_FEATURE_ENABLED.

4
Display the feature flag value
Print the output of the environment variable NEW_FEATURE_ENABLED from the pod. This should show false as the current feature flag value.
Kubernetes
Need a hint?

The output should be exactly false, showing the feature flag is off.