Search code examples
kubernetesdocker-desktop

Docker Desktop error converting YAML to JSON while trying to deploy the voting app


I am using Docker Desktop to run the voting app, I am following the tutorial the link in the command line is deprecated :

kubectl apply -f https://raw.githubusercontent.com/docker/docker-birthday/master/resources/kubernetes-docker-desktop/vote.yaml

So I tried to use the link from this repo :

kubectl apply -f https://github.com/dockersamples/docker-fifth-birthday/blob/master/kubernetes-desktop/kube-deployment.yml

But this error keeps on popping :

error: error parsing https://github.com/dockersamples/docker-fifth-birthday/blob/master/kubernetes-desktop/kube-deployment.yml: error converting YAML to JSON: YAML: line 92: mapping values are not allowed in this context

---
apiVersion: v1
kind: Service
metadata:
  name: result
  labels:
    app: result
spec:
  type: LoadBalancer
  ports:

what am I doing wrong?


Solution

  • I tried to do a get the file to my local to execute but got the same error as 92 line using wget https://github.com/dockersamples/docker-fifth-birthday/blob/master/kubernetes-desktop/kube-deployment.yml. However, I tried just did a copy/paste of the content and it creates services fine but there are 2 issues with the project.

    1. the apiversion in deployment is apps/v1beta it needs to be apps/v1 as per documentation. https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
    2. There are places where the selectors have not been mentioned in the deployments which is why the deployments are not getting created, you might need to fix it. To elaborate, the selectors in the deployments(spec section) have to match the labels of the service (metadata). Below is a working version of service/deployment from the project mentioned.

    On why you would do that? every deployment will run a set of pods,it will Maintain a set of identical pods, ensuring that they have the correct config and that the right number and to access these you will expose a service. these services will look up the deployment based on these labels.

    If you are looking for learning material, you can check the official documentation below. https://kubernetes.io/docs/tutorials/kubernetes-basics/deploy-app/deploy-interactive/

    --- 
    apiVersion: v1
    kind: Service
    metadata: 
      labels: 
        app: redis
      name: redis
    spec: 
      clusterIP: None
      ports:
        - name: redis
          port: 6379
          targetPort: 6379
      selector: 
        app: redis
    ---
    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: redis
      labels:
        app: redis
    spec:
      selector:
        matchLabels:
          app: redis
      replicas: 1
      template:
        metadata:
          labels:
            app: redis
        spec:
          containers:
          - name: redis
            image: redis:alpine
            ports:
            - containerPort: 6379
              name: redis