执行 `helm install` 命令时 `deployment.yaml` 出现验证错误

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

我正在尝试使用 Helm 图表部署到 Azure Kubernetes 集群。 尝试执行以下命令时:

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

我收到以下错误:

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]

以下是我的 deployment.yaml 文件:

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 }}

我也提到过这个 Github issue 但它没有达到目的。

这是我第一次从事 Kubernetes 部署和 Helm chart 方面的工作。如果有任何帮助,我将不胜感激。

我尝试使用以下命令调试 helm 图表:

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

Helm Template 通过从 values.yaml 文件中查找所有变量字段值,在您的控制台上本地呈现图表。

--dry-run 基本上模拟了一个 helm install 命令,但没有连接到您的实际 kubernetes 集群。

--debug 帮助您获得上述命令的更详细输出。

到这里,我知道问题中显示的错误是由 requirements.yaml

提供的依赖关系表引起的

这是执行 helm template 命令时在控制台中的样子。我试图用评论来解释问题所在。

# 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.