ValidationError in `deployment.yaml` while executing `helm install` command

Viewed 3142

I am trying to deploy to the Azure Kubernetes cluster using Helm charts. While trying to execute following command:

helm install --namespace custom-namspace my-project ./my-project

I am getting following error:

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: [ValidationError(Deployment.spec.template.spec.volumes[1]): unknown field "namespace" in io.k8s.api.core.v1.Volume, ValidationError(Deployment.spec.template.spec.volumes[1]): missing required field "name" in io.k8s.api.core.v1.Volume]

Following is my deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.serviceName }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ .Values.serviceName }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ .Values.serviceName }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ .Values.serviceAccountName }}
      automountServiceAccountToken: true
      imagePullSecrets:
      containers:
      - image: "{{ .Values.dockerimage }}"
        name: {{ .Values.serviceName }}
        env:
        - name: {{ $key }}
          value: {{ $value  | quote }}
        - name: {{ $key }}
          value: {{ $value  | quote }}
        - name: {{ $key }}
          value: {{ $value  | quote }}
        - name: {{ $key }}
          value: {{ $value  | quote }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - name: HTTP
          containerPort: {{ .Values.appPort }}
          protocol: TCP

        resources:
          requests:
            memory: {{ .Values.appRessource.request.memory }}
            cpu: {{ .Values.appRessource.request.cpu }}
          limits:
            memory: {{ .Values.appRessource.limit.memory }}
            cpu: {{ .Values.appRessource.limit.cpu }}

       volumes:
       - name: secretfiles
         secret:
           secretName: secret-vault
           optional: true
           items:
           - key: some-key
             path: custom/some.key
       - name: custommappings-volume
         configMap:
           name: custommappings
           optional: true
       - name: customxsds-volume
         configMap:
           name: customxsds
           optional: true
       mountPoints:
       - name: secretfiles
         mountPath: "/some-path/secretfiles"
         readOnly: true
       - name: custommappings-volume
         mountPath: /app/some-path/client
         readOnly: true
       - name: customxsds-volume
         mountPath: /app/some-path/xsd/client
         readOnly: true
        {{- with .Values.nodeSelector }}
       nodeSelector:
       {{-  toYaml . | nindent 8 }}
       {{- end }}
       {{- with .Values.affinity }}
       affinity:
       {{- toYaml . | nindent 8 }}
       {{- end }}
       {{- with .Values.tolerations }}
       tolerations:
       {{- toYaml . | nindent 8 }}
       {{- end }}

I have also referred to this Github issue but it didn't serve the purpose.

This is the first time I am working on Kubernetes deployment and Helm chart. I would really grateful for any help.

1 Answers

I tried to debug the helm chart using the following command:

helm template --dry-run --debug --namespace my-namespace my-project ./my-project

Helm Template renders the charts locally on your console by looking up all the variable field values from values.yaml file.

--dry-run basically simulates an helm install command but without connecting with your actual kubernetes cluster.

--debug helps you get more verbose output of above commands.

More details about helm template, --dry-run and debug options

Here, I got to know that the error shown in the question is arising from a dependency chart provided through requirements.yaml

This is how it looks in the console when the helm template command was executed. I have tried to explain what went wrong using comments.

# Source: my-project/charts/some-dependency/templates/deployment.yaml
 apiVersion: apps/v1
 kind: Deployment
 metadata:
   name: some-dependency-name
   namespace: my-namespace
 spec:
   replicas: 1
   selector:
     matchLabels:
       app.kubernetes.io/name: some-dependency-name
       app.kubernetes.io/instance: my-project
   template:
     metadata:
       labels:
         app.kubernetes.io/name: some-dependency-name
         app.kubernetes.io/instance: my-project
     spec:
       serviceAccountName: default
       automountServiceAccountToken: true
       imagePullSecrets:
         - name: xxxxx
       containers:
         - env:
           - name: CLUSTERNAME
             value: "my-cluster"
         ....
         ....
         ....
       volumes:
         - name: my-volume           # This is mis-aligned field.
       - name: my-volume             # This is the correct indentation of 'name' field
         - namespace: my-namespace   # This is unknown field here. Need to be removed.
Related