kubernetes envFrom部署的Pod模板中的配置Map

6ioyuze2  于 2022-12-03  发布在  Kubernetes
关注(0)|答案(3)|浏览(148)

我们希望在部署单元模板中使用envFrom,如下所示:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mydeployment
spec:
  replicas: 3
  template:
    spec:
      containers:
      - name: myservice
        image: myimage:latest
        envFrom:
          - configMapRef:
            name: myconfigmap

错误消息:
错误:验证“k8s/deployment.yaml”时出错:验证数据时出错:发现v1.EnvFromSource的字段名无效
使用K8s 1.7
编辑:配置Map

apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
data:
  TEST1: Hello world
  TEST2: test

配置图也显示在k8s Jmeter 板的ConfigMaps板上。

eyh26e7m

eyh26e7m1#

yaml文件有缩进问题。尝试这个

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mydeployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myservice
        image: myimage:latest
        envFrom:
        - configMapRef:
          name: myconfigmap
qltillow

qltillow2#

请确保配置Map具有相应的键值对沿着缩进。**键:“Value”**这是一个微小的错误,将创建配置Map,但Pod将无法从配置Map中读取。

1wnzp6jl

1wnzp6jl3#

您的部署中缺少标签字段,并确保正确的yaml语法(空格)。已更新部署配置

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mydeployment
  labels:
    app: mydeployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myservice
        image: httpd:latest
        envFrom:
        - configMapRef:
       name: myconfigmapenter code here

相关问题