while i'm trying to run below yaml file,i got one error as " mapping values are not allowed in this context at line 10 column 14"

11/18/2019
apiVersion: v1
kind: Service
metadata:
   name: my-emp
   labels:
     run: my-emp
spec:
   ports:
    port: 80
     protocol: TCP
     targetPort: 8888
   type: NodePort
   selector:
     run: my-emp
---
apiVersion: apps/v1
kind: Deployment
metadata:
   name: my-emp
spec:
   replicas: 2
   template:
     metadata:
       labels:
         run: my-emp
   spec:
     containers:
      name: my-emp
       image: kavisuresh/employee
       ports:
        containerPort: 8888
-- harish hari
kubernetes
minikube
yaml

1 Answer

11/18/2019

The problem is that you have "–" (an en dash) where you want "-" (a hyphen).

I'm guessing you wrote this in a text editor that automatically does "smart" substitutions like " to , and when you typed - you got instead. If that's the case it will be worth your while to make sure those features are turned off, or switch to a "programmer's editor" like Visual Studio Code, Sublime Text, Atom, Vim, etc.

To fix the problem, replace the en dashes on lines 9, 28, and 31 with hyphens (and make sure your editor doesn't override them):

apiVersion: v1
kind: Service
metadata:
   name: my-emp
   labels:
     run: my-emp
spec:
   ports:
   - port: 80
     protocol: TCP
     targetPort: 8888
   type: NodePort
   selector:
     run: my-emp
---
apiVersion: apps/v1
kind: Deployment
metadata:
   name: my-emp
spec:
   replicas: 2
   template:
     metadata:
       labels:
         run: my-emp
   spec:
     containers:
     - name: my-emp
       image: kavisuresh/employee
       ports:
       - containerPort: 8888
-- Jordan Running
Source: StackOverflow