Helm - Subchart dependent on other subchart

8/24/2018

I have a Parent chart with two sub-charts subchart1 and postgres and there is a pre-install job in subchart1 which creates necessary tables/schema's for subchart1 service, where the job is in turn dependent on postgres sub-chart to be installed first, so when I install the parent chart with pre-install job hook, it fails because the postgres sub-chart is not installed yet.

To overcome this problem I changed job from pre-install to post-install or install, used initContainer to wait until postgres sub-chart is installed before starting the job,

the issue now I am facing is how to make sure the job is run before installing the subchart1 when doing an subchart1 upgrade

One way I can think of is have a initContainer in the subchart1 to wait until the job is finished, how to notify subchart1 that the job is finished

-- Coding Ninja
google-kubernetes-engine
kubectl
kubernetes
kubernetes-helm

1 Answer

8/26/2018

Rather than using helm concepts, you can use k8s concepts to solve this problem. You can add a k8s job to your subchart1 which runs to completion and creates the needed tables. The initContainer in other pods can be used to wait for the k8s job to complete. The k8s job can fail if the needed dependency postgres is not up. On failure, k8s will make sure to re-run the job. The job is ran to completion.

Rather than using init-containers to wait, you can also choose to use liveness and readiness-probe. The readiness probe is generally implemented using /ready API. If the readiness-probe fails, no tarffic is sent to the POD. If liveness-probe fails, the POD is restarted. See k8s docs on configuring liveness and readiness probe

-- Jay Rajput
Source: StackOverflow