# Cronjob chart example templates/cronjob.yaml ```yaml= {{- $appName := include "general-template.name" . -}} apiVersion: batch/v1beta1 kind: CronJob metadata: name: {{ include "general-template.name" . }} spec: schedule: "{{ .Values.schedule.cron }}" concurrencyPolicy: "{{ .Values.schedule.concurrencyPolicy }}" jobTemplate: spec: template: spec: containers: - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" name: {{ $appName }}-{{ .Release.Namespace }} env: {{- include "helpers.list-env-variables" . | indent 12 }} restartPolicy: OnFailure {{- if .Values.volume.enabled }} volumes: - name: {{ $appName }}-{{ .Release.Namespace }} persistentVolumeClaim: claimName: {{ $appName }}-{{ .Release.Namespace }} {{- end }} ``` templates/_helpers.tpl ```yaml= {{/* Expand the name of the chart. */}} {{- define "general-template.name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- end }} {{/* Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). If release name contains chart name it will be used as a full name. */}} {{- define "general-template.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} {{- $name := default .Chart.Name .Values.nameOverride }} {{- if contains $name .Release.Name }} {{- .Release.Name | trunc 63 | trimSuffix "-" }} {{- else }} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} {{- end }} {{- end }} {{- end }} {{/* Create chart name and version as used by the chart label. */}} {{- define "general-template.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} {{/* Common labels */}} {{- define "general-template.labels" -}} helm.sh/chart: {{ include "general-template.chart" . }} {{ include "general-template.selectorLabels" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} app.kubernetes.io/managed-by: {{ .Release.Service }} {{- end }} {{/* Selector labels */}} {{- define "general-template.selectorLabels" -}} app.kubernetes.io/name: {{ include "general-template.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} {{/* Create the name of the service account to use */}} {{- define "general-template.serviceAccountName" -}} {{- if .Values.serviceAccount.create }} {{- default (include "general-template.fullname" .) .Values.serviceAccount.name }} {{- else }} {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} {{/* Create helper for environemnt variaableh Usage: {{- include "helpers.list-env-variables" . | indent 12 }} */}} {{- define "helpers.list-env-variables"}} {{- range $key, $val := .Values.envVar }} - name: {{ $val.name | quote }} value: {{ $val.value | quote}} {{- end}} {{- end }} {{/* Renders a value that contains template. Usage: {{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }} */}} {{- define "common.tplvalues.render" -}} {{- if typeIs "string" .value }} {{- tpl .value .context }} {{- else }} {{- tpl (.value | toYaml) .context }} {{- end }} {{- end -}} ``` templates/PersistentVolume.yaml ```yaml= {{- $appName := include "general-template.name" . -}} {{- if .Values.volume.enabled }} apiVersion: v1 kind: PersistentVolume metadata: name: {{ $appName }}-{{ .Release.Namespace }} spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain #storageClassName: nfs nfs: server: {{ .Values.volume.server }} path: {{ .Values.volume.path }} --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: {{ $appName }}-{{ .Release.Namespace }} spec: accessModes: - ReadWriteOnce storageClassName: '' # volumeMode: Filesystem volumeName: {{ $appName }}-{{ .Release.Namespace }} resources: requests: storage: 5Gi {{- end }} ``` templates/serviceaccount.yaml ```yaml= {{- if .Values.serviceAccount.create -}} apiVersion: v1 kind: ServiceAccount metadata: name: {{ include "general-template.serviceAccountName" . }} labels: {{- include "general-template.labels" . | nindent 4 }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} {{- end }} {{- end }} ``` Chart.yaml ``` apiVersion: v2 name: cronjob description: A Helm chart for Kubernetes type: application version: 0.1.0 appVersion: "0.1.0" ``` values.yaml ```yaml= image: repository: "" tag: "" schedule: cron: "5 3 * * *" concurrencyPolicy: "Forbid" volume: enabled: true mountPath: server: path: imagePullSecrets: [] nameOverride: "" fullnameOverride: "" serviceAccount: create: true annotations: {} name: "" podAnnotations: {} podSecurityContext: {} securityContext: {} service: type: ClusterIP port: 8080 targetPort: 8080 route: enabled: #for openshift annotations: {} ingress: enabled: false annotations: {} hosts: - host: chart-example.local paths: - path: / backend: serviceName: chart-example.local servicePort: 80 tls: [] resources: {} autoscaling: enabled: false minReplicas: 1 maxReplicas: 100 targetCPUUtilizationPercentage: 80 nodeSelector: {} tolerations: [] affinity: {} envVar: - name: key value: value - name: key1 value: value1 - name: key2 value: value2 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up