One Developer
One Developer

Reputation: 556

Azure Kubernetes - Overwrite the configmap values using environment variables?

I am reading the configuration details from the configmap as shown below

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: akv2k8s-test
  name: akv2k8s-test
data:
  Log_Level: Debug
  Alert_Email: [email protected]

pod definition

apiVersion: v1
kind: Pod
metadata:
  name: akv2k8s-test
  namespace: akv2k8s-test
spec:
  containers:
    - name: akv2k8s-env-test
      image: kavija/python-env-variable:latest
      envFrom:
        - configMapRef:
            name: akv2k8s-test

and reading it with python

import os
loglevel = os.environ['Log_Level']
alertemail = os.environ['Alert_Email']
print("Running with Log Level: %s, Alert Email:%s" % (loglevel,alertemail))

I want to update the Configuration values while deploying, the below command fails

kubectl apply -f deploy.yaml --env="Log_Level=error"

How do I pass the environment variable while deploying?

Upvotes: 0

Views: 867

Answers (1)

Amit Baranes
Amit Baranes

Reputation: 8122

Since you want to update the configmap while deplyoing, The easiest way would be by getting the file content using cat and then update as you wish -

cat configmap.yaml |sed -e 's|Log_Level: Debug|Log_Level: error|' | kubectl apply -f -

In case you want to update the existing configmap, use kubectl patch command.

kubectl patch configmap/akv2k8s-test -n akv2k8s-test --type merge -p '{"data":{"Log_Level":"error"}}'

Upvotes: 2

Related Questions