error converting YAML to JSON Line did not find expected '-' indicator

2/2/2022

I am new to kubernetes I am writing a yml file to create a deployment. I am crating deployment by running this command "kubectl create -f backend-deployment.yml" but I keep getting this error: "error: error parsing backend-deployment.yml: error converting YAML to JSON: yaml: line 16: did not find expected '-' indicator"

line 16 is - name: django-react-ecommerce-master_backend_1

following is my backend-deployment.yml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name : backend-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: backend
  template:
    metadata:
      labels:
        component: backend
    spec:
      containers:
        - name: django-react-ecommerce-master_backend_1
        ports:
          - containerPort: 8000
-- Usama Hameed
kubernetes
yaml

2 Answers

2/2/2022

The hyphen should have no indentation:

spec:
  containers:
  - name: django-react-ecommerce-master_backend_1
    ports:
    - containerPort: 8000
-- pytness
Source: StackOverflow

2/2/2022

The problem comes from the line below, you have an indentation problem there. ports should be at the same level than name.

# indent the port bloc   
    spec:
      containers:
        - name: django-react-ecommerce-master_backend_1
          ports:
          - containerPort: 8000
-- Marc ABOUCHACRA
Source: StackOverflow