In the Kubernetes environment, you can use the hooks for event-based chart upgrade, downgrade and delete operation.

Helm supports a lot of hooks that related to events, those are pre-install, post-install, pre-delete and etc. For example, if you want to ensure, the deployment process occurred after secrets are created successfully on the Kubernetes environment you can use `pre-install` annotation on your helm chart.

You can get more information about where to use these helm chart hooks from there:

Today I will show you a simple example for pre-delete annotations let’s start a story.

Toros Mountains

Design of the Story

This example is not to have production-grade compliance, but it can give ideas for you.

For these requirements, the helm presents a capability to catch those events like delete , upgrade .. etc.

You can catch the delete event in this annotation shown below.

"": "pre-delete"

This annotation is defined on a pod manifest file, and when the delete event occurred, the pod starts and makes what it should do. In my case, designed a pod to take the snapshot of my MongoDB pod.

command: ['sh', '-c', 'mongodump --host  {{ .Release.Name }}-mongodb {{ .Values.backup.targetDb}}--port 27017']

As a summary, when I run helm delete mychart command and then these annotations catch the event and run the pod.

In this blogpost, I just wanted to tell a story about the concept, but you can use this annotation for a lot of use cases like you can be sure configmap is successfully created before your pods like this annotation :

"": "pre-install"

If you want to learn more information about helm hook annotations you can check the official link from there:

You can check the example in this repository :