Adding an init-container to a pod in a standard Helm chart

8/23/2019

I am using a standard PostgreSQL Helm chart for deploying the database to a Kubernetes cluster. I need to add logic to the deployment procedure for loading the latest database backup into PostgreSQL. I would like to create an init container for a master pod defined in statefulsets.yaml.

I can add the init container definition directly in statefulsets.yaml template of PostgreSQL chart. I would like to avoid doing that for obvious reasons (applying Open/Closed Principle).

How can I add an init container to PostgreSQL master without modifying the standard Helm chart (e.g., from values.yaml)?

Is there a better way to load the database backup (other than an init container)?

-- Michael Smolyak
database-backups
kubernetes
kubernetes-helm
postgresql

1 Answer

9/13/2019

Add something via values.yaml "without modifying the standard Helm chart" sounds a bit contradictory because the values.yaml itself is part of the chart.

If you still need something more sophisticated to get the DB prepared, and want to stick with the "Open/Closed Principle", you might draw the border between the "Open" and "Closed" in the following manner for example:

  • "Closed part": keep the initContainers section in the Statefulset as a "placeholder" with something like exit 0 as the containers' command;
  • "Open part": provide actual values for the initContainers "image" and "command" as part of values.html.

That way your statefulset will look closed for changes but open for extensions via values.html.

-- mebius99
Source: StackOverflow