Kubernetes :Validation Error(Deployment.spec.template.spec.container[0]): unknown field "ConfigMapref" in io.k8s.api.core.v1.Container

9/30/2021

I am doing my first deployment in Kubernetes and I've hosted my API in my namespace and it's up and running. So I tried to connect my API with MongoDB. Added my database details in ConfigMaps via Rancher.

I tried to invoke the DB in my deployment YAML file but got an error stating Unknown Field - ConfigMapref

Below is my deployment YAML file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myfistproject
  namespace: Owncloud
spec
  replicas: 2
  selector:
   matchLables:
    app: myfirstproject
    version: 1.0.0
  template:
    metadata:
      labels:
        app: myfirstproject
        version: 1.0.0
    spec:
      containers:
         - name: myfirstproject
           image: **my image repo location**
           imagePullPolicy: always
           ports:
             - containerPort: 80
           configMapRef:
             - name: myfirstprojectdb # This is the name of the config map created via rancher

myfirstprojectdb ConfigMap will store all the details like the database name, username, password, etc.

On executing the pipeline I get the below error.

How do I need to refer my config map in deployment yaml?

Validation Error(Deployment.spec.template.spec.container[0]): unknown field "ConfigMapref" in io.k8s.api.core.v1.Container
-- user15292536
kubernetes
kubernetes-pod

1 Answer

10/1/2021

There are some more typos (e.g. missing : after spec or Always should be with capital letter). Also indentation should be consistent in the whole yaml file - see yaml indentation and separation.

I corrected your yaml so it passes api server's check + added config map reference (considering it contains env variables):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myfistproject
  namespace: Owncloud
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myfirstproject
      version: 1.0.0
  template:
    metadata:
      labels:
        app: myfirstproject
        version: 1.0.0
    spec:
      containers:
        - name: myfirstproject
          image: **my image repo location**
          imagePullPolicy: Always
          ports:
            - containerPort: 80
          envFrom:
            - configMapRef:
                name: myfirstprojectdb

Useful link:

Configure all key-value pairs in a ConfigMap as container environment variables which is related to this question.

-- moonkotte
Source: StackOverflow