Invalid Kubernetes YAML Spec. mapping values are not allowed here

6/17/2021

I am trying to deploy my Kubernetes app and it keeps throwing the error:

Exception while processing templates/deployment.yaml
ERROR   2021-06-17 14:57:05    Invalid Kubernetes YAML Spec. mapping values are not allowed here
ERROR   2021-06-17 14:57:05     in 'string', line 27, column 24:
ERROR   2021-06-17 14:57:05                      valueFrom:

From this error, I can at least narrow it down to my deployment.yaml file. Further with the "valueFrom" error, I can follow it down to "env:" section. From there I believe it to be a formatting issue.

Deployment.yaml

{{- if .Values.env.config}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{.Values.name}}
data:
{{.Values.env.config | toYaml | indent 2}}
---
{{- end}}

{{- if .Values.env.secrets}}
apiVersion: v1
kind: Secret
metadata:
  name: {{.Values.name}}
stringData:
{{.Values.env.secrets | toYaml | indent 2}}
---
{{- end}}

{{- if .Values.dockercfg}}
apiVersion: v1
kind: Secret
metadata:
  name: {{.Values.name}}-dockercfg
  annotations:
    harness.io/skip-versioning: true
data:
  .dockercfg: {{.Values.dockercfg}}
type: kubernetes.io/dockercfg
---
{{- end}}

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{.Values.name}}-deployment
spec:
  replicas: {{int .Values.replicas}}
  selector:
    matchLabels:
      app: {{.Values.name}}
  template:
    metadata:
      labels:
        app: {{.Values.name}}
        tags.datadoghq.com/env: {{.Values.environment_name}}
        tags.datadoghq.com/service: {{.Values.name}}
        tags.datadoghq.com/version: "{{.Values.version}}"
    spec:
      {{- if .Values.dockercfg}}
      imagePullSecrets:
      - name: {{.Values.name}}-dockercfg
      {{- end}}
      serviceAccountName: {{.Values.name}}-service-account
      containers:
      - name: {{.Values.name}}
        image: {{.Values.image}}
        env:
          - name: FILE_SYSTEM_ID
              valueFrom:
                configMapKeyRef:
                  name: efs-provisioner
                  key: file.system.id
          - name: AWS_REGION
              valueFrom:
                configMapKeyRef:
                  name: efs-provisioner
                  key: aws.region
          - name: PROVISIONER_NAME
              valueFrom:
                configMapKeyRef:
                  name: efs-provisioner
                  key: provisioner.name
          - name: DD_AGENT_HOST
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
          volumeMounts:
            - name: pv-volume
              mountPath: /usr/local/share/mapserver
      volumes:
        - name: pv-volume
          nfs:
            server: {{.Values.EFS_ID}}.efs.{{.Values.AWS_REGION}}.amazonaws.com
            path: /
        {{- if or .Values.env.config .Values.env.secrets}}
        envFrom:
        {{- if .Values.env.config}}
        - configMapRef:
            name: {{.Values.name}}
        {{- end}}
        {{- if .Values.env.secrets}}
        - secretRef:
            name: {{.Values.name}}
        {{- end}}
        {{- end}}

I am new to using Kubernetes and YAML. I believe this to be a formatting issue, however whereever I look the formatting looks correct.

-- sd-gallowaystorm
kubernetes

1 Answer

6/17/2021

Looks like this is an indentation issue:

- name: FILE_SYSTEM_ID
    valueFrom:
      configMapKeyRef:

should be

- name: FILE_SYSTEM_ID
  valueFrom:
    configMapKeyRef:
-- Berk Soysal
Source: StackOverflow