1
00:00:02,200 --> 00:00:03,850
With that we're almost done

2
00:00:03,850 --> 00:00:07,290
with these very basics about Kubernetes

3
00:00:07,290 --> 00:00:10,260
and resources with Kubernetes.

4
00:00:10,260 --> 00:00:13,220
There's one a little bit more advanced concept,

5
00:00:13,220 --> 00:00:15,120
which I wanna touch on right now.

6
00:00:15,120 --> 00:00:17,750
And that is related to how Kubernetes

7
00:00:17,750 --> 00:00:20,200
checks whether your pods and containers,

8
00:00:20,200 --> 00:00:22,760
and the pods are healthy or not,

9
00:00:22,760 --> 00:00:26,530
because this can matter in certain applications.

10
00:00:26,530 --> 00:00:27,363
Up to this point,

11
00:00:27,363 --> 00:00:30,580
it always works the way it seems to do it by default

12
00:00:30,580 --> 00:00:33,960
but you can of course configure how it should do that.

13
00:00:33,960 --> 00:00:36,520
And for this deployment Yami file,

14
00:00:36,520 --> 00:00:39,430
I will actually go to my container definition

15
00:00:39,430 --> 00:00:43,930
to change how this container is checked by the pod

16
00:00:43,930 --> 00:00:46,690
to see whether it's up and running.

17
00:00:46,690 --> 00:00:48,550
And we can change this

18
00:00:48,550 --> 00:00:53,550
by adding a so called liveness probe key.

19
00:00:54,650 --> 00:00:56,080
And again, you find this

20
00:00:56,080 --> 00:00:58,140
in your official documentation as well.

21
00:00:58,140 --> 00:01:00,010
If you have a look at the deployment,

22
00:01:00,010 --> 00:01:01,770
the deploymentSpec

23
00:01:01,770 --> 00:01:05,000
they are at the template and the podSpec

24
00:01:05,000 --> 00:01:08,000
there if you dive into the container array,

25
00:01:08,000 --> 00:01:11,220
you find that for containers,

26
00:01:11,220 --> 00:01:13,210
you can configure a lot of things.

27
00:01:13,210 --> 00:01:15,250
For example, all the environment variables

28
00:01:15,250 --> 00:01:17,560
which can become important later

29
00:01:17,560 --> 00:01:19,800
also how the image should be pulled

30
00:01:19,800 --> 00:01:22,683
and here you also find the liveness probe key.

31
00:01:24,920 --> 00:01:27,310
So, how can we configure this?

32
00:01:27,310 --> 00:01:30,810
Well, there you can add a httpGet key,

33
00:01:30,810 --> 00:01:32,470
and of course there are more options,

34
00:01:32,470 --> 00:01:34,040
which you can learn about if you dive

35
00:01:34,040 --> 00:01:36,210
into that probe definition

36
00:01:36,210 --> 00:01:38,080
or simply into the official docs.

37
00:01:38,080 --> 00:01:41,560
If you search for kubernetes liveness probe,

38
00:01:41,560 --> 00:01:45,210
here you find more information and documentation,

39
00:01:45,210 --> 00:01:47,560
but here we can simply define

40
00:01:47,560 --> 00:01:50,270
that a Gethttp request should be sent

41
00:01:50,270 --> 00:01:53,210
by the pod to the running application so to say,

42
00:01:53,210 --> 00:01:56,290
or by Kubernetes to the running application.

43
00:01:56,290 --> 00:01:59,630
We wanna send it to a path of just slash,

44
00:01:59,630 --> 00:02:01,930
but of course that could be another nested path

45
00:02:01,930 --> 00:02:03,603
your application might have,

46
00:02:04,600 --> 00:02:07,710
on port 8080 in our container,

47
00:02:07,710 --> 00:02:10,780
since that's the port this container exposes

48
00:02:10,780 --> 00:02:13,240
maybe with some extra Headers,

49
00:02:13,240 --> 00:02:16,260
but we don't need some here so we can omit this.

50
00:02:16,260 --> 00:02:19,220
And then, on the same level as httpGet

51
00:02:19,220 --> 00:02:21,320
not nested inside of it,

52
00:02:21,320 --> 00:02:25,020
you add the periodSeconds value

53
00:02:25,020 --> 00:02:28,360
where you define how often that should be performed.

54
00:02:28,360 --> 00:02:31,120
For example, all three seconds or 10 seconds,

55
00:02:31,120 --> 00:02:32,620
whatever you want.

56
00:02:32,620 --> 00:02:36,690
In addition, you can add to the initial DelaySeconds key,

57
00:02:36,690 --> 00:02:39,820
where you can tell Kubernetes how long it should wait

58
00:02:39,820 --> 00:02:42,520
until it checks the health for the first time,

59
00:02:42,520 --> 00:02:45,040
for example, five seconds.

60
00:02:45,040 --> 00:02:48,300
And now we've got our own liveness probe in action,

61
00:02:48,300 --> 00:02:52,060
where we define how Kubernetes should verify

62
00:02:52,060 --> 00:02:54,923
whether that container is up and running.

63
00:02:56,090 --> 00:02:58,070
And if I now save this

64
00:02:58,070 --> 00:03:03,040
I can of course again apply the deployment.yaml file

65
00:03:03,040 --> 00:03:05,793
and service.yaml file.

66
00:03:07,580 --> 00:03:11,540
And if you then run minikube service backend

67
00:03:11,540 --> 00:03:15,773
we again get our URL to the deployed application.

68
00:03:16,850 --> 00:03:17,900
Here it is.

69
00:03:17,900 --> 00:03:20,150
But if I now visit slash error

70
00:03:21,670 --> 00:03:25,230
it of course crashed, but it's opens immediately

71
00:03:25,230 --> 00:03:28,600
up and running again because that crash was detected

72
00:03:28,600 --> 00:03:31,980
and the container and the pod was restarted

73
00:03:31,980 --> 00:03:34,520
as you can see if you get your pods.

74
00:03:34,520 --> 00:03:37,890
you see it was restarted once here.

75
00:03:37,890 --> 00:03:40,520
Now that is something which worked before as well.

76
00:03:40,520 --> 00:03:41,840
I will say that,

77
00:03:41,840 --> 00:03:45,070
but it still works with our own liveness probe

78
00:03:45,070 --> 00:03:48,520
and defining such a liveness probe can be very useful

79
00:03:48,520 --> 00:03:50,010
if you have an application

80
00:03:50,010 --> 00:03:52,310
which doesn't react to the default,

81
00:03:52,310 --> 00:03:54,620
or if you simply want to check the health

82
00:03:54,620 --> 00:03:57,220
by sending a request to slash something

83
00:03:57,220 --> 00:03:59,300
instead of just slash.

84
00:03:59,300 --> 00:04:02,830
So knowing how that can be defined can be very helpful

85
00:04:02,830 --> 00:04:05,700
to ensure that your applications work

86
00:04:05,700 --> 00:04:09,163
no matter how they are structured or configured.

