1
00:00:02,150 --> 00:00:03,500
Now, to see this in action,

2
00:00:03,500 --> 00:00:04,333
for the moment,

3
00:00:04,333 --> 00:00:08,880
I will stick to this application we worked on thus far

4
00:00:08,880 --> 00:00:10,090
in this course.

5
00:00:10,090 --> 00:00:13,150
Just make sure that you've got no ongoing deployments

6
00:00:13,150 --> 00:00:16,410
with kubectl get deployments

7
00:00:16,410 --> 00:00:18,100
and you shouldn't see anything here.

8
00:00:18,100 --> 00:00:22,500
If you do, use the kubectl delete deployment command

9
00:00:22,500 --> 00:00:25,853
and then specify the name of the deployment to delete it.

10
00:00:26,700 --> 00:00:29,120
Also, make sure you've got no pods,

11
00:00:29,120 --> 00:00:32,100
which you shouldn't have if you have no deployments.

12
00:00:32,100 --> 00:00:33,650
And you've got no services,

13
00:00:33,650 --> 00:00:36,560
except for that default Kubernetes services,

14
00:00:36,560 --> 00:00:37,523
which is fine.

15
00:00:38,520 --> 00:00:41,350
Of course, also ensure that minikube is still up

16
00:00:41,350 --> 00:00:43,220
and running but if it wouldn't be,

17
00:00:43,220 --> 00:00:46,860
these commands I just showed you would have failed anyways.

18
00:00:46,860 --> 00:00:49,850
And with that, let's now create a config file

19
00:00:49,850 --> 00:00:51,220
for the deployment,

20
00:00:51,220 --> 00:00:53,980
which we created in the command line before.

21
00:00:53,980 --> 00:00:57,010
For this, I'll add a new file in this project

22
00:00:57,010 --> 00:00:59,600
and I'll name it deployment.yaml.

23
00:00:59,600 --> 00:01:02,310
The file name is totally up to you though.

24
00:01:02,310 --> 00:01:03,780
The only thing that matters

25
00:01:03,780 --> 00:01:05,459
is that it's a YAML file

26
00:01:05,459 --> 00:01:07,750
but the file name is up to you.

27
00:01:07,750 --> 00:01:10,140
Now, in this deployment.yaml file,

28
00:01:10,140 --> 00:01:15,010
we now specify how our deployment should look like,

29
00:01:15,010 --> 00:01:16,410
how it should work,

30
00:01:16,410 --> 00:01:17,910
how it should be configured.

31
00:01:17,910 --> 00:01:20,660
And there is a certain syntax you have to use

32
00:01:20,660 --> 00:01:23,163
in these Kubernetes config files.

33
00:01:23,163 --> 00:01:26,390
First of all, no matter which kind

34
00:01:26,390 --> 00:01:28,840
of resource you are configuring,

35
00:01:28,840 --> 00:01:30,550
if it's a deployment or a service,

36
00:01:30,550 --> 00:01:34,250
whatever it is, you need to specify an apiVersion

37
00:01:34,250 --> 00:01:37,873
by adding such an apiVersion key written like this.

38
00:01:38,930 --> 00:01:41,630
Now, there are different apiVersions available

39
00:01:41,630 --> 00:01:43,800
and like everything in the world,

40
00:01:43,800 --> 00:01:44,810
Kubernetes, of course,

41
00:01:44,810 --> 00:01:47,470
also is under active development.

42
00:01:47,470 --> 00:01:50,550
To find out which apiVersion to use here,

43
00:01:50,550 --> 00:01:54,150
my personal approach is that I dive into the docs

44
00:01:54,150 --> 00:01:59,150
or that I simply google for Kubernetes deployment YAML

45
00:01:59,540 --> 00:02:00,920
or something like this.

46
00:02:00,920 --> 00:02:03,010
You could also search for service.yaml

47
00:02:03,010 --> 00:02:05,030
if you would want to define a service

48
00:02:05,030 --> 00:02:06,780
and then somewhere in the docs,

49
00:02:06,780 --> 00:02:09,440
you will find an example snippet like this one

50
00:02:09,440 --> 00:02:11,873
and you'll see the apiVersion here.

51
00:02:13,380 --> 00:02:15,130
This is a quick way of finding out

52
00:02:15,130 --> 00:02:17,750
what the currently latest apiVersion is.

53
00:02:17,750 --> 00:02:19,580
Though, of course, you should keep in mind

54
00:02:19,580 --> 00:02:21,622
that if you always use the latest version,

55
00:02:21,622 --> 00:02:25,420
of course, some features might change over time.

56
00:02:25,420 --> 00:02:27,790
Here, I can use the latest version though

57
00:02:27,790 --> 00:02:30,060
and therefore, I set the apiVersion here

58
00:02:30,060 --> 00:02:34,410
to apps/v1 for this deployment resource,

59
00:02:34,410 --> 00:02:35,560
which I'm gonna create.

60
00:02:36,430 --> 00:02:37,990
And that's the next important piece

61
00:02:37,990 --> 00:02:39,790
of information we need here.

62
00:02:39,790 --> 00:02:42,610
Just because we named the file deployment

63
00:02:42,610 --> 00:02:45,610
does not mean that Kubernetes will treat it

64
00:02:45,610 --> 00:02:48,170
as a file that creates a deployment

65
00:02:48,170 --> 00:02:50,940
because we could have chosen any file name.

66
00:02:50,940 --> 00:02:53,410
Instead, you have to let Kubernetes know

67
00:02:53,410 --> 00:02:54,942
what you want to create

68
00:02:54,942 --> 00:02:58,390
by adding a kind key here.

69
00:02:58,390 --> 00:02:59,900
And that's super important.

70
00:02:59,900 --> 00:03:01,730
Here you define the kind

71
00:03:01,730 --> 00:03:04,330
of Kubernetes object you wanna create.

72
00:03:04,330 --> 00:03:06,500
And here, we wanna create a Deployment

73
00:03:06,500 --> 00:03:09,280
and of course, this value is not up to you.

74
00:03:09,280 --> 00:03:13,910
There's only a certain set of possible values here,

75
00:03:13,910 --> 00:03:18,400
like Service or Job, which we haven't used thus far.

76
00:03:18,400 --> 00:03:21,310
But in this case, we need a Deployment.

77
00:03:21,310 --> 00:03:23,700
And again, the official docs are a place

78
00:03:23,700 --> 00:03:26,790
where you can learn about all possible resource types

79
00:03:26,790 --> 00:03:28,486
and also very useful,

80
00:03:28,486 --> 00:03:30,310
in the official docs,

81
00:03:30,310 --> 00:03:33,750
at the very bottom here on the left, the reference.

82
00:03:33,750 --> 00:03:37,090
If you dive into the latest API reference here,

83
00:03:37,090 --> 00:03:39,430
you also find a full reference

84
00:03:39,430 --> 00:03:42,760
of all supported objects and configurations

85
00:03:42,760 --> 00:03:45,160
and for example, here, we can also dive

86
00:03:45,160 --> 00:03:46,880
into the Deployment object.

87
00:03:46,880 --> 00:03:51,320
Here we also see that it's apps v1 as a version.

88
00:03:51,320 --> 00:03:54,550
And then here, you see what you can configure

89
00:03:54,550 --> 00:03:56,100
in this YAML file.

90
00:03:56,100 --> 00:03:59,650
For example, here you also see the kind configuration,

91
00:03:59,650 --> 00:04:02,143
which here, of course, should be Deployment.

92
00:04:03,240 --> 00:04:06,310
So that's the next thing we set.

93
00:04:06,310 --> 00:04:08,180
Now, with that, we're telling Kubernetes

94
00:04:08,180 --> 00:04:11,570
that we wanna create a new deployment object.

95
00:04:11,570 --> 00:04:13,640
As a next step, you typically need

96
00:04:13,640 --> 00:04:15,360
to add some metadata.

97
00:04:15,360 --> 00:04:18,065
Now, this is not some random data you come up with

98
00:04:18,065 --> 00:04:22,270
but instead, this includes crucial things like the name

99
00:04:22,270 --> 00:04:23,903
of the object you're creating.

100
00:04:24,740 --> 00:04:27,050
And keep in mind, we chose a name

101
00:04:27,050 --> 00:04:29,821
in the imperative approach as well.

102
00:04:29,821 --> 00:04:32,590
There we created a deployment like this

103
00:04:32,590 --> 00:04:34,923
and we gave it a name like this.

104
00:04:35,810 --> 00:04:38,410
And here, we're basically doing the same.

105
00:04:38,410 --> 00:04:41,270
This deployment here is basically replaced

106
00:04:41,270 --> 00:04:42,970
by setting a kind here.

107
00:04:42,970 --> 00:04:45,220
And now we also need to give it a name

108
00:04:45,220 --> 00:04:47,610
so that we can identify it later.

109
00:04:47,610 --> 00:04:50,074
And we do this by adding the metadata key

110
00:04:50,074 --> 00:04:52,650
and then nest it in there

111
00:04:52,650 --> 00:04:55,410
and therefore, since it's YAML, indent it

112
00:04:55,410 --> 00:04:57,550
because that is how you nest things

113
00:04:57,550 --> 00:04:59,150
in a YAML document.

114
00:04:59,150 --> 00:05:00,660
We set a name.

115
00:05:00,660 --> 00:05:03,510
And now this name is totally up to you.

116
00:05:03,510 --> 00:05:07,510
I will name is second-app-deployment

117
00:05:07,510 --> 00:05:10,820
but this name again is up to you.

118
00:05:10,820 --> 00:05:13,370
Now, there is more metadata, which you can add.

119
00:05:13,370 --> 00:05:16,240
As you can see in the reference docs here

120
00:05:16,240 --> 00:05:19,404
on metadata, if you click on this type definition.

121
00:05:19,404 --> 00:05:21,700
It's not possible for all types

122
00:05:21,700 --> 00:05:23,040
but for many it is.

123
00:05:23,040 --> 00:05:26,470
And here you then see, if you scroll down below that list

124
00:05:26,470 --> 00:05:28,900
of objects which support this type,

125
00:05:28,900 --> 00:05:31,740
her you see what you can add.

126
00:05:31,740 --> 00:05:33,720
There you see you can add a lot,

127
00:05:33,720 --> 00:05:35,950
for example, the name, which we just added

128
00:05:35,950 --> 00:05:37,520
but also, other things,

129
00:05:37,520 --> 00:05:40,270
though I will say, many of these things don't need

130
00:05:40,270 --> 00:05:43,940
to be added for the vast majority of objects.

131
00:05:43,940 --> 00:05:45,810
And I will highlight some other things,

132
00:05:45,810 --> 00:05:48,410
which you can add whenever we have an object

133
00:05:48,410 --> 00:05:50,320
where it makes sense.

134
00:05:50,320 --> 00:05:53,540
So with that, I'll go back to my deployment definition here

135
00:05:53,540 --> 00:05:55,533
and just add the name here.

136
00:05:56,400 --> 00:05:58,270
Okay, so now we tell Kubernetes

137
00:05:58,270 --> 00:06:00,040
that we wanna create a deployment

138
00:06:00,040 --> 00:06:04,570
and that it will have a name of second-app-deployment.

139
00:06:04,570 --> 00:06:07,370
Now we need to add the so-called spec,

140
00:06:07,370 --> 00:06:10,870
the specification of this deployment.

141
00:06:10,870 --> 00:06:12,930
And that's the meat of this object

142
00:06:12,930 --> 00:06:16,410
because here, we will define how this deployment

143
00:06:16,410 --> 00:06:17,560
should be configured.

144
00:06:17,560 --> 00:06:20,320
So here, all the interesting things are being added

145
00:06:20,320 --> 00:06:22,543
and therefore, let's now dive into this.

