k8s使用configmap载入环境变量

从官网 https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/ 搬运

configmap配置如下

apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  SPECIAL_LEVEL: very
  SPECIAL_TYPE: charm

deployment/statefulset/pod…配置如下

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      envFrom:
      - configMapRef:
          name: special-config
  restartPolicy: Never

主要用法在于

envFrom:
- configMapRef:
    name: special-config

同样的 对于secret型字段可以使用

secretKeyRef

你可能感兴趣的:(我爱k8s,k8s爱我)