Hi, Lets understand about Chart Hooks. Already we discussed about chart hooks where we can add a hook to do the testing
which will not get deployed as a component as a part of kubernetes cluster, but will get executed so
that I can utilize that particular execution for testing.
Let's have a detailed discussion about hooks where hooks can get triggered at various stages of the chart
lifecycle like pre-install, post-install, pre-delete, pre-upgrade, post-uprade, pre-rollback
Post-rollback. As the name suggest
I can get the hook executed before or after a specific stage of the chart, and I can make use of that
particular execution for testing purpose to make sure we do
have all the prerequired requisites for example, before doing the
upgrade, I can make some process to get triggered and even for example, post-rollback I can trigger some
process to get invoked so that the other processes or other pods can take care of it.
Let's see through some example, let me go ahead and create a chart with the name hooktest. As a part
of the templates within hooktest I can get into the templates.
Here's where I'm going to create the hooks.
I can mention a particular component as a hook by adding an annotation.
saying that is a hook and at what state that particular hook should get triggered.
Let me go ahead and create pre-install and post install
hook. For that I will be creating separate yaml files. Let me create
yaml file and add the content. Here I do have the annotation with the key
It is a hook and at what stage it should get triggered.
Basically it is going to start a container and that's going to sleep for fifteen seconds and get stopped.
The same way let me go ahead and create another hook. Let me add the content for this specific hook.
Here I have mentioned the hook as a post install
So after the installation of the helm chart this particular hook will get triggered and within the
hook it's going to echo this particular statement and sleep for ten seconds.
Now, I do have two hooks.
Let me go ahead and check the components as a part of kubernetes cluster.
I did not have any pods related to this particular chart. Let me install this hook.
I'm installing with the command helm install hooktest install and then the chart resources.
So it's going to trigger the pre-install hook.
And since we gave the sleep command it's going to sleep for certain duration, then the actual chart
will get installed. Then post install
hook should get triggered. Pre-install hook is successful then the pod should get installed
Yes, the Chart installation is successful and it is deployed.
Let me check the status of the chart helm list
hooktest install is successfully installed.
Let me check the status of this particular deployment, helm status and then the name of the deployment.
It is successfully deployed. Now, let me go ahead and get the status of the pods.
So if you look at very carefully, this is the pod that got deployed as a part of this particular chart
hooktest install and two pods that got executed
And it got over. It came to the status completed.
Now, let me go ahead and get more description about this particular pod that is pre-install hook
pod and grep the annotation tag started and finished information from describe kubectl describe the
pre-install hook pod and grep the annotation started and finished.
Values. So within that, this is the started
So it started in 22 seconds and got over in 37 seconds.
Now, let me get the details about this particular pod and get the information.
So this particular pod is still running. So it started in 42 seconds.
So basically after the pre-install hook got over it started its deployment and it successfully
started in 42 second. Now, let me get the details about post-install hook.
Post-install hook started in 41th second.
So basically, like with microseconds, if you consider the post-install it started and it got over
in 51 seconds. So that's the overlap.
So don't worry about this particular overlap. So what's going to happen
Pre-install hook will get triggered before the deployment of the pod and post-install hook will
get triggered after the deployment of the pod.
And I can make use of this particular staged execution to validate as well as to verify the resources or any pre-check
I wanted to do before or after the deployment of the charts. So in a quick summary we discussed about the
introduction about hooks and how to make use of the pre-install and post-install hook
Now let me go ahead and clear this particular deployment.
Let me delete the deployment using helm delete and the name of the deployment.
Also, I need to explicitly delete the completed pods.
So this completed pods I need to explicitly delete so I'll use the command kubectl delete and then
name of the pod, the same way I will delete the post-install hook pod as well.
So both are deleted. Now, let me get the list of pods.
So I do not have any pods related to this hook. The same way
I can make the hooks to get triggered for the jobs as well. Within Kubernetes
We do have another component called Jobs when the jobs getting executed before and after execution
I can make the hooks to get triggered
Let's see that in the next example as well as
We can set the weightage for the hooks also. In case if I have multiple hooks which hook should get
triggered based on the weightage it can decide that example
also we will be seeing in the future lecture.