Annoying issue with yaml which I cannot overcome

10/8/2018

I keep getting

error: error parsing httpd-project-last.yaml.backup1: error converting YAML to JSON: yaml: line 45: did not find expected key

. So the line is the one with key: password I don't know what to do. Pulling my hair for an hour now I keep getting it. Any tips?

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: webandstorage
spec:
  selector:
    matchLabels:
      app: apache
  replicas: 1 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: apache
    spec:
      containers:
      - name: httpd
        image: httpd:latest
        volumeMounts:
        - name: storage
          mountPath: /usr/local/apache2/htdocs/
      volumes:
        - name: storage
          persistentVolumeClaim:
            claimName: pvc1
      dnsPolicy: ClusterFirst
      dnsConfig:
       nameservers:
         - 8.8.8.8
    spec:
      containers:
      - name: mysql
        image: mysql:latest
        volumeMounts:
        - name: data3
          mountPath: /var/lib/mysql
      volumes:
      - name: storage
        persistentVolumeClaim:
            claimName: data
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password
              name: dbparola
       ports:
       - protocol: TCP
         port:8080
-- WhoAmI
cloud
devops
kubernetes
linux

2 Answers

10/8/2018

There are quite a few problems with your configuration. For example: there should be one containers section, and one volumes section. Each container would have a volumeMount specified.

Start by stripping down your definition to just one container, with volumeMounts and volumes, and then think about adding in the second container (but keeping one containers section! Look up yaml lists).

-- dwillams782
Source: StackOverflow

10/9/2018

As the community pointed out, there are some errors in your yaml file. I've fixed the syntax, so it passes a validation test.

In case you will have issues with the configuration, you can always ask another question.

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 kind: Deployment metadata: name: webandstorage spec: replicas: 1 # tells deployment to run 2 pods matching the template selector: matchLabels: app: apache template: metadata: labels: app: apache spec: containers: - name: httpd image: httpd:latest volumeMounts: - name: storage mountPath: /usr/local/apache2/htdocs/ volumes: - name: storage persistentVolumeClaim: claimName: pvc1 dnsPolicy: ClusterFirst dnsConfig: nameservers: - 8.8.8.8 spec: containers: - name: mysql image: mysql:latest volumeMounts: - name: data3 mountPath: /var/lib/mysql volumes: - name: storage persistentVolumeClaim: claimName: data env: - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: key: password name: dbparola ports: - protocol: TCP port:8080

You can check it on any YAML validator online, for example, you can find your yaml here as I left it there as a static link for you.

You can find more information on how to create yaml files in this article or directly in the Kubernetes documentation for Deployments

-- aurelius
Source: StackOverflow