Using Helm Chart Hooks for Effective Management of Release Lifecycle

Raju Dawadi
3 min readApr 14, 2020

--

Helm, if you are new to the world, is an application package manager running atop Kubernetes making it easier to define, install, and upgrade Kubernetes application. Helm is also an incubator project in the CNCF and is maintained by the Helm community.

When we are managing the lifecycle of application which includes install, upgrade, rollback, delete using the charts, won’t it be interesting if we could do some task before and after the changes not by making changes on application but adding manifest definition on helm chart? As everything runs on container, this also can’t go beyond. Here is the structure of typical Chart Hook.

Helm Chart Hook

By using the annotations like helm.sh/hook , we can declare the time it runs like, before or after any changes on lifecycle of the service.

Let’s consider some scenarios when we can use Chart Hook:

Wait for dependency

There might be some dependency of an application service which could be out of the cluster or external dependency. If we have to wait for readiness of any service before starting the new service, hooks comes into play and as soon as the readiness if fulfilled, the installation/upgrade of service happens.

Like, if our service needs database server and connection to be working before starting the process. Here, on the hook we can configure it to wait till the connection is successful and then kick off the application container/pod.

Prepare and Verify Environment

Consider one of the application uses volumes and expect some files, folders to be there before the start. Here, we can employ the hook container to prepare the environment.

Even for database migration or database backup, we can make use of this temporary pod that eases the release process.

Clean Deletion of Application

While removing service from Kubernetes cluster, we need to remove its various touch areas like, file/folder states on PVC, any secrets. For this, by using post-delete hook, we can make sure of dumping any traces.

Notify Release Lifecycle

This is interesting case and makes it easier for sending notifications. Let’s say we need to release a new version of our containerized service and want to get the idea of starting & ending time along with version of the release to slack or email or any api so that we could get some metrics. Also, it makes us easier to track the changes. Here is a simple pod manifest which runs as Helm Chart Hook(Gist):

Post-Install Slack Hook

Here, we can send simply curl to any monitoring endpoint which records the new releases from where we can track the rollout duration also.

Following are the available hooks for maintaining the lifecycle of applications along with the annotations to be used:

Hooks and annotations

Do you have any interesting use cases of Helm Chart Hooks? Feel free to share !

Say Hi to me on Twitter and Linkedin where I keep on sharing interesting updates.

--

--

Raju Dawadi
Raju Dawadi

Responses (1)