管理部署文件中的图表卷和卷挂载



我不能让我的图表使用我的volumesvolumeMounts值。在我的价值观中。我在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/

在我的_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 }}

我尝试用同样的方式挂载卷和volumeMounts,我对环境变量(他们工作),但遗憾的是它不起作用。

你的代码缩进有问题。

volume应该与container保持相同的缩进水平。

:

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

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

执掌调试

最新更新