1
00:00:02,070 --> 00:00:04,730
Let's have a look at the tasks-API,

2
00:00:04,730 --> 00:00:07,910
there we got one JavaScript file.

3
00:00:07,910 --> 00:00:09,000
and in the end here,

4
00:00:09,000 --> 00:00:12,720
we're also sending a request to the auth-service.

5
00:00:12,720 --> 00:00:16,059
At the moment, I still got auth hard-coded in the code

6
00:00:16,059 --> 00:00:20,210
because in the past it only had to work with docker-compose

7
00:00:20,210 --> 00:00:23,600
and dare using the service name like this, did work.

8
00:00:23,600 --> 00:00:25,130
Now we only got one line of code

9
00:00:25,130 --> 00:00:28,140
where we are sending a request to Naver service,

10
00:00:28,140 --> 00:00:29,770
and that is this one line

11
00:00:29,770 --> 00:00:33,180
so we don't need to worry about the rest of the code here.

12
00:00:33,180 --> 00:00:36,640
Nonetheless, of course, we need to adjust this

13
00:00:36,640 --> 00:00:38,580
and to make this flexible,

14
00:00:38,580 --> 00:00:41,260
I will replace it with an environment variable

15
00:00:41,260 --> 00:00:44,190
so that this again works with both Kubernetes

16
00:00:44,190 --> 00:00:47,160
but also with docker-compose.

17
00:00:47,160 --> 00:00:49,650
So I'll use a similar approach as before,

18
00:00:49,650 --> 00:00:51,910
and now here, we got two options.

19
00:00:51,910 --> 00:00:55,460
We can use the automatically generated environment variable

20
00:00:55,460 --> 00:00:56,730
for the auth-service,

21
00:00:56,730 --> 00:00:59,590
since that's the service we wanna talk to here

22
00:00:59,590 --> 00:01:02,670
or we of course use our own environment variable

23
00:01:02,670 --> 00:01:07,670
and pass in the service name in the docker-compose world

24
00:01:07,760 --> 00:01:11,740
and the service domain name in the Kubernetes world

25
00:01:11,740 --> 00:01:13,890
and I'm going to do that.

26
00:01:13,890 --> 00:01:17,290
I'm going to name it AUTH-ADDRESS here as well,

27
00:01:17,290 --> 00:01:20,620
though this environment variable name is totally up to you

28
00:01:21,580 --> 00:01:24,020
and I'm going to save this file

29
00:01:24,020 --> 00:01:26,320
in the docker-compose yaml file,

30
00:01:26,320 --> 00:01:29,190
just to ensure that this also works again.

31
00:01:29,190 --> 00:01:31,770
I will therefore add AUTH-ADDRESS

32
00:01:31,770 --> 00:01:34,020
and set this to auth,

33
00:01:34,020 --> 00:01:37,723
which is my service name here in the docker-compose file.

34
00:01:39,340 --> 00:01:41,390
But now more important than that

35
00:01:41,390 --> 00:01:46,390
we can of course create a new tasks-deployment dot yaml file

36
00:01:46,890 --> 00:01:51,350
and a new tasks-service dot yaml file.

37
00:01:51,350 --> 00:01:53,610
We need a task-service

38
00:01:53,610 --> 00:01:55,750
because this tasks container

39
00:01:55,750 --> 00:01:57,450
and the Pod in which it is running

40
00:01:57,450 --> 00:01:59,590
should be reachable from outside

41
00:01:59,590 --> 00:02:02,430
through Postman, for example.

42
00:02:02,430 --> 00:02:05,040
So let's start with the tasks-deployment

43
00:02:05,040 --> 00:02:08,669
and here we can really use the users-deployment code.

44
00:02:08,669 --> 00:02:11,820
Copy that into the tasks-deployment yaml file

45
00:02:11,820 --> 00:02:16,500
and just change the name here to tasks dash deployment

46
00:02:16,500 --> 00:02:20,120
to selector, and this label here to app tasks

47
00:02:21,170 --> 00:02:22,950
and to container of course,

48
00:02:22,950 --> 00:02:26,980
I'll label this or I'll name this container tasks as well.

49
00:02:26,980 --> 00:02:29,470
And we'll need to push our image

50
00:02:29,470 --> 00:02:31,810
and I expect to get an image here,

51
00:02:31,810 --> 00:02:35,183
which has a name of kub dash demo dash tasks.

52
00:02:36,270 --> 00:02:39,370
We also need the AUTH-ADDRESS environment variable,

53
00:02:39,370 --> 00:02:41,290
at least that's the name I just chose

54
00:02:41,290 --> 00:02:42,900
a couple of seconds ago.

55
00:02:42,900 --> 00:02:45,730
So I wanna provide this here

56
00:02:45,730 --> 00:02:47,680
and of course I wanna use the domain name

57
00:02:47,680 --> 00:02:49,010
for my auth-service.

58
00:02:49,010 --> 00:02:51,150
So this also doesn't change here

59
00:02:52,640 --> 00:02:55,563
and that's the task-deployment configured already.

60
00:02:56,850 --> 00:02:58,760
Now for the task-service,

61
00:02:58,760 --> 00:03:00,990
it's very similar to the users-service,

62
00:03:00,990 --> 00:03:03,170
so we can copy that as well,

63
00:03:03,170 --> 00:03:04,710
but of course rename it

64
00:03:04,710 --> 00:03:08,830
and select our ports with an app label auth tasks

65
00:03:10,060 --> 00:03:12,570
and set the type to LoadBalancer

66
00:03:12,570 --> 00:03:13,700
and that's important.

67
00:03:13,700 --> 00:03:15,650
It's not clusterIP

68
00:03:15,650 --> 00:03:20,170
because tasks should be reachable from outside the cluster.

69
00:03:20,170 --> 00:03:24,020
Hence, we typically use LoadBalancer

70
00:03:24,020 --> 00:03:27,680
since this gives us a great way of exposing a stable IP

71
00:03:27,680 --> 00:03:28,963
to the outside world.

72
00:03:30,010 --> 00:03:32,490
Now for the ports that should be mapped,

73
00:03:32,490 --> 00:03:34,327
we can take a look at the dockerfile

74
00:03:37,270 --> 00:03:40,400
and we see that it listens on port 8,000.

75
00:03:40,400 --> 00:03:44,900
So that's the port I wanna use here in my tasks-service

76
00:03:45,850 --> 00:03:48,660
and with that, the services declared

77
00:03:48,660 --> 00:03:50,870
that the deployment is declared.

78
00:03:50,870 --> 00:03:54,050
Now we need to create the image and push it.

79
00:03:54,050 --> 00:03:56,660
So for this on docker hub,

80
00:03:56,660 --> 00:03:59,870
we create a new repository of course,

81
00:03:59,870 --> 00:04:03,260
and name it, kub-demo dash tasks

82
00:04:03,260 --> 00:04:06,100
and of course, make sure you're using the name here,

83
00:04:06,100 --> 00:04:09,060
which you defined in your tasks-deployment file

84
00:04:11,330 --> 00:04:13,273
and create this repository.

85
00:04:15,960 --> 00:04:20,600
And then let's go into that tasks-API folder,

86
00:04:20,600 --> 00:04:24,380
and build that image with a tag of your

87
00:04:24,380 --> 00:04:28,913
docker hub account names slash kub dash demo dash tasks.

88
00:04:29,790 --> 00:04:31,850
So that this image is built

89
00:04:31,850 --> 00:04:33,340
and once it is built,

90
00:04:33,340 --> 00:04:35,780
we of course wanna push it

91
00:04:35,780 --> 00:04:38,160
just as we did it multiple times before

92
00:04:38,160 --> 00:04:42,853
for the other images like this.

93
00:04:44,290 --> 00:04:46,600
So this will now be pushed

94
00:04:46,600 --> 00:04:47,940
and once it is pushed,

95
00:04:47,940 --> 00:04:51,320
we can apply our deployment and our service here

96
00:04:51,320 --> 00:04:54,320
and everything should work thereafter.

97
00:04:54,320 --> 00:04:57,203
So let's wait for that to be pushed.

98
00:04:58,580 --> 00:05:00,300
Let's then go out of this folder

99
00:05:00,300 --> 00:05:02,630
into the Kubernetes folder here.

100
00:05:02,630 --> 00:05:06,210
We don't need to stop our existing deployments

101
00:05:06,210 --> 00:05:08,330
these can continue running.

102
00:05:08,330 --> 00:05:10,350
I just, in addition,

103
00:05:10,350 --> 00:05:13,890
wanna apply my tasks-service yaml file

104
00:05:13,890 --> 00:05:17,460
and my tasks-deployment dot yaml file,

105
00:05:17,460 --> 00:05:19,593
so these two new files we added.

106
00:05:20,980 --> 00:05:24,380
This creates the new service and the new deployment

107
00:05:24,380 --> 00:05:28,320
and hence here with get deployments,

108
00:05:28,320 --> 00:05:32,330
we see that this new deployment is coming up with get pods.

109
00:05:32,330 --> 00:05:35,200
We see that it's trying to launch this,

110
00:05:35,200 --> 00:05:39,270
but we also see something is wrong here,

111
00:05:39,270 --> 00:05:40,430
something is not working.

112
00:05:40,430 --> 00:05:43,340
So what could be the issue here?

113
00:05:43,340 --> 00:05:44,920
What's failing about this file?

114
00:05:44,920 --> 00:05:46,663
Why is it not starting?

115
00:05:47,900 --> 00:05:50,280
Well because there's a little trick here.

116
00:05:50,280 --> 00:05:54,520
This file actually uses more than one environment variable,

117
00:05:54,520 --> 00:05:57,540
you see that in the docker-compose yaml file.

118
00:05:57,540 --> 00:06:00,380
We also provide the folder name

119
00:06:00,380 --> 00:06:03,860
in which the tasks text files should be stored

120
00:06:03,860 --> 00:06:07,130
through the TASKS-FOLDER environment variable.

121
00:06:07,130 --> 00:06:10,300
So of course, we still have to provide that

122
00:06:10,300 --> 00:06:12,310
when using Kubernetes.

123
00:06:12,310 --> 00:06:15,540
Hence, in the tasks-deployment yaml file,

124
00:06:15,540 --> 00:06:18,880
we wanna add an additional environment variable

125
00:06:18,880 --> 00:06:20,820
for the tasks container

126
00:06:20,820 --> 00:06:23,630
with the name of TASKS-FOLDER,

127
00:06:23,630 --> 00:06:27,430
which simply is the environment variable name expected here

128
00:06:27,430 --> 00:06:29,873
in the tasks-app JavaScript file.

129
00:06:31,300 --> 00:06:36,040
And then we wanna provide a value here auth-tasks,

130
00:06:37,210 --> 00:06:40,010
because that is the folder name I'm using here.

131
00:06:40,010 --> 00:06:43,580
That is the folder I pre-created as an empty folder

132
00:06:43,580 --> 00:06:46,150
and therefore that is the folder name we wanna use

133
00:06:46,150 --> 00:06:48,173
in the Kubernetes world as well.

134
00:06:49,250 --> 00:06:51,310
So with that fixed,

135
00:06:51,310 --> 00:06:56,080
we can apply the updated tasks-deployment dot yaml file,

136
00:06:56,080 --> 00:06:59,570
which now does provide this environment variable.

137
00:06:59,570 --> 00:07:02,290
And now if we get our deployments,

138
00:07:02,290 --> 00:07:05,620
we see the tasks-deployment is also up and running

139
00:07:05,620 --> 00:07:06,623
and ready.

140
00:07:07,930 --> 00:07:09,470
Of course, if we get our pods,

141
00:07:09,470 --> 00:07:12,083
we also see all the pods are up and running.

142
00:07:13,240 --> 00:07:14,530
And with that now,

143
00:07:14,530 --> 00:07:17,060
we just need to ensure that we can send the request

144
00:07:17,060 --> 00:07:19,390
to the new task-service.

145
00:07:19,390 --> 00:07:20,900
So if we get our services,

146
00:07:20,900 --> 00:07:22,330
of course, we see

147
00:07:22,330 --> 00:07:24,550
we got this new task-service here,

148
00:07:24,550 --> 00:07:26,610
it's of type LoadBalancer

149
00:07:26,610 --> 00:07:29,510
and just as with the users-service

150
00:07:29,510 --> 00:07:33,450
to get the externally awaitable IP address here,

151
00:07:33,450 --> 00:07:35,000
when using minikube,

152
00:07:35,000 --> 00:07:38,900
we need to run minikube service and then the service name.

153
00:07:38,900 --> 00:07:40,940
So in this case tasks-service,

154
00:07:40,940 --> 00:07:43,510
and this gives us a new URL,

155
00:07:43,510 --> 00:07:47,633
which we can use to send requests to this tasks-service.

156
00:07:48,810 --> 00:07:51,570
The URL of the user-service,

157
00:07:51,570 --> 00:07:54,280
to which we for example, sends to signup request

158
00:07:54,280 --> 00:07:55,980
does not change,

159
00:07:55,980 --> 00:07:58,553
but we now can use this new URL

160
00:07:59,618 --> 00:08:02,800
to send the request to slash tasks.

161
00:08:02,800 --> 00:08:06,360
A simple get request to get our tasks.

162
00:08:06,360 --> 00:08:08,760
Now, if you try sending this like this,

163
00:08:08,760 --> 00:08:11,940
you should get a no token provided error.

164
00:08:11,940 --> 00:08:14,300
So make sure that here in Postman,

165
00:08:14,300 --> 00:08:16,200
you add headers,

166
00:08:16,200 --> 00:08:20,220
and then you add authorization key here

167
00:08:20,220 --> 00:08:23,250
simply by typing it and making sure it's checked

168
00:08:23,250 --> 00:08:26,500
and then add bearer white space,

169
00:08:26,500 --> 00:08:27,333
and then abc,

170
00:08:28,230 --> 00:08:31,393
which is a valid token in this dummy application.

171
00:08:32,830 --> 00:08:34,750
Now, initially you'll get a loading

172
00:08:34,750 --> 00:08:37,340
the tasks failed error back here

173
00:08:37,340 --> 00:08:40,059
because we have no tasks initially.

174
00:08:40,059 --> 00:08:42,250
So make sure you send a post request

175
00:08:42,250 --> 00:08:46,620
to the same minikube exposed URL slash tasks.

176
00:08:46,620 --> 00:08:47,980
Make sure under headers,

177
00:08:47,980 --> 00:08:50,130
you add that authorization header

178
00:08:50,130 --> 00:08:53,040
with a value of bearer white space abc

179
00:08:54,650 --> 00:08:58,840
and under body, add a raw body of type JSON

180
00:08:58,840 --> 00:09:00,080
with curly braces

181
00:09:00,080 --> 00:09:02,990
and then text and title between double quotes

182
00:09:02,990 --> 00:09:05,080
and then separated with colons,

183
00:09:05,080 --> 00:09:07,200
the values for these fields,

184
00:09:07,200 --> 00:09:10,430
like a first task and do this too,

185
00:09:10,430 --> 00:09:12,283
also between double quotes.

186
00:09:13,480 --> 00:09:16,190
And if you tried this and you sent this request,

187
00:09:16,190 --> 00:09:18,960
you should get back task stored.

188
00:09:18,960 --> 00:09:21,350
And if you then try to get request again,

189
00:09:21,350 --> 00:09:23,593
you should get back task loaded.

190
00:09:24,850 --> 00:09:29,180
And if you will enter an invalid token, like just ab,

191
00:09:29,180 --> 00:09:32,380
you should get back a request failed with status code

192
00:09:32,380 --> 00:09:34,260
for or one error.

193
00:09:34,260 --> 00:09:35,640
Which proves that

194
00:09:35,640 --> 00:09:38,610
sending this request to the auth-service works

195
00:09:38,610 --> 00:09:42,160
and validating the dummy token there works.

196
00:09:42,160 --> 00:09:45,660
And that of course shows that this tasks-app here

197
00:09:45,660 --> 00:09:48,210
was deployed correctly

198
00:09:48,210 --> 00:09:51,600
and that it is able to interact with the auth-service

199
00:09:51,600 --> 00:09:53,230
and the outside world

200
00:09:53,230 --> 00:09:56,150
because of its own service of type LoadBalancer,

201
00:09:56,150 --> 00:09:57,550
and with the auth-service,

202
00:09:57,550 --> 00:09:59,250
because of that domain name,

203
00:09:59,250 --> 00:10:03,250
the automatically generated cluster internal domain name,

204
00:10:03,250 --> 00:10:04,543
which we're using here.

