Kustomize and Helm

Helm becomes the de facto standard for packaging 3rd party applications. Sometimes the helm chart is not well suited to our needs, we can contribute to this helm chart or fork it or… combine it with kustomize to provide what we need. Kustomize provides HelmChartInflationGenerator which lets you specify which helm chart, and which values to provide and the customization part can be taken from “regular” kustomize.

I’ve taken an example helm chart of the Minecraft server. It’s a pretty extensible helm chart, but it lacks a Kubernetes priorityclass option. So I’ve decided to extend it through the kustomize:

$ tree
.
├── base
│   ├── kustomization.yaml
│   ├── prefix-rules.yaml
│   └── priorityclass.yaml
├── dev
│   └── kustomization.yaml
└── prod
    └── kustomization.yaml

$ cat -p base/kustomization.yaml
helmCharts:
- name: minecraft
  includeCRDs: false
  valuesInline:
    minecraftServer:
      eula: true
      difficulty: hard
      rcon:
        enabled: true
  releaseName: moria
  version: 3.1.3
  repo: https://itzg.github.io/minecraft-server-charts
patchesJson6902:
- target:
    version: v1
    kind: Deployment
    name: moria-minecraft
  patch: |-
    - op: add
      path: /spec/priorityClassName
      value: "minecraft"
resources:
  - priorityclass.yaml
configurations:
  - prefix-rules.yaml

$ cat -p base/prefix-rules.yaml
namePrefix:
- path: metadata/name
- path: /spec/template/spec/priorityClassName

$ cat -p base/priorityclass.yaml
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
  name: minecraft
value: 1000000
preemptionPolicy: Never
globalDefault: false

$ cat -p dev/kustomization.yaml
namePrefix:  dev-
resources:
- ../base

$ cat -p prod/kustomization.yaml
namePrefix:  prod-
resources:
- ../base

$ kustomize build --enable-helm prod
...
apiVersion: scheduling.k8s.io/v1
globalDefault: false
kind: PriorityClass
metadata:
  name: prod-minecraft
preemptionPolicy: Never
value: 1000000
...
apiVersion: apps/v1
kind: Deployment
...
      priorityClassName: prod-minecraft
      securityContext:
...

Nice to have another alternative for dealing with unsuited helm charts, but this alternative can be only tagged as a workaround. Helm chart support in kustomize is pretty limited, why it’s described here.

comments powered by Disqus

powered by Hugo and Noteworthy theme