当我试图 运行 below yaml 文件时,我得到一个错误,因为“在第 10 行第 14 列的上下文中不允许映射值”

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"

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

问题是你有“–”(en dash) where you want "-" (a hyphen)。

我猜你是在文本编辑器中写的,它会自动执行 "smart" 替换,例如 ",当你输入 - 时,你会得到 代替。如果是这种情况,确保关闭这些功能或切换到 "programmer's editor" 是值得的,例如 Visual Studio Code、Sublime Text、Atom、Vim 等

要解决此问题,请将第 9、28 和 31 行的破折号替换为连字符(并确保您的编辑器不会覆盖它们):

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