【发布时间】:2020-06-19 16:39:30
【问题描述】:
这里的第一天掌舵用户。试图了解如何为 k8s 资源构建通用模板。 假设我在单个图表中有 10 个 cron 作业,所有这些作业仅在参数和名称上有所不同。今天存在 10 个完整的作业清单,并且 95% 的清单内容是相等的。我想移动模板中的公共部分并创建 10 个清单,我将在其中为 args 和名称提供特定值。
所以我定义了模板_cron-job.yaml
{{- define "common.cron-job"}}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ include "costing-report.name" . }}-bom-{{ .Values.env }}
labels:
{{ include "costing-report.labels" . | indent 4 }}
spec:
schedule: "{{ .Values.cronjob.scheduleBom }}"
suspend: {{ .Values.cronjob.suspendBom }}
{{- with .Values.cronjob.concurrencyPolicy }}
concurrencyPolicy: {{ . }}
{{- end }}
{{- with .Values.cronjob.failedJobsHistoryLimit }}
failedJobsHistoryLimit: {{ . }}
{{- end }}
{{- with .Values.cronjob.successfulJobsHistoryLimit }}
successfulJobsHistoryLimit: {{ . }}
{{- end }}
jobTemplate:
metadata:
labels:
app.kubernetes.io/name: {{ include "costing-report.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
template:
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: ["--report=Bom","--email={{ .Values.configmap.service.email_bom }}"]
env:
- name: spring_profiles_active
value: "{{ .Values.env }}"
envFrom:
- configMapRef:
name: {{ include "costing-report.fullname" . }}
- secretRef:
name: {{ .Values.secrets.properties }}
restartPolicy: Never
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end -}}
现在我需要创建覆盖名称和参数 job1.yaml 的作业清单
{{- template "common.cron-job" . -}}
??? override ???
name: {{ include "cost-report.name" . }}-job1-{{ .Values.env }}
jobTemplate:
spec:
template:
spec:
containers:
args: ["--report=Bom","--email={{ .Values.configmap.service.email_bom }}"]
有没有办法做到这一点?我在 helm 文档中没有找到这个。我确实找到了这个https://github.com/helm/charts/tree/master/incubator/common,但它并没有很好地工作并且给了我错误。
谢谢。
【问题讨论】:
-
您使用提供的链接时遇到了什么错误?
标签: templates kubernetes charts overriding kubernetes-helm