base-cronjob

by Das Meta

Helm chartv0.1.40App 0.1.40

A Base Helm chart for Kubernetes CronJob

About this chart

This helm chart allows to create and configure kubernetes cronjob resources, it designed in way to be able to pass list of cronjobs configs

Public values and options are documented in values.yaml. Example values files: examples/base-cronjob/ (e.g. minimal.yaml). From repo root: helm template test charts/base-cronjob -f examples/base-cronjob/minimal.yaml.

Key values

KeyDescriptionDefault / Example
jobsList of cronjob definitionseach: name, schedule, image (repository, tag), env, etc.
jobs[].nameCronJob namerequired
jobs[].scheduleCron schedule (e.g. "0 * * * *")required
jobs[].image.repositoryContainer imagerequired
jobs[].image.tagImage taglatest
jobs[].rbacOptional Role/ClusterRole and binding for the job ServiceAccountdisabled
jobs[].securityContextOptional container security context{}
jobs[].successfulJobsHistoryLimitNumber of successful finished jobs to retainoptional
jobs[].failedJobsHistoryLimitNumber of failed finished jobs to retainoptional
jobs[].suspendSuspend future CronJob runsoptional
jobs[].jobBackoffLimitNumber of retries before marking a Job failedoptional
jobs[].ttlSecondsAfterFinishedTTL in seconds for finished Jobsoptional

Easy how to

Easiest option to deploy cronjob is:

helm repo add dasmeta https://dasmeta.github.io/helm/
helm upgrade --install my-cronjob dasmeta/base-cronjob \
  --set jobs[0].name=my-cronjob \
  --set jobs[0].image.repository=my-cronjob \
  --set jobs[0].schedule="* * * * *"

Via values file

Values can be supplied via values.yaml.

jobs:
  - name: cronjob1
    schedule: "0 * * * *"
    image:
      repository: my-cronjob
helm repo add dasmeta https://dasmeta.github.io/helm/
helm upgrade --install my-cronjob dasmeta/base-cronjob -f path/to/values.yaml

As sub-chart

Alternatively base chart can be used as sub-chart.

dependencies:
  - name: base
    version: 0.1.36
    repository: https://dasmeta.github.io/helm

Resources

Some resources are created only when you specify them. For example, set this to escape from creating an empty ConfigMap resource:

config:
  enabled: false
  data:
    <data>

Set config.envFrom: false when the ConfigMap is mounted as files and should not be imported as environment variables. Specify this to create ServiceAccount resource:

serviceAccount:
  create: true

Set this to create RBAC for a job:

rbac:
  create: true
  clusterWide: true
  rules:
    - apiGroups:
        - ""
      resources:
        - namespaces
      verbs:
        - get
        - list

Set this to have PVCs for a job:

storage:
  - persistentVolumeClaimName: pvc-job1-storage1
    keepPvc: true
    accessModes:
      - ReadWriteOnce
    volumeMode: Filesystem
    requestedSize: 5Gi
    className: standard
    enableDataSource: false
  - persistentVolumeClaimName: pvc-job1-storage2
    keepPvc: false
    accessModes:
      - ReadWriteMany
    volumeMode: Filesystem
    requestedSize: 10Gi
    className: standard
    enableDataSource: true

Use secrets:

    secrets:
    - APP_NAME:
        from: secret-name
        key: APP_NAME

Deploy base-cronjob with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has base-cronjob on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartbase-cronjob is pinned at v0.1.40 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply