1
00:00:02,300 --> 00:00:05,310
For pod-internal communication

2
00:00:05,310 --> 00:00:08,230
so when two containers run in the same pod,

3
00:00:08,230 --> 00:00:09,930
and that's important, only then,

4
00:00:09,930 --> 00:00:12,900
kubernetes allows you to send a request

5
00:00:12,900 --> 00:00:16,770
to the localhost address and then using the pod

6
00:00:16,770 --> 00:00:19,173
which is exposed by that other container.

7
00:00:20,160 --> 00:00:23,850
So localhost is the magic address

8
00:00:23,850 --> 00:00:26,710
you can use inside of a pod.

9
00:00:26,710 --> 00:00:29,450
So if you have one container running in a pod,

10
00:00:29,450 --> 00:00:31,330
which executes some code

11
00:00:31,330 --> 00:00:34,360
which also runs on the server side so to say,

12
00:00:34,360 --> 00:00:37,530
ends up the pod, and that code needs an address

13
00:00:37,530 --> 00:00:40,030
you can use a localhost as an address

14
00:00:40,030 --> 00:00:41,800
if you wanna send the request

15
00:00:41,800 --> 00:00:45,093
to another container running in the same pod.

16
00:00:46,770 --> 00:00:50,120
Therefore here, in the users-deployment,

17
00:00:50,120 --> 00:00:55,120
for our users container, we wanna add the env field

18
00:00:55,420 --> 00:00:58,342
to provide a value for that

19
00:00:58,342 --> 00:01:02,700
AUTH_ADDRESS environment variable, in that users container

20
00:01:02,700 --> 00:01:05,250
and then as you learned in the last core section

21
00:01:05,250 --> 00:01:08,690
for env, we can have multiple environment variables.

22
00:01:08,690 --> 00:01:10,600
And for every environment variable

23
00:01:11,550 --> 00:01:14,890
created with such a dash here, we provide a name

24
00:01:14,890 --> 00:01:16,770
which is the name of the environment variable.

25
00:01:16,770 --> 00:01:18,733
So in my case AUTH_ADDRESS

26
00:01:19,670 --> 00:01:22,040
and then we also have a value

27
00:01:22,040 --> 00:01:23,940
and we could get that from a file

28
00:01:23,940 --> 00:01:26,000
as shown in the last section

29
00:01:26,000 --> 00:01:27,770
but here, I will just hard-code it

30
00:01:27,770 --> 00:01:30,887
into debt's deployment file and use localhost,

31
00:01:31,750 --> 00:01:33,800
and this should do the trick.

32
00:01:33,800 --> 00:01:36,550
Now we provide auth as an address

33
00:01:36,550 --> 00:01:41,260
in the docker-compose world using that other services name

34
00:01:42,780 --> 00:01:46,340
and we use local hosts in the kubernetes world

35
00:01:46,340 --> 00:01:49,490
which should work since that is the special address

36
00:01:49,490 --> 00:01:52,660
that can be used inside of one and the same pod,

37
00:01:52,660 --> 00:01:55,440
if two containers running in that same pod

38
00:01:55,440 --> 00:01:57,283
wanna communicate with each other.

39
00:01:58,550 --> 00:02:01,750
So, if we now save this,

40
00:02:01,750 --> 00:02:04,320
we can go out of that users API folder

41
00:02:04,320 --> 00:02:08,310
into the kubernetes folder and apply

42
00:02:09,610 --> 00:02:14,383
the updated users-deployment.yaml file.

43
00:02:15,350 --> 00:02:18,610
This updates, the deployment

44
00:02:18,610 --> 00:02:20,590
hence if we now run get pods,

45
00:02:20,590 --> 00:02:22,870
we see that one pod is being created now

46
00:02:22,870 --> 00:02:25,020
and the containers are being created there.

47
00:02:26,880 --> 00:02:28,010
And once that finished

48
00:02:28,010 --> 00:02:30,190
we see the old pod is being terminated

49
00:02:30,190 --> 00:02:31,880
and the new pod is up and running

50
00:02:31,880 --> 00:02:34,320
and there we got two containers in the pod.

51
00:02:34,320 --> 00:02:37,200
That's what this 2/2 means two containers

52
00:02:37,200 --> 00:02:39,460
and both are up and running.

53
00:02:39,460 --> 00:02:42,510
So that's looking good we got two containers up and running.

54
00:02:42,510 --> 00:02:46,550
Now let's see whether that really all works.

55
00:02:46,550 --> 00:02:50,360
Our service IP and the service address exposed by minikube

56
00:02:50,360 --> 00:02:51,990
didn't change in the meantime

57
00:02:51,990 --> 00:02:55,210
changing the deployment does not change the service

58
00:02:55,210 --> 00:02:57,440
and therefore we should be able to send

59
00:02:57,440 --> 00:03:00,900
that same sign up request again, in postman.

60
00:03:00,900 --> 00:03:04,170
So a POST request to that minikube exposed

61
00:03:04,170 --> 00:03:05,720
IP address and port

62
00:03:05,720 --> 00:03:10,040
two slash signup with some raw JSON data attached

63
00:03:10,040 --> 00:03:13,050
an email address and a password

64
00:03:13,050 --> 00:03:16,420
and if I click send, this is looking good.

65
00:03:16,420 --> 00:03:19,690
This is looking good because if something would fail

66
00:03:19,690 --> 00:03:23,520
about sending that request here, when we sign up

67
00:03:23,520 --> 00:03:26,460
sending that request to the off service,

68
00:03:26,460 --> 00:03:28,810
if something would fail about that,

69
00:03:28,810 --> 00:03:32,430
we should not get back 'User created' as a response,

70
00:03:32,430 --> 00:03:35,510
instead, if this would throw some kind of error,

71
00:03:35,510 --> 00:03:38,530
because the address isn't found or anything like that,

72
00:03:38,530 --> 00:03:41,960
we should actually get back an error response

73
00:03:41,960 --> 00:03:44,513
and we are not which proves that it works.

74
00:03:45,740 --> 00:03:48,690
Now let's try sending the same request data

75
00:03:48,690 --> 00:03:51,030
to the slash login service.

76
00:03:51,030 --> 00:03:53,280
and we get back token 'abc',

77
00:03:53,280 --> 00:03:55,660
which again, proves that it works

78
00:03:55,660 --> 00:03:59,570
because that token value, is actually not created

79
00:03:59,570 --> 00:04:02,770
in the users service file here

80
00:04:02,770 --> 00:04:05,370
but in the auth-app.js file.

81
00:04:05,370 --> 00:04:08,580
Is here where this token is being generated

82
00:04:08,580 --> 00:04:11,883
and where this value of 'abc' is being sent back.

83
00:04:12,740 --> 00:04:15,230
So that again proves, that it works

84
00:04:15,230 --> 00:04:18,899
because we're using localhost as an address name here

85
00:04:18,899 --> 00:04:22,740
since we got two containers running in the same pod,

86
00:04:22,740 --> 00:04:25,790
and then for the pod-internal communication,

87
00:04:25,790 --> 00:04:27,497
we can use localhost.

