1
00:00:02,070 --> 00:00:04,470
For the spec, the specification

2
00:00:04,470 --> 00:00:08,060
of this object, we again have a nested key.

3
00:00:08,060 --> 00:00:09,690
So we indent

4
00:00:09,690 --> 00:00:11,400
below spec here,

5
00:00:11,400 --> 00:00:14,560
and we then add a couple of pieces of information

6
00:00:14,560 --> 00:00:17,010
about this deployment.

7
00:00:17,010 --> 00:00:19,920
For example, the number of pod instances

8
00:00:19,920 --> 00:00:21,930
we wanna have as a default.

9
00:00:21,930 --> 00:00:24,170
Now, if you don't add any information

10
00:00:24,170 --> 00:00:25,770
the default is one,

11
00:00:25,770 --> 00:00:27,820
but you can also manually set it

12
00:00:27,820 --> 00:00:30,170
by adding the replicas key here,

13
00:00:30,170 --> 00:00:34,980
and give that a value of one, or two, or three, or even zero

14
00:00:34,980 --> 00:00:38,513
if you initially don't want any pods to be launched.

15
00:00:39,450 --> 00:00:42,820
I'll set it to one, but you could also set it to three

16
00:00:42,820 --> 00:00:46,180
to start with three running pods,

17
00:00:46,180 --> 00:00:49,380
three equal pods containing the same container,

18
00:00:49,380 --> 00:00:50,960
right from the start.

19
00:00:50,960 --> 00:00:54,400
Which of course could make sense for certain applications.

20
00:00:54,400 --> 00:00:57,330
If you know that for the traffic which you expect

21
00:00:57,330 --> 00:01:00,560
to arrive you will need three pods anyways,

22
00:01:00,560 --> 00:01:03,980
you of course don't have to scale them after you created

23
00:01:03,980 --> 00:01:07,170
the deployment, you can simply start with three.

24
00:01:07,170 --> 00:01:09,690
But here we'll start with one, because of course,

25
00:01:09,690 --> 00:01:12,693
for our local development, this will suffice.

26
00:01:13,600 --> 00:01:17,270
Now as our next step, you need to add a template.

27
00:01:17,270 --> 00:01:21,890
Here You will define the pods that should be created

28
00:01:21,890 --> 00:01:24,060
as part of this deployment.

29
00:01:24,060 --> 00:01:26,600
And that's of course, super important.

30
00:01:26,600 --> 00:01:30,970
With the imperative approach, create deployment first app,

31
00:01:30,970 --> 00:01:34,010
we added "dash dash image" to define

32
00:01:34,010 --> 00:01:37,330
which image should be used for the container used

33
00:01:37,330 --> 00:01:40,940
in the pod attached to this deployment.

34
00:01:40,940 --> 00:01:43,400
Now we'll do kind of the same here.

35
00:01:43,400 --> 00:01:45,580
Now with the template we define the pod

36
00:01:45,580 --> 00:01:49,540
which should be created and therefor nested below template,

37
00:01:49,540 --> 00:01:52,950
we now also, again, add "metadata"

38
00:01:52,950 --> 00:01:57,570
because a pod is a new object in the Kubernetes World.

39
00:01:57,570 --> 00:02:00,840
Deployment is an object, a pod is another object,

40
00:02:00,840 --> 00:02:03,350
and therefore, we need new metadata here

41
00:02:03,350 --> 00:02:04,870
for this new object.

42
00:02:04,870 --> 00:02:08,320
To, for example, give it a name if you want to,

43
00:02:08,320 --> 00:02:11,670
but in this case, we want to add a label

44
00:02:11,670 --> 00:02:14,170
and we do this with the labels key.

45
00:02:14,170 --> 00:02:17,500
I'll come back to why we need a label in a second.

46
00:02:17,500 --> 00:02:20,660
For the moment, let's add it and nested below that,

47
00:02:20,660 --> 00:02:23,570
you can give it any label you want.

48
00:02:23,570 --> 00:02:27,503
And here both the key as well as the "value" value,

49
00:02:27,503 --> 00:02:28,933
are up to you.

50
00:02:29,910 --> 00:02:33,610
So here I'll name this app, "second dash app",

51
00:02:33,610 --> 00:02:38,300
but you could have also named this here, "deployment"

52
00:02:38,300 --> 00:02:39,620
or "depl"

53
00:02:39,620 --> 00:02:41,500
or... "tier"

54
00:02:41,500 --> 00:02:42,600
whatever you want.

55
00:02:42,600 --> 00:02:46,570
I'll add a label named "app" and give it a value

56
00:02:46,570 --> 00:02:48,310
of second app.

57
00:02:48,310 --> 00:02:49,650
And again I will come back to

58
00:02:49,650 --> 00:02:53,416
why labels are important metadata for some objects,

59
00:02:53,416 --> 00:02:54,653
in a second.

60
00:02:55,490 --> 00:02:59,410
Now, as a side note, you don't need to add the kind here

61
00:02:59,410 --> 00:03:03,960
because the template of a deployment always describes a pod.

62
00:03:03,960 --> 00:03:06,260
So this always is a pod object,

63
00:03:06,260 --> 00:03:10,133
and that's why we don't need to add this pod kind here.

64
00:03:11,080 --> 00:03:14,090
Indeed, if you have a look at the reference documentation,

65
00:03:14,090 --> 00:03:18,720
here in the deployment spec, and then there

66
00:03:18,720 --> 00:03:19,770
on the template,

67
00:03:19,770 --> 00:03:23,230
you see, this is always a pod template spec

68
00:03:23,230 --> 00:03:26,930
and therefor here, you see, you only can add two pieces

69
00:03:26,930 --> 00:03:29,450
of data, and that's the metadata and

70
00:03:29,450 --> 00:03:31,960
then the specification of the pod.

71
00:03:31,960 --> 00:03:36,010
And you can't even add a kind here because it's not expected

72
00:03:36,010 --> 00:03:39,203
by Kubernetes because this always has to be a pod.

73
00:03:40,190 --> 00:03:44,070
So we added the metadata, but as we just saw the other thing

74
00:03:44,070 --> 00:03:46,890
which we have to add for this pod template is

75
00:03:46,890 --> 00:03:51,070
the specification for how this pod should look like.

76
00:03:51,070 --> 00:03:54,500
We did add a specification before, this one,

77
00:03:54,500 --> 00:03:58,210
but that was the specification for the overall deployment.

78
00:03:58,210 --> 00:04:01,080
Now we add another spec on the same level

79
00:04:01,080 --> 00:04:03,750
as metadata inside of the template,

80
00:04:03,750 --> 00:04:07,620
so indented below template and here we now define

81
00:04:07,620 --> 00:04:10,720
how this pod should be configured.

82
00:04:10,720 --> 00:04:14,010
So this spec is the configuration of the deployment,

83
00:04:14,010 --> 00:04:17,880
which basically sets up which pod we want and how many pods.

84
00:04:17,880 --> 00:04:21,339
Now we have to specification of the individual pods

85
00:04:21,339 --> 00:04:24,300
which are created for this deployment.

86
00:04:24,300 --> 00:04:28,100
And here it's one type of pod per deployment.

87
00:04:28,100 --> 00:04:31,600
So you can have multiple pods if you increase the replicas

88
00:04:31,600 --> 00:04:33,350
but it's always the same pods then

89
00:04:33,350 --> 00:04:36,030
with the same containers inside of it.

90
00:04:36,030 --> 00:04:39,090
If you want different pods with different containers,

91
00:04:39,090 --> 00:04:40,860
you need different deployments.

92
00:04:40,860 --> 00:04:43,483
And we'll see that in action later as well.

93
00:04:44,430 --> 00:04:47,410
So here in this specification for the pod,

94
00:04:47,410 --> 00:04:49,990
we now basically need one important key

95
00:04:49,990 --> 00:04:52,620
and that's the containers key.

96
00:04:52,620 --> 00:04:54,300
And again, you can always look this up

97
00:04:54,300 --> 00:04:56,150
in the official documentation.

98
00:04:56,150 --> 00:04:58,230
If we have a look at the pod spec,

99
00:04:58,230 --> 00:05:00,770
we see that there's a lot we can configure,

100
00:05:00,770 --> 00:05:03,430
many things which you will rarely need,

101
00:05:03,430 --> 00:05:06,370
and basically nothing we need right now.

102
00:05:06,370 --> 00:05:09,690
But we do need this containers key here

103
00:05:09,690 --> 00:05:12,020
which allows us to define the containers

104
00:05:12,020 --> 00:05:15,913
or the single container, which should be part of this pod.

105
00:05:17,240 --> 00:05:20,530
Now we'll have a look at some of the other options later.

106
00:05:20,530 --> 00:05:23,030
For the moment, let's just add containers

107
00:05:23,030 --> 00:05:26,060
and there, we now have a list of containers,

108
00:05:26,060 --> 00:05:27,770
which means we need dashes.

109
00:05:27,770 --> 00:05:31,400
Without a dash it's just a nested key below another key.

110
00:05:31,400 --> 00:05:35,510
Now here, we can have multiple containers in the same pod,

111
00:05:35,510 --> 00:05:37,880
so you can have multiple containers to find

112
00:05:37,880 --> 00:05:41,563
with multiple dashes here, with multiple list items.

113
00:05:42,420 --> 00:05:45,430
And every container then can have a name,

114
00:05:45,430 --> 00:05:46,970
which is up to you.

115
00:05:46,970 --> 00:05:48,787
I will name it,

116
00:05:48,787 --> 00:05:51,410
"second node".

117
00:05:51,410 --> 00:05:54,410
Not because it's on the second worker node

118
00:05:54,410 --> 00:05:57,450
or anything like that, but because it's a Node.js app

119
00:05:57,450 --> 00:05:59,320
and it's our second app and the container

120
00:05:59,320 --> 00:06:00,720
for this second app.

121
00:06:00,720 --> 00:06:02,463
The name is up to you, of course.

122
00:06:03,720 --> 00:06:07,210
Very important is another key which you now don't add

123
00:06:07,210 --> 00:06:10,160
with a dash because it's still for the same container,

124
00:06:10,160 --> 00:06:11,510
just in a new line.

125
00:06:11,510 --> 00:06:14,130
And that's the image which you want to use here.

126
00:06:14,130 --> 00:06:17,300
And of course, that's the image you would have specified

127
00:06:17,300 --> 00:06:19,210
with "dash dash image" here

128
00:06:19,210 --> 00:06:21,583
when creating a deployment imperatively.

129
00:06:22,570 --> 00:06:25,570
There, as a side note, you could have also

130
00:06:25,570 --> 00:06:28,080
added multiple images by separating them

131
00:06:28,080 --> 00:06:31,480
with commas to create multiple containers.

132
00:06:31,480 --> 00:06:35,580
Here in the declarative approach, as mentioned before,

133
00:06:35,580 --> 00:06:38,620
you could add multiple containers like this

134
00:06:38,620 --> 00:06:40,870
by adding multiple dashes.

135
00:06:40,870 --> 00:06:42,610
Not something we need to do here though,

136
00:06:42,610 --> 00:06:44,930
so I'll comment this out.

137
00:06:44,930 --> 00:06:47,320
Here the image I want to use, of course,

138
00:06:47,320 --> 00:06:48,580
is the first...

139
00:06:49,550 --> 00:06:52,000
app image I deployed before.

140
00:06:52,000 --> 00:06:54,540
So the "kub dash first app" image.

141
00:06:54,540 --> 00:06:57,150
And it needs to be an image on a registry,

142
00:06:57,150 --> 00:07:00,960
so that's why I'm using my registry account name here

143
00:07:00,960 --> 00:07:02,740
slash and then the image name.

144
00:07:02,740 --> 00:07:05,770
So overall the repository name on that image.

145
00:07:05,770 --> 00:07:08,540
And you can, of course, also specify a tag here

146
00:07:08,540 --> 00:07:10,620
like that latest version we deployed

147
00:07:10,620 --> 00:07:12,620
in one of the last lectures.

148
00:07:12,620 --> 00:07:15,840
And that's it, that's the bare minimum configuration

149
00:07:15,840 --> 00:07:18,660
we need here to create a deployment,

150
00:07:18,660 --> 00:07:21,094
which will create one pod with that one container

151
00:07:21,094 --> 00:07:23,010
inside of it.

152
00:07:23,010 --> 00:07:25,330
That of course leaves only one question.

153
00:07:25,330 --> 00:07:28,730
How can we now apply that deployment?

154
00:07:28,730 --> 00:07:31,530
How can we now make the cluster aware of it

155
00:07:31,530 --> 00:07:34,490
and have it create that deployment and pod

156
00:07:34,490 --> 00:07:36,290
and launch that container?

157
00:07:36,290 --> 00:07:38,670
Well for that, we use the command line

158
00:07:38,670 --> 00:07:41,870
and we still use the kube control command here

159
00:07:41,870 --> 00:07:44,063
because that is our communication device

160
00:07:44,063 --> 00:07:46,220
with the master node.

161
00:07:46,220 --> 00:07:51,220
But now we don't call, create something, but instead, apply.

162
00:07:51,310 --> 00:07:52,920
That's another command built

163
00:07:52,920 --> 00:07:56,200
into this kube control command tool here,

164
00:07:56,200 --> 00:07:59,590
and it's simply applies a configuration file

165
00:07:59,590 --> 00:08:02,090
to the connected cluster.

166
00:08:02,090 --> 00:08:05,840
You identify the file with the dash F...

167
00:08:05,840 --> 00:08:06,890
option here

168
00:08:06,890 --> 00:08:09,490
and you can have multiple dash F options,

169
00:08:09,490 --> 00:08:12,190
if you wanna apply multiple files at once.

170
00:08:12,190 --> 00:08:14,270
Here, it's only one file though.

171
00:08:14,270 --> 00:08:17,970
And then you simply add an equal sign and then the file name

172
00:08:17,970 --> 00:08:21,410
or the path to the file, which should be applied.

173
00:08:21,410 --> 00:08:23,740
So in this case kube control applied

174
00:08:23,740 --> 00:08:27,250
dash F equals deployment dot yaml.

175
00:08:27,250 --> 00:08:30,723
And if we now hit enter, it tries to apply this.

176
00:08:31,660 --> 00:08:33,820
But you see, I get an error.

177
00:08:33,820 --> 00:08:37,130
I'm getting a missing required field "selector" here.

178
00:08:37,130 --> 00:08:40,230
And I did this on purpose because selectors are

179
00:08:40,230 --> 00:08:43,120
a key concept in the Kubernetes world,

180
00:08:43,120 --> 00:08:46,083
especially when using the declarative approach.

