0
0
Kubernetesdevops~5 mins

Feature flags in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Feature flags let you turn parts of your app on or off without changing code. In Kubernetes, you can use ConfigMaps to manage these flags easily and update your app behavior without redeploying.
When you want to enable a new feature for testing without redeploying your app
When you need to quickly disable a feature causing issues in production
When you want to gradually roll out a feature to some users by changing config
When you want to keep one app version but change behavior based on flags
When you want to separate feature control from app code for easier updates
Config File - feature-flags-configmap.yaml
feature-flags-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: feature-flags
  namespace: default
data:
  newFeatureEnabled: "true"
  betaFeature: "false"

This ConfigMap stores feature flags as key-value pairs.

newFeatureEnabled controls if the new feature is active.

betaFeature controls a beta feature toggle.

Your app reads these values to decide which features to run.

Commands
Create or update the ConfigMap with feature flags in Kubernetes.
Terminal
kubectl apply -f feature-flags-configmap.yaml
Expected OutputExpected
configmap/feature-flags created
Check the current feature flags stored in the ConfigMap.
Terminal
kubectl get configmap feature-flags -o yaml
Expected OutputExpected
apiVersion: v1 data: betaFeature: "false" newFeatureEnabled: "true" kind: ConfigMap metadata: name: feature-flags namespace: default resourceVersion: "12345" uid: abcdef12-3456-7890-abcd-ef1234567890
-o yaml - Outputs the ConfigMap in YAML format for easy reading
Restart the app deployment to pick up updated feature flags if your app reads them on startup.
Terminal
kubectl rollout restart deployment my-app
Expected OutputExpected
deployment.apps/my-app restarted
View detailed information about the feature flags ConfigMap.
Terminal
kubectl describe configmap feature-flags
Expected OutputExpected
Name: feature-flags Namespace: default Labels: <none> Annotations: <none> Data ==== betaFeature: false newFeatureEnabled: true Events: <none>
Key Concept

If you remember nothing else from this pattern, remember: use ConfigMaps to store feature flags so you can change app behavior without changing code or rebuilding images.

Common Mistakes
Changing the ConfigMap but not restarting the app pods
The app may not reload the new flags until restarted, so changes have no effect.
Restart the deployment or pods after updating the ConfigMap if your app reads flags only on startup.
Storing feature flags inside the app code instead of ConfigMaps
You lose flexibility to toggle features without redeploying the app.
Use ConfigMaps to separate feature flags from code for easy updates.
Using non-string values in ConfigMap data
ConfigMap data must be strings; other types cause errors or unexpected behavior.
Always store feature flag values as strings like "true" or "false".
Summary
Create a ConfigMap to hold feature flags as key-value pairs.
Apply the ConfigMap with kubectl apply -f to create or update it.
Check the ConfigMap contents with kubectl get or describe commands.
Restart your app deployment to apply new flags if your app reads them on startup.