華為云計算 云知識 Pod中使用ConfigMap的方法
Pod中使用ConfigMap的方法

在Pod中使用ConfigMap配置環(huán)境變量:

apiVersion: v1
kind: Pod
metadata:
  name: configmap-demo-pod
spec:
  containers:
    - name: demo
      image: alpine
      command: ["sleep", "3600"]
      env:
        - name: PLAYER_INITIAL_LIVES
          valueFrom:
            configMapKeyRef:
              name: my-config
              key: player_initial_lives
        - name: UI_PROPERTIES_FILE_NAME
          valueFrom:
            configMapKeyRef:
              name: my-config
              key: ui_properties_file_name

在Pod中使用ConfigMap掛載配置文件:

apiVersion: v1
kind: Pod
metadata:
  name: configmap-demo-pod
spec:
  containers:
    - name: demo
      image: alpine
      command: ["sleep", "3600"]
      volumeMounts:
      - name: config
        mountPath: "/config"
        readOnly: true
  volumes:
    - name: config
      configMap:
        name: my-config
        items:
        - key: "game.properties"
          path: "game.properties"