部署文件中的 Helm 图表卷和volumeMounts

Łuk*_*ski 5 devops kubernetes-helm

我无法让我的图表使用我的volumes, 和volumeMounts值。在我的values.yaml 文件中,我有这样的内容:

volumes:
- name: docker1
  hostPath:
    path: /var/
- name: docker2
  hostPath:
    path: /usr/
- name: docker3
  hostPath:
    path: /opt/
    
volumeMounts:
- name: docker1
  mountPath: /var/
- name: docker2
  mountPath: /usr/
- name: docker3
  mountPath: /opt/
Run Code Online (Sandbox Code Playgroud)

在我的 _deployment.tpl 文件中,我有这样的内容:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "fullname" . }}
  namespace: {{ .Values.namespace }}
  labels:
    {{- include "labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  revisionHistoryLimit: {{ .Values.revisionHistory | default 2 }}
  selector:
    matchLabels:
      {{- include "selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        {{- toYaml .Values.podAnnotations | nindent 8 }}
      labels:
        {{- include "labels" . | nindent 8 }}
    spec:
      imagePullSecrets:
        {{- toYaml .Values.imagePullSecrets | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
              {{- toYaml .Values.image.ports | nindent 10 }}
          env:
              {{- toYaml .Values.env | nindent 10 }}
          volumeMounts:
            - name: {{- toYaml .Values.volumeMounts | default "" | nindent 10 }} 
          volumes:
            - name: {{- toYaml .Values.volumes | default "" | nindent 10 }}     
      nodeSelector:
        {{- toYaml .Values.nodeSelector | nindent 8 }}
      tolerations:
        {{- toYaml .Values.tolerations | nindent 8 }}
{{- end }}
 
Run Code Online (Sandbox Code Playgroud)

我尝试以与环境变量相同的方式安装卷和volumeMounts (它们有效),但遗憾的是它不起作用。

z.x*_*z.x 5

您的代码缩进有问题。

卷应与容器处于相同的缩进水平。

如下:

    spec:
      imagePullSecrets:
        {{- toYaml .Values.imagePullSecrets | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            {{- toYaml .Values.image.ports | nindent 12 }}
          env:
            {{- toYaml .Values.env | nindent 12 }}
          volumeMounts:
            {{- toYaml .Values.volumeMounts | default "" | nindent 12 }} 
      volumes:
        {{- toYaml .Values.volumes | default "" | nindent 8 }}     
      nodeSelector:
        {{- toYaml .Values.nodeSelector | nindent 8 }}
      tolerations:
        {{- toYaml .Values.tolerations | nindent 8 }}
Run Code Online (Sandbox Code Playgroud)

如果要调试模板,可以参考helm官方文档操作。

舵调试

  • 男人,我全心全意地爱你 (3认同)