Error parsing deployment-definition.yaml: error converting YAML to JSON: yaml: line 16: did not find expected key

Hi everyone. Below is the config file for a k8s deployment I am working on and I am new to k8s. Your help would be greatly appreciated.

kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 4
selector:
matchLabels:
type: front-end

To be really sure, it would help to put your YAML into a code block, using the </> key, or using 3 back tics “```” before and after the block, like this:

put your code
  in a block
     that preserves indentation

It might be invalid due to indentation, although I don’t see the required apiVersion key; a valid deployment will look something like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: myapp-pod
  name: myapp-pod
spec:
  replicas: 4
  selector:
    matchLabels:
      app: myapp-pod
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: myapp-pod
    spec:
      containers:
      - image: nginx
        name: nginx-container
        resources: {}

You have a few more keys, of course. But the indentation is essential for it to be valid.

1 Like

Thanks Rob for your help but I am sorry to say the problem persist. Here’s the new code, kindly help with whatever I am doing wrong.

apiVerion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
name: myapp-deployment
labels:
app: “myapp”
type: front-end
spec:
template:
metadata:
creationTimestamp: null
name: “myapp-pod”
labels:
app: “myapp”
type: front-end
spec:
containers:
- name: “nginx-container”
image: “nginx”
spec:
replicas: 4
selector:
matchLabels:
app: “myapp-pod”
type: front-end
resources: {}

We cannot help you if you keep posting the YAML like that. Indentation is part of the syntax so losing the indentation makes it impossible to see where the error might be.

You must use a

code block

1 Like