# Error when adding ConfigMap data into deployment yaml

**URL:** <https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885>\
**Category:** Regional Discussions\
**Created:** [December 19, 2024, 7:33pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885 "2024-12-19T19:33:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tron40a](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/tron40a/32/16505_2.png) [@tron40a](https://discuss.kubernetes.io/u/tron40a)\
**Post date:** [December 19, 2024, 7:33pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/1 "2024-12-19T19:33:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [December 19, 2024, 8:00pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/2 "2024-12-19T20:00:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tron40a](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/tron40a/32/16505_2.png) [@tron40a](https://discuss.kubernetes.io/u/tron40a)\
**Post date:** [December 19, 2024, 8:13pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/4 "2024-12-19T20:13:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tron40a](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/tron40a/32/16505_2.png) [@tron40a](https://discuss.kubernetes.io/u/tron40a)\
**Post date:** [December 19, 2024, 8:18pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/5 "2024-12-19T20:18:51Z")

</div>

```auto
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

```

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [December 19, 2024, 8:30pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/7 "2024-12-19T20:30:06Z")

</div>

> [@tron40a](#):
>
> ```auto
> 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.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![tron40a](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/tron40a/32/16505_2.png) [@tron40a](https://discuss.kubernetes.io/u/tron40a)\
**Post date:** [December 19, 2024, 8:34pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/8 "2024-12-19T20:34:12Z")

</div>

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.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![tron40a](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/tron40a/32/16505_2.png) [@tron40a](https://discuss.kubernetes.io/u/tron40a)\
**Post date:** [December 19, 2024, 8:43pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/9 "2024-12-19T20:43:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [December 19, 2024, 9:07pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/10 "2024-12-19T21:07:30Z")

</div>

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.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![tron40a](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/tron40a/32/16505_2.png) [@tron40a](https://discuss.kubernetes.io/u/tron40a)\
**Post date:** [December 19, 2024, 9:13pm UTC](https://discuss.kubernetes.io/t/error-when-adding-configmap-data-into-deployment-yaml/30885/11 "2024-12-19T21:13:12Z")

</div>

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