env varaible error converting YAML to JSON: yaml: did not find expected key

Viewed 11

I have a deployment file which takes the environment variables from the values.yaml file. Also I want to add one more variable named "PURPOSE".

apiVersion: apps/v1 

kind: Deployment
metadata:
  name: {{ .Values.scheduler.name }}
spec:
  selector:
    matchLabels:
      app: {{ .Values.scheduler.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.scheduler.name }}
    spec:
      containers:
      - name: {{ .Values.scheduler.name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        ports:
          - containerPort: {{ .Values.scheduler.targetPort }}
        imagePullPolicy: Always 
        env: 
            {{- toYaml .Values.envVariables | nindent 10 }}
        - name: PURPOSE 
          value: "SCHEDULER"

The error I get is the following:

error converting YAML to JSON: yaml: line 140: did not find expected key

The env varaibles from the values file work fine, the problem seems to be the variable "PURPOSE"

1 Answers

The problem was the formatting. Solution:

apiVersion: apps/v1 

kind: Deployment
metadata:
  name: {{ .Values.scheduler.name }}
spec:
  selector:
    matchLabels:
      app: {{ .Values.scheduler.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.scheduler.name }}
    spec:
      containers:
      - name: {{ .Values.scheduler.name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        ports:
          - containerPort: {{ .Values.scheduler.targetPort }}
        imagePullPolicy: Always 
        env: 
          - name: PURPOSE 
            value: "SCHEDULER"
            {{- toYaml .Values.envVariables | nindent 10 }}
    
Related