Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the error in YAML file converting yaml to JSON? mapping values are not allowed in this context"

I have been breaking my head trying to understand what the issue is, it shows the following error message:

error parsing feedback.yaml: error converting YAML to JSON: yaml: line 10: mapping values are not allowed in this context

apiVersion: v1
kind: Service
metadata:
   name: feedback
   labels:
     run: feedback
spec:
   ports:
   – port: 80
     targetPort: 3000
     protocol: TCP
   type: NodePort
   selector:
     run: feedback

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
   name: feedback
spec:
   replicas: 1
   template:
     metadata:
       labels:
         run: feedback
   spec:
     containers:
     – name: feedback
       image: username/feedback
       ports:
       – containerPort: 8888
---
apiVersion: v1
kind: Service
metadata:
   name: mongo
   labels:
     run: mongo
spec:
   ports:
   – port: 27017
     targetPort: 27017
     protocol: TCP
   selector:
     run: mongo

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
   name: mongo
spec:
   template:
     metadata:
       labels:
         run: mongo
     spec:
       containers:
       – name: mongo
         image: mongo
         ports:
         – containerPort: 27017

I have checked it using a yaml validator and also checked the spacing, am I missing something?

like image 825
Debjani Avatar asked Feb 23 '20 21:02

Debjani


1 Answers

This was a weird one. Turns out your hyphens were the wrong type :) all your instances of - were actually – (see the difference? one's longer).

Here's a working file:

apiVersion: v1
kind: Service
metadata:
  name: feedback
  labels:
    run: feedback
spec:
  ports:
    - port: 80
      targetPort: 3000
      protocol: TCP
  type: NodePort
  selector:
    run: feedback

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: feedback
spec:
  replicas: 1
  template:
    metadata:
      labels:
        run: feedback
  spec:
    containers:
      - name: feedback
        image: username/feedback
        ports:
          – containerPort: 8888
---
apiVersion: v1
kind: Service
metadata:
  name: mongo
  labels:
    run: mongo
spec:
  ports:
    - port: 27017
      targetPort: 27017
      protocol: TCP
  selector:
    run: mongo

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mongo
spec:
  template:
    metadata:
      labels:
        run: mongo
    spec:
      containers:
        - name: mongo
          image: mongo
          ports:
            - containerPort: 27017

Side note: this is definitely not node.js – please tag as kubernetes

like image 58
Andy Mardell Avatar answered Nov 15 '22 07:11

Andy Mardell