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

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

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

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

Can you post with indentation?