云容器引擎 CCE-设置环境变量:YAML样例

时间:2024-05-31 08:37:32

YAML样例

apiVersion: apps/v1
kind: Deployment
metadata:
  name: env-example
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: env-example
  template:
    metadata:
      labels:
        app: env-example
    spec:
      containers:
        - name: container-1
          image: nginx:alpine
          imagePullPolicy: Always
          resources:
            requests:
              cpu: 250m
              memory: 512Mi
            limits:
              cpu: 250m
              memory: 512Mi
          env:
            - name: key                     # 自定义
              value: value
            - name: key1                    # 配置项键值导入
              valueFrom:
                configMapKeyRef:
                  name: configmap-example
                  key: configmap_key
            - name: key2                    # 密钥键值导入
              valueFrom:
                secretKeyRef:
                  name: secret-example
                  key: secret_key
            - name: key3                    # 变量引用,用Pod定义的字段作为环境变量的值
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: key4                    # 资源引用,用Container定义的字段作为环境变量的值
              valueFrom:
                resourceFieldRef:
                  containerName: container1
                  resource: limits.cpu
                  divisor: 1
          envFrom:
            - configMapRef:                 # 配置项导入
                name: configmap-example
            - secretRef:                    # 密钥导入
                name: secret-example
      imagePullSecrets:
        - name: default-secret
support.huaweicloud.com/usermanual-cce/cce_11_0113.html