Search code examples
kubernetesyamlindentation

kubectl apply -f service.yml throws error


error: error converting YAML to JSON: yaml: line 2: mapping values are not allowed in this context

This is my service.yml:

apiVersion: v1
 kind: Service
  metadata:
    name: eureka-service
spec:
  type: LoadBalancer
  ports:
    - port: 8761
      targetPort: 8761
  selector:
    app: eureka-naming-server

I don't know what's wrong with this service.yml. I have a running pod on Google Kubernetes with the labels: app eureka-naming-server


Solution

  • In YAML block styles, structure is determined by indentation. Did you space the file as follows?:

    apiVersion: v1
    kind: Service
    metadata:
      name: eureka-service
    spec:
      type: LoadBalancer
      ports:
        - port: 8761
          targetPort: 8761
      selector:
        app: eureka-naming-server