1
00:00:00,000 --> 00:00:13,033
Hi, Lets understand about Chart Hooks. Already we discussed about chart hooks where we can add a hook to do the testing

2
00:00:13,033 --> 00:00:18,933
which will not get deployed as a component as a part of kubernetes cluster, but will get executed so

3
00:00:18,933 --> 00:00:22,533
that I can utilize that particular execution for testing.

4
00:00:22,533 --> 00:00:30,133
Let's have a detailed discussion about hooks where hooks can get triggered at various stages of the chart

5
00:00:30,133 --> 00:00:37,299
lifecycle like pre-install, post-install, pre-delete, pre-upgrade, post-uprade, pre-rollback

6
00:00:37,300 --> 00:00:39,400
Post-rollback. As the name suggest

7
00:00:39,400 --> 00:00:47,400
I can get the hook executed before or after a specific stage of the chart, and I can make use of that

8
00:00:47,400 --> 00:00:51,266
particular execution for testing purpose to make sure we do

9
00:00:51,266 --> 00:00:56,132
have all the prerequired requisites for example, before doing the

10
00:00:56,133 --> 00:01:03,299
upgrade, I can make some process to get triggered and even for example, post-rollback I can trigger some

11
00:01:03,300 --> 00:01:09,433
process to get invoked so that the other processes or other pods can take care of it.

12
00:01:09,433 --> 00:01:16,333
Let's see through some example, let me go ahead and create a chart with the name hooktest. As a part

13
00:01:16,333 --> 00:01:21,033
of the templates within hooktest I can get into the templates.

14
00:01:21,033 --> 00:01:24,133
Here's where I'm going to create the hooks.

15
00:01:24,133 --> 00:01:28,133
I can mention a particular component as a hook by adding an annotation.

16
00:01:28,133 --> 00:01:34,299
saying that is a hook and at what state that particular hook should get triggered.

17
00:01:34,300 --> 00:01:37,966
Let me go ahead and create pre-install and post install

18
00:01:37,966 --> 00:01:43,199
hook. For that I will be creating separate yaml files. Let me create

19
00:01:43,200 --> 00:01:53,600
yaml file and add the content. Here I do have the annotation with the key

20
00:01:53,600 --> 00:01:57,000
It is a hook and at what stage it should get triggered.

21
00:01:57,000 --> 00:02:03,766
Basically it is going to start a container and that's going to sleep for fifteen seconds and get stopped.

22
00:02:03,766 --> 00:02:13,999
The same way let me go ahead and create another hook. Let me add the content for this specific hook.

23
00:02:14,000 --> 00:02:16,800
Here I have mentioned the hook as a post install

24
00:02:16,800 --> 00:02:23,633
So after the installation of the helm chart this particular hook will get triggered and within the

25
00:02:23,633 --> 00:02:29,366
hook it's going to echo this particular statement and sleep for ten seconds.

26
00:02:29,366 --> 00:02:32,966
Now, I do have two hooks.

27
00:02:32,966 --> 00:02:41,566
Let me go ahead and check the components as a part of kubernetes cluster.

28
00:02:41,566 --> 00:02:51,066
I did not have any pods related to this particular chart. Let me install this hook.

29
00:02:51,066 --> 00:02:57,532
I'm installing with the command helm install hooktest install and then the chart resources.

30
00:02:57,533 --> 00:03:00,899
So it's going to trigger the pre-install hook.

31
00:03:00,900 --> 00:03:07,233
And since we gave the sleep command it's going to sleep for certain duration, then the actual chart

32
00:03:07,233 --> 00:03:10,299
will get installed. Then post install

33
00:03:10,300 --> 00:03:17,900
hook should get triggered. Pre-install hook is successful then the pod should get installed

34
00:03:17,900 --> 00:03:21,300
Yes, the Chart installation is successful and it is deployed.

35
00:03:21,300 --> 00:03:25,933
Let me check the status of the chart helm list

36
00:03:25,933 --> 00:03:28,966
hooktest install is successfully installed.

37
00:03:28,966 --> 00:03:37,499
Let me check the status of this particular deployment, helm status and then the name of the deployment.

38
00:03:37,500 --> 00:03:46,633
It is successfully deployed. Now, let me go ahead and get the status of the pods.

39
00:03:46,633 --> 00:03:53,466
So if you look at very carefully, this is the pod that got deployed as a part of this particular chart

40
00:03:53,466 --> 00:03:58,299
hooktest install and two pods that got executed

41
00:03:58,300 --> 00:04:03,000
And it got over. It came to the status completed.

42
00:04:03,000 --> 00:04:08,200
Now, let me go ahead and get more description about this particular pod that is pre-install hook

43
00:04:08,200 --> 00:04:16,600
pod and grep the annotation tag started and finished information from describe kubectl describe the

44
00:04:16,600 --> 00:04:22,600
pre-install hook pod and grep the annotation started and finished.

45
00:04:22,600 --> 00:04:26,200
Values. So within that, this is the started

46
00:04:26,200 --> 00:04:31,133
So it started in 22 seconds and got over in 37 seconds.

47
00:04:31,133 --> 00:04:37,266
Now, let me get the details about this particular pod and get the information.

48
00:04:37,266 --> 00:04:42,366
So this particular pod is still running. So it started in 42 seconds.

49
00:04:42,366 --> 00:04:49,599
So basically after the pre-install hook got over it started its deployment and it successfully

50
00:04:49,600 --> 00:04:58,300
started in 42 second. Now, let me get the details about post-install hook.

51
00:04:58,300 --> 00:05:01,000
Post-install hook started in 41th second.

52
00:05:01,000 --> 00:05:07,566
So basically, like with microseconds, if you consider the post-install it started and it got over

53
00:05:07,566 --> 00:05:11,799
in 51 seconds. So that's the overlap.

54
00:05:11,800 --> 00:05:14,766
So don't worry about this particular overlap. So what's going to happen

55
00:05:14,766 --> 00:05:19,932
Pre-install hook will get triggered before the deployment of the pod and post-install hook will

56
00:05:19,933 --> 00:05:22,799
get triggered after the deployment of the pod.

57
00:05:22,800 --> 00:05:29,800
And I can make use of this particular staged execution to validate as well as to verify the resources or any pre-check

58
00:05:29,800 --> 00:05:37,300
I wanted to do before or after the deployment of the charts. So in a quick summary we discussed about the

59
00:05:37,300 --> 00:05:42,533
introduction about hooks and how to make use of the pre-install and post-install hook

60
00:05:42,533 --> 00:05:46,166
Now let me go ahead and clear this particular deployment.

61
00:05:46,166 --> 00:05:54,299
Let me delete the deployment using helm delete and the name of the deployment.

62
00:05:54,300 --> 00:06:02,333
Also, I need to explicitly delete the completed pods.

63
00:06:02,333 --> 00:06:09,299
So this completed pods I need to explicitly delete so I'll use the command kubectl delete and then

64
00:06:09,300 --> 00:06:14,666
name of the pod, the same way I will delete the post-install hook pod as well.

65
00:06:14,666 --> 00:06:23,066
So both are deleted. Now, let me get the list of pods.

66
00:06:23,066 --> 00:06:27,666
So I do not have any pods related to this hook. The same way

67
00:06:27,666 --> 00:06:33,699
I can make the hooks to get triggered for the jobs as well. Within Kubernetes

68
00:06:33,700 --> 00:06:39,866
We do have another component called Jobs when the jobs getting executed before and after execution

69
00:06:39,866 --> 00:06:42,632
I can make the hooks to get triggered

70
00:06:42,633 --> 00:06:45,699
Let's see that in the next example as well as

71
00:06:45,700 --> 00:06:51,733
We can set the weightage for the hooks also. In case if I have multiple hooks which hook should get

72
00:06:51,733 --> 00:06:55,299
triggered based on the weightage it can decide  that example

73
00:06:55,300 --> 00:06:57,700
also we will be seeing in the future lecture.

