Published on

Using a Helm Chart to Simplify Management of Common Kubernetes Dependencies


In most projects I work on there are common dependencies I want run but these dependencies do not change very often. For example I may have a docker secret (to my private docker registry) in my namespace that I want available to all charts that run in that namespace. Adding this secret to each chart is problematic as chart-1 will install fine but chart-2 will fail as the common secret is already installed.

You can obviously simply have a Kubernetes secret yaml file configuration for this and kubectl apply -f docker-registry-secret.yaml. But if you want to add other common dependencies you need to add additional kubectl apply -f to your build scripts for each new dependency. The same goes for any delete scripts you have where you need to kubectl delete -f each dependency.

I have found that making a simple helm-chart for this automates this whole process as helm will kubectl apply -f each file in the templates directory when you helm install your-chart and conversely it will kubectl delete -f each file in the templates directory when you helm delete your-chart. You also only need to install the common helm chart once and can install any other charts you need to into that namespace afterwards.

The structure of this chart is very straightforward:

> helm-chart-common:
  > Chart.yaml
  > templates
    > docker-registry-secret.yaml
  > values.yaml

These files are all very basic:

  • Chart.yaml
apiVersion: v1
appVersion: '1.0'
description: your-app
name: your-app
version: 0.1.0
  • values.yaml: this is intentionally blank as we have no values to configure
# Default values for helm-chart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
  • docker-registry-secret.yaml
apiVersion: v1
kind: Secret
  name: dockerprivateregistrysecret
  namespace: yourNamespace
  .dockerconfigjson: yourSecretHere

In my case there was no need to have any configurable values but you can add them if need be.