1
00:00:02,260 --> 00:00:04,590
Now, let's get started step by step.

2
00:00:04,590 --> 00:00:07,360
And let's first of all, create a deployment

3
00:00:07,360 --> 00:00:10,380
and a service for this demo application

4
00:00:10,380 --> 00:00:13,310
so that we can at least reach it.

5
00:00:13,310 --> 00:00:16,360
For that I'll run kubectrl get deployments first

6
00:00:16,360 --> 00:00:19,870
to verify that I have no ongoing deployments.

7
00:00:19,870 --> 00:00:23,360
And then I wanna use the declarative approach

8
00:00:23,360 --> 00:00:26,180
of creating a new deployment and service.

9
00:00:26,180 --> 00:00:30,190
So for that, I'll add a deployment.yaml file

10
00:00:30,190 --> 00:00:32,759
and a service.yaml file.

11
00:00:32,759 --> 00:00:35,620
And we could merge both into one file

12
00:00:35,620 --> 00:00:37,780
if we wanted to of course, as you saw,

13
00:00:37,780 --> 00:00:39,120
but I will split it up

14
00:00:39,120 --> 00:00:42,523
so that it is easier to find the different configurations.

15
00:00:43,580 --> 00:00:45,430
Now you'll learn to syntax,

16
00:00:45,430 --> 00:00:47,290
in the deployment .yeml file.

17
00:00:47,290 --> 00:00:49,920
We first of all, add the apiVersion

18
00:00:49,920 --> 00:00:53,533
and for the deployment, this should be apps/v1.

19
00:00:55,731 --> 00:00:58,170
Now we need to let Kubernetes know which kind

20
00:00:58,170 --> 00:01:00,110
of resource we wanna create.

21
00:01:00,110 --> 00:01:02,020
And we do this with the kind key

22
00:01:02,020 --> 00:01:04,462
and set this to deployment here.

23
00:01:06,090 --> 00:01:08,320
And then we add some metadata

24
00:01:08,320 --> 00:01:11,020
where we give this deployment a name.

25
00:01:11,020 --> 00:01:16,020
This name is up to you and I'll name it, "story-deployment."

26
00:01:16,390 --> 00:01:18,490
But again, this name is totally up to you.

27
00:01:19,640 --> 00:01:21,860
Next we need to add the spec key

28
00:01:21,860 --> 00:01:25,470
to provide the specification of this deployment.

29
00:01:25,470 --> 00:01:27,550
So the configuration of it.

30
00:01:27,550 --> 00:01:28,910
Here we can then for example

31
00:01:28,910 --> 00:01:31,520
specify the number of replicas we want

32
00:01:31,520 --> 00:01:33,460
and I'll start with one.

33
00:01:33,460 --> 00:01:35,690
And then we need to specify the template,

34
00:01:35,690 --> 00:01:38,280
the port template for the ports

35
00:01:38,280 --> 00:01:40,543
that are created by this deployment.

36
00:01:41,580 --> 00:01:44,640
So for the one kind of port that is attached

37
00:01:44,640 --> 00:01:47,470
to the supplement and which can then be replicated

38
00:01:47,470 --> 00:01:49,770
by changing the replica's number.

39
00:01:49,770 --> 00:01:52,630
Now in this template here, we also need a spec.

40
00:01:52,630 --> 00:01:54,730
Now this will set up the specification

41
00:01:54,730 --> 00:01:56,950
40 individual ports, as you learn.

42
00:01:56,950 --> 00:01:59,830
And there, I wanna make it clear which containers

43
00:01:59,830 --> 00:02:02,670
will be part of this port.

44
00:02:02,670 --> 00:02:04,950
And here we have just one container.

45
00:02:04,950 --> 00:02:07,110
So we need one bullet point,

46
00:02:07,110 --> 00:02:09,090
so to say one dash here,

47
00:02:09,090 --> 00:02:13,040
and the name of this container could be, "story"

48
00:02:13,040 --> 00:02:14,800
it's up to you of course,

49
00:02:14,800 --> 00:02:18,090
the image which I wanna use here of course

50
00:02:18,090 --> 00:02:22,500
is the image we'll create with help of that docker file.

51
00:02:22,500 --> 00:02:25,840
And you know that we need to push this to docker hub

52
00:02:25,840 --> 00:02:30,070
in order for it, for it to be available in here

53
00:02:30,070 --> 00:02:33,690
so I will already use my to be created

54
00:02:33,690 --> 00:02:35,830
docker hop repository name

55
00:02:35,830 --> 00:02:40,830
and I will name it 'kub-data-demo."

56
00:02:41,630 --> 00:02:43,850
But of course, this is up to you

57
00:02:43,850 --> 00:02:46,420
and it's depends on how you are going to name

58
00:02:46,420 --> 00:02:49,400
your docker hub repository later.

59
00:02:49,400 --> 00:02:53,520
And with that, we configured this container already.

60
00:02:53,520 --> 00:02:55,240
Now, we're not entirely done

61
00:02:55,240 --> 00:02:59,950
for our port template here, besides the specification.

62
00:02:59,950 --> 00:03:03,870
We also need metadata where we add labels

63
00:03:03,870 --> 00:03:07,150
by which the port can then be selected.

64
00:03:07,150 --> 00:03:08,220
And here you learn,

65
00:03:08,220 --> 00:03:11,520
you can have any key value pairs of your choice.

66
00:03:11,520 --> 00:03:16,520
I will add an app key here and give it a value of "story".

67
00:03:17,750 --> 00:03:19,150
So to same as I used here

68
00:03:19,150 --> 00:03:21,850
as a container name, but you can use a different name.

69
00:03:23,130 --> 00:03:28,130
Now, this matters because on the spec of our deployment

70
00:03:28,630 --> 00:03:33,000
here we also need to add a selector as you learn

71
00:03:33,000 --> 00:03:35,990
and here we can add match labels

72
00:03:35,990 --> 00:03:37,930
and then select by the app key

73
00:03:37,930 --> 00:03:41,910
and look for pods with the value of story for the app label.

74
00:03:41,910 --> 00:03:44,530
And their for of course, the pod from this template

75
00:03:44,530 --> 00:03:45,533
will be selected.

76
00:03:46,450 --> 00:03:48,760
And that's all just something you learned about

77
00:03:48,760 --> 00:03:50,610
in the last course section.

78
00:03:50,610 --> 00:03:52,630
So this shouldn't be anything new.

79
00:03:52,630 --> 00:03:55,540
And if it is definitely make sure you go through

80
00:03:55,540 --> 00:03:57,763
this last course section first.

81
00:03:59,590 --> 00:04:03,270
Now that's the deployment, let's now add a service.

82
00:04:03,270 --> 00:04:05,500
For this here in the serviceyaml file,

83
00:04:05,500 --> 00:04:07,760
we also set up an apiVersion.

84
00:04:07,760 --> 00:04:09,210
However, here it's just v1

85
00:04:10,200 --> 00:04:13,383
And of course we add a kind which should be service.

86
00:04:14,830 --> 00:04:16,930
We should give this service a name

87
00:04:16,930 --> 00:04:20,916
by adding metadata and I'll name it "story-service."

88
00:04:22,240 --> 00:04:24,720
And then we add specification.

89
00:04:24,720 --> 00:04:27,870
So the options for this service

90
00:04:27,870 --> 00:04:31,700
and here, we now define which ports we want to select.

91
00:04:31,700 --> 00:04:33,820
And of course I want to select the ports

92
00:04:33,820 --> 00:04:35,773
created by this deployment.

93
00:04:36,700 --> 00:04:40,850
These ports have an app label with the value of story.

94
00:04:40,850 --> 00:04:42,470
So for a serviceyaml

95
00:04:42,470 --> 00:04:47,400
under a selector we can add this app key here

96
00:04:47,400 --> 00:04:50,250
and then look for a story as a value.

97
00:04:50,250 --> 00:04:53,130
And again, that is something we already covered

98
00:04:53,130 --> 00:04:55,113
in the previous course section.

99
00:04:56,960 --> 00:05:00,250
Now, once that is done, we can define the ports

100
00:05:00,250 --> 00:05:02,670
which should be mapped and exposed.

101
00:05:02,670 --> 00:05:07,280
And here I'll set the protocol to "TCP."

102
00:05:07,280 --> 00:05:09,030
You can also wrap this between quotes

103
00:05:09,030 --> 00:05:11,240
if you want to both works

104
00:05:11,240 --> 00:05:15,520
and then set the port on what you wanna expose it

105
00:05:15,520 --> 00:05:19,130
to, for example, 80 and the targetport

106
00:05:19,130 --> 00:05:22,370
ends up the container to three thousand

107
00:05:22,370 --> 00:05:26,310
because that is the port my container exposes.

108
00:05:26,310 --> 00:05:31,280
So now we've got the service and deployment configurations

109
00:05:31,280 --> 00:05:33,820
created before we apply them,

110
00:05:33,820 --> 00:05:36,400
We need to make sure that this image exists

111
00:05:36,400 --> 00:05:37,713
on Docker hub though.

112
00:05:38,560 --> 00:05:40,760
So, for that on Docker hub,

113
00:05:40,760 --> 00:05:43,780
make sure you create a new repository

114
00:05:43,780 --> 00:05:46,210
and then give it the name you chose here.

115
00:05:46,210 --> 00:05:48,510
So in my case kup-data-demo

116
00:05:50,200 --> 00:05:52,810
and then of course create this repository

117
00:05:54,630 --> 00:05:58,320
with it created, we now need to build and our image.

118
00:05:58,320 --> 00:06:01,730
So for that, we can use a docker build

119
00:06:01,730 --> 00:06:04,560
and use the current folder as a context

120
00:06:04,560 --> 00:06:07,240
because that is where my docker file

121
00:06:07,240 --> 00:06:09,793
and the application source code sits.

122
00:06:10,990 --> 00:06:15,969
And then simply give it a tag of academind/

123
00:06:15,969 --> 00:06:19,010
and then kup-data-demo.

124
00:06:19,010 --> 00:06:22,570
So that name you chose built this image

125
00:06:26,040 --> 00:06:28,160
and there after push it.

126
00:06:28,160 --> 00:06:32,233
So push academind/kub-data-demo.

127
00:06:33,751 --> 00:06:36,020
So now this is pushed to Docker hub

128
00:06:36,020 --> 00:06:38,153
and they for should be found here.

129
00:06:38,990 --> 00:06:42,260
You could of course also give it a tag, a version number

130
00:06:42,260 --> 00:06:45,990
to ensure that always this specific version is fetched

131
00:06:45,990 --> 00:06:48,270
but these are all things I already talked about

132
00:06:48,270 --> 00:06:50,020
in the last course section.

133
00:06:50,020 --> 00:06:52,263
So I won't dive into that again here.

134
00:06:53,340 --> 00:06:56,980
Instead now this was pushed and therefore of course

135
00:06:56,980 --> 00:07:00,760
we can apply our service and our deployment.

136
00:07:00,760 --> 00:07:04,360
So for that of course your Minikube virtual machine

137
00:07:04,360 --> 00:07:06,530
needs to be up and running.

138
00:07:06,530 --> 00:07:10,010
You can check this with minikube status,

139
00:07:10,010 --> 00:07:12,430
and if you don't have the bunch of running there,

140
00:07:12,430 --> 00:07:15,460
you can restart it with minikube start.

141
00:07:15,460 --> 00:07:17,870
And then by adding a driver as explained

142
00:07:17,870 --> 00:07:20,030
in the last course section

143
00:07:20,030 --> 00:07:21,860
and once it is up and running,

144
00:07:21,860 --> 00:07:23,980
we can run cubectrl apply-f

145
00:07:25,178 --> 00:07:28,220
and apply to service.yaml file.

146
00:07:28,220 --> 00:07:31,613
And also the deployment.yaml file.

147
00:07:32,600 --> 00:07:36,350
And this will create a service and the deployment.

148
00:07:36,350 --> 00:07:40,190
And by doing that, if we then run, get deployments

149
00:07:40,190 --> 00:07:42,210
we should see that we have one deployment up

150
00:07:42,210 --> 00:07:44,363
and running and it should be ready.

151
00:07:45,260 --> 00:07:48,330
Now we can try reaching that deployment

152
00:07:48,330 --> 00:07:52,890
by running minikube service.

153
00:07:52,890 --> 00:07:56,050
And then the name of the service we chose here

154
00:07:56,050 --> 00:08:00,460
story-service, and this will expose that service.

155
00:08:00,460 --> 00:08:02,830
However, of course it fails

156
00:08:02,830 --> 00:08:05,070
because I forgot one important thing.

157
00:08:05,070 --> 00:08:08,010
We need to use a type here.

158
00:08:08,010 --> 00:08:11,040
Of course besides specifying the ports,

159
00:08:11,040 --> 00:08:13,750
we should add a type to the service.yaml file

160
00:08:13,750 --> 00:08:16,343
and set this to LoadBalancer.

161
00:08:17,670 --> 00:08:20,170
My mistake of course, this needs to be added

162
00:08:20,170 --> 00:08:23,760
otherwise it's by default just exposed internally

163
00:08:24,623 --> 00:08:26,700
in the cluster and not reachable from outside,

164
00:08:26,700 --> 00:08:28,410
which is what we need here though.

165
00:08:28,410 --> 00:08:29,990
So make sure you add this type

166
00:08:31,440 --> 00:08:33,480
then simply reapply it by running

167
00:08:33,480 --> 00:08:38,470
kubectrl apply-F=serviceyaml we don't need

168
00:08:38,470 --> 00:08:40,950
to reapply the deployment.

169
00:08:40,950 --> 00:08:43,370
We just need to update the service.

170
00:08:43,370 --> 00:08:48,030
And with that done run minikube service story-service again

171
00:08:48,030 --> 00:08:49,920
and now this gives you a URL

172
00:08:49,920 --> 00:08:52,203
which you can use to reach your application.

173
00:08:53,420 --> 00:08:57,610
And now we can use that here in Postman,

174
00:08:57,610 --> 00:09:02,610
use this URL/story and send a get request

175
00:09:02,910 --> 00:09:06,250
and you should get back a valid response.

176
00:09:06,250 --> 00:09:09,140
Of course, without any data initially,

177
00:09:09,140 --> 00:09:13,090
we can also use it to send a post request like this

178
00:09:13,090 --> 00:09:17,500
with some dummy data added and that should work.

179
00:09:17,500 --> 00:09:19,940
And if we then get this again,

180
00:09:19,940 --> 00:09:22,053
we of course see our data here.

181
00:09:22,980 --> 00:09:25,440
And that means that of course, it's working

182
00:09:25,440 --> 00:09:27,620
now, let's dig into the problems

183
00:09:27,620 --> 00:09:30,763
and then the solution, which of course are volumes.

