Error when adding ConfigMap data into deployment yaml

Hey everyone, really new to Kubernetes and need a little help. Have anyone of you come across this?

Error when trying to apply ConfigMap to deployment yaml.
error when creating “httpd-deployment-datacenter.yaml”: Deployment in version “v1” cannot be handled as a Deployment: strict decoding error: unknown field “spec.template.spec.spec”

apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-deployment-datacenter
spec:
selector:
matchLabels:
app: httpd_app_datacenter
replicas: 4
template:
metadata:
labels:
app: httpd_app_datacenter
spec:
containers:
- name: httpd-container-datacenter
image: httpd:latest
ports:
- containerPort: 80
spec:
volumeMounts:
- name: httpd-configmap-datacenter
mountPath: /usr/share/nginx/html/
volumes:
- name: httpd-configmap-datacenter

Please put your YAML in a code block (triple-backquotes) – nobody can make sense of it without whitespace.

1 Like

Hi thockin, sorry, but not sure how to do this.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment-datacenter
spec:
  selector:
    matchLabels:
      app: httpd_app_datacenter
  replicas: 4
  template:
    metadata:
      labels:
        app: httpd_app_datacenter
    spec:
      containers:
      - name: httpd-container-datacenter
        image: httpd:latest
        ports:
        - containerPort: 80
      spec:
       volumeMounts:
       - name: httpd-configmap-datacenter
       mountPath: /usr/share/nginx/html/
       volumes:
       - name: httpd-configmap-datacenter

Yeah, you have spec under spec - this is just incorrect yaml.

kind: Deployment
metadata:
  name: httpd-deployment-datacenter
spec:
  selector:
    matchLabels:
      app: httpd_app_datacenter
  replicas: 4
  template:
    metadata:
      labels:
        app: httpd_app_datacenter
    spec:
      containers:
        - name: httpd-container-datacenter
          image: httpd:latest
          ports:
            - containerPort: 80
         volumeMounts:
           - name: httpd-configmap-datacenter
             mountPath: /usr/share/nginx/html/
       volumes:
         - name: httpd-configmap-datacenter

I had it without the 1st time and got the following error.
=Error parsing httpd-deployment-datacenter.yaml: error converting YAML to JSON. Line 19: did not find expected key.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment-datacenter
spec:
  selector:
    matchLabels:
      app: httpd_app_datacenter
  replicas: 4
  template:
    metadata:
      labels:
        app: httpd_app_datacenter
    spec:
      containers:
      - name: httpd-container-datacenter
        image: httpd:latest
        ports:
        - containerPort: 80
       volumeMounts:
       - name: httpd-configmap-datacenter
       mountPath: /usr/share/nginx/html/
       volumes:
       - name: httpd-configmap-datacenter

I copied your updated yaml and got the following error, but there is the “-” that you entered, so not sure why it’s not seeing it.

error: error parsing httpd-deployment-datacenter.yaml: error converting YAML to JSON: yaml: line 18: did not find expected ‘-’ indicator

Yours is still messed up - please do look at the API docs. Pasting mine into a YAML-to-JSON converter shows I mistyped some whitespace, too. The below passes that test, but I didn’t try to run it.

kind: Deployment
metadata:
  name: httpd-deployment-datacenter
spec:
  selector:
    matchLabels:
      app: httpd_app_datacenter
  replicas: 4
  template:
    metadata:
      labels:
        app: httpd_app_datacenter
    spec:
      containers:
        - name: httpd-container-datacenter
          image: httpd:latest
          ports:
            - containerPort: 80
          volumeMounts:
            - name: httpd-configmap-datacenter
              mountPath: /usr/share/nginx/html/
      volumes:
        - name: httpd-configmap-datacenter

This one worked! Thank a bunch for all of your help. Just getting started in Kubernetes, day 2 actually. Will read up more. :slightly_smiling_face: :+1: