根据 v1.6 及更高版本的 Kubernetes 文档K8s Docs,我们可以使用:
envFrom:
- configMapRef:
name: <config-file>
Run Code Online (Sandbox Code Playgroud)
将所有 configMaps 数据定义为容器环境变量。使用它与将其设置为具有名称和键的环境变量的用例是什么:
env:
# Define the environment variable
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
# The ConfigMap containing the value you want to assign to SPECIAL_LEVEL_KEY
name: special-config
# Specify the key associated with the value
key: special.how
Run Code Online (Sandbox Code Playgroud)
如果文件中有多个变量但只想提取单个键=值对,您会使用第二个示例吗?我试图了解我在 CKAD 考试中可能遇到的场景的不同用例。