# Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "metadata.spec"

**URL:** <https://discuss.kubernetes.io/t/deployment-in-version-v1-cannot-be-handled-as-a-deployment-strict-decoding-error-unknown-field-metadata-spec/24621>\
**Category:** General Discussions\
**Created:** [June 27, 2023, 3:17am UTC](https://discuss.kubernetes.io/t/deployment-in-version-v1-cannot-be-handled-as-a-deployment-strict-decoding-error-unknown-field-metadata-spec/24621 "2023-06-27T03:17:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bravikr](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/bravikr/32/12781_2.png) [@bravikr](https://discuss.kubernetes.io/u/bravikr)\
**Post date:** [June 27, 2023, 3:17am UTC](https://discuss.kubernetes.io/t/deployment-in-version-v1-cannot-be-handled-as-a-deployment-strict-decoding-error-unknown-field-metadata-spec/24621/1 "2023-06-27T03:17:19Z")

</div>

### Describe the issue

Deployment in version “v1” cannot be handled as a Deployment: strict decoding error: unknown field “metadata.spec”

Get the above error with latest version of kubernetes

Engine:  
Version: 24.0.2  
API version: 1.43 (minimum version 1.12)  
Go version: go1.20.4  
Git commit: 659604f  
Built: Thu May 25 21:52:17 2023  
OS/Arch: linux/amd64  
Experimental: false  
containerd:  
Version: 1.6.21  
GitCommit: 3dce8eb055cbb6872793272b4f20ed16117344f8  
runc:  
Version: 1.1.7  
GitCommit: v1.1.7-0-g860f061  
docker-init:  
Version: 0.19.0  
GitCommit: de40ad0

Client Version: v1.25.9  
Kustomize Version: v4.5.7  
Server Version: v1.26.3

trying to do the deployment using below yaml file

apiVersion: apps/v1  
kind: Deployment  
metadata:  
name: mongodb-deployment  
labels:  
app: mongodb  
spec:  
replicas: “1”  
selector:  
matchLabels:  
app: mongodb  
template:  
metadata:  
labels:  
app: mongodb  
spec:  
containers:

- name: mongodb  
image: mongo  
ports:
- containerPort: “27107”  
env:
- name: MONGO\_INITDB\_ROOT\_USERNAME  
valueFrom:  
secretKeyRef:  
name: mongodb-secret  
key: mongo-root-username
- name: MONGO\_INITDB\_ROOT\_PASSWORD  
valueFrom:  
secretKeyRef:  
name: mongodb-secret  
key: mongo-root-password

---

<div class="post-metadata">

**Author:** ![Ramakanth](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/ramakanth/32/12808_2.png) [@Ramakanth](https://discuss.kubernetes.io/u/Ramakanth)\
**Post date:** [June 30, 2023, 9:24pm UTC](https://discuss.kubernetes.io/t/deployment-in-version-v1-cannot-be-handled-as-a-deployment-strict-decoding-error-unknown-field-metadata-spec/24621/2 "2023-06-30T21:24:20Z")

</div>

Got the same issue. Please share the solution or workaround for resolving this issue if known

---

<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:** [June 30, 2023, 9:49pm UTC](https://discuss.kubernetes.io/t/deployment-in-version-v1-cannot-be-handled-as-a-deployment-strict-decoding-error-unknown-field-metadata-spec/24621/3 "2023-06-30T21:49:34Z")

</div>

Given the error (metadata.spec) I am 100% confident you have an indenting problem.

---

<div class="post-metadata">

**Author:** ![MovieMaker93](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/moviemaker93/32/12859_2.png) [@MovieMaker93](https://discuss.kubernetes.io/u/MovieMaker93)\
**Post date:** [July 11, 2023, 10:50am UTC](https://discuss.kubernetes.io/t/deployment-in-version-v1-cannot-be-handled-as-a-deployment-strict-decoding-error-unknown-field-metadata-spec/24621/4 "2023-07-11T10:50:23Z")

</div>

Can you post with indentation?

---

<div class="post-metadata">

**Author:** ![A\_K\_M\_Shafiul\_Hasan](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/a_k_m_shafiul_hasan/32/13400_2.png) [@A\_K\_M\_Shafiul\_Hasan](https://discuss.kubernetes.io/u/A_K_M_Shafiul_Hasan)\
**Post date:** [October 5, 2023, 3:30pm UTC](https://discuss.kubernetes.io/t/deployment-in-version-v1-cannot-be-handled-as-a-deployment-strict-decoding-error-unknown-field-metadata-spec/24621/5 "2023-10-05T15:30:43Z")

</div>

Try with below manifest:

```auto
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
  labels:
    app: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
        - name: mongodb
          image: mongo
          ports:
            - containerPort: 27107
          env:
            - name: MONGO_INITDB_ROOT_USERNAME
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: mongo-root-username
            - name: MONGO_INITDB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: mongo-root-password
          resources:
            limits:
              cpu: 64m
              memory: 256Mi

```

---

<div class="post-metadata">

**Author:** ![mamadmal](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/mamadmal/32/18450_2.png) [@mamadmal](https://discuss.kubernetes.io/u/mamadmal)\
**Post date:** [August 19, 2026, 10:47pm UTC](https://discuss.kubernetes.io/t/deployment-in-version-v1-cannot-be-handled-as-a-deployment-strict-decoding-error-unknown-field-metadata-spec/24621/6 "2026-08-19T22:47:34Z")

</div>

most likely, there’s a sysntax error in manifest. if you fix this issue will be resolved. fix the place of metadata.spec in manifest, this is important not the first error [version “v1”] thing.
