envFrom configmap in Pod template of Deployment

1/23/2018

We want to use envFrom inside a Deployment's Pod template like below:

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

Error msg:

error: error validating "k8s/deployment.yaml": error validating data: found invalid field name for v1.EnvFromSource

Using K8s 1.7

Edit: ConfigMap

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

The config map is also shown on the ConfigMaps board in the k8s dashboard.

-- yogiginger
kubernetes

3 Answers

8/9/2019

Please ensure the config map has the key & value pair appropriately along with indentation. Key: "Value" This is a minute error that will create the configmap but the pod will not be able to read from the configmap.

-- Sandy
Source: StackOverflow

4/9/2019

yaml file has indentation issue . try this

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
-- shubham_asati
Source: StackOverflow

7/10/2018

your deployment where missing labels field and make sure proper yaml syntax (space). Updated Deployment config

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
-- Savio Mathew
Source: StackOverflow