我正在从configmap中读取配置详细信息,如下所示
apiVersion: v1
kind: ConfigMap
metadata:
namespace: akv2k8s-test
name: akv2k8s-test
data:
Log_Level: Debug
Alert_Email: Test@demo.com
pod定义
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
并使用python阅读
import os
loglevel = os.environ['Log_Level']
alertemail = os.environ['Alert_Email']
print("Running with Log Level: %s, Alert Email:%s" % (loglevel,alertemail))
我要在部署时更新配置值,以下命令失败
kubectl apply -f deploy.yaml --env="Log_Level=error"
在部署时如何传递环境变量?
答案 0 :(得分:2)
由于您要在配置过程中更新配置文件 ,最简单的方法是使用cat获取文件内容,然后根据需要进行更新-
cat configmap.yaml |sed -e 's|Log_Level: Debug|Log_Level: error|' | kubectl apply -f -
如果要更新现有的配置映射,请使用kubectl patch
命令。
kubectl patch configmap/akv2k8s-test -n akv2k8s-test --type merge -p '{"data":{"Log_Level":"error"}}'