Jenkins on Kubernetes service yaml parsing error

2/10/2022

I'm following this Link to setup Jenkins on Kubernetes cluster. When I tried to apply jenkins-svc.yaml it fails with an error.

jenkins-svc.yaml file content as follows,

apiVersion: v1
kind: Service
metadata:
  name: jenkins-ui-service
  namespace: jenkins
spec:
    type: ClusterIP # NodePort, LoadBalancer 
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      # nodePort: 30100
      name: ui
  selector:
    app: jenkins
--- 
apiVersion: v1
kind: Service
metadata:
  name: jenkins-jnlp-service
  namespace: jenkins
spec:
    type: ClusterIP # NodePort, LoadBalancer
  ports:
    - port: 50000
      targetPort: 50000
  selector:
    app: jenkins

The error I get when I tried to apply jenkins-svc.yaml.

# kubectl  apply -f jenkins-svc.yaml -n jenkins
error: error parsing jenkins-svc.yaml: error converting YAML to JSON: yaml: line 7: did not find expected key

Please let me know how do I solve this issue?

-- user4948798
jenkins
kubernetes
kubernetes-cluster
yaml

1 Answer

2/10/2022

please check indentation of line 7 & 23. remove 2 extra spaces before "type" in spec section for both svc.

-- Anurag Arya
Source: StackOverflow