1
00:00:02,150 --> 00:00:04,430
Now that we learned about the crucial

2
00:00:04,430 --> 00:00:05,840
feature of volumes,

3
00:00:05,840 --> 00:00:07,160
persistent volumes,

4
00:00:07,160 --> 00:00:09,340
and persistent volume claims.

5
00:00:09,340 --> 00:00:12,600
The last topic I wanna cover in this course section

6
00:00:12,600 --> 00:00:14,713
would be environment variables.

7
00:00:16,040 --> 00:00:17,400
Because environment variables

8
00:00:17,400 --> 00:00:18,500
of course matter

9
00:00:18,500 --> 00:00:20,143
in a lot of applications.

10
00:00:21,080 --> 00:00:23,920
Let's say in this application here.

11
00:00:23,920 --> 00:00:26,890
The application we've been working on all the time.

12
00:00:26,890 --> 00:00:28,870
This story folder,

13
00:00:28,870 --> 00:00:31,650
in which we stored a text text file

14
00:00:31,650 --> 00:00:34,270
is of course hard-coded in the code.

15
00:00:34,270 --> 00:00:35,330
Now actually,

16
00:00:35,330 --> 00:00:36,760
the fact that

17
00:00:36,760 --> 00:00:39,690
we do store data in a story folder

18
00:00:39,690 --> 00:00:41,220
is however configured

19
00:00:41,220 --> 00:00:44,260
in our deployment yaml file, here.

20
00:00:44,260 --> 00:00:46,370
At least that is the folder

21
00:00:46,370 --> 00:00:47,420
which we save

22
00:00:47,420 --> 00:00:48,893
with help of a volume.

23
00:00:49,980 --> 00:00:51,550
So we might prefer

24
00:00:51,550 --> 00:00:54,080
to set up that exact folder name here

25
00:00:54,080 --> 00:00:56,040
in our yaml files,

26
00:00:56,040 --> 00:00:58,990
and use it through an environment variable

27
00:00:58,990 --> 00:01:01,370
inside of app JS.

28
00:01:01,370 --> 00:01:04,060
And we learned about applying environment variables

29
00:01:04,060 --> 00:01:06,170
with Docker and Docker compose.

30
00:01:06,170 --> 00:01:07,700
Of course, Kubernetes

31
00:01:07,700 --> 00:01:10,470
also supports environment variables.

32
00:01:10,470 --> 00:01:11,303
And for that,

33
00:01:11,303 --> 00:01:12,550
let's start the code.

34
00:01:12,550 --> 00:01:13,930
Here I will replace

35
00:01:13,930 --> 00:01:15,450
the hard-coded story

36
00:01:15,450 --> 00:01:16,690
folder name

37
00:01:16,690 --> 00:01:18,683
with process.env.STORY_FOLDER.

38
00:01:21,880 --> 00:01:23,340
This name is up to you.

39
00:01:23,340 --> 00:01:24,530
It's your program,

40
00:01:24,530 --> 00:01:25,710
it's your environment,

41
00:01:25,710 --> 00:01:27,700
the names are up to you.

42
00:01:27,700 --> 00:01:29,560
But of course now we need to ensure

43
00:01:29,560 --> 00:01:31,260
that this environment variable

44
00:01:31,260 --> 00:01:33,560
is set to a folder name

45
00:01:33,560 --> 00:01:34,800
we wanna use

46
00:01:34,800 --> 00:01:37,193
when we deploy our cluster.

47
00:01:38,080 --> 00:01:40,540
And therefore we need to provide a value

48
00:01:40,540 --> 00:01:42,530
for this environment variable.

49
00:01:42,530 --> 00:01:44,830
And the easiest way of doing that

50
00:01:44,830 --> 00:01:48,780
is to go to the file where you define your pod,

51
00:01:48,780 --> 00:01:50,480
and therefore the container,

52
00:01:50,480 --> 00:01:52,360
which is executed in the pod.

53
00:01:52,360 --> 00:01:55,990
So in our case, the deployment.yaml file,

54
00:01:55,990 --> 00:01:57,550
and in there,

55
00:01:57,550 --> 00:02:00,000
in your containers config,

56
00:02:00,000 --> 00:02:01,920
next to volume mounts,

57
00:02:01,920 --> 00:02:02,753
and image,

58
00:02:02,753 --> 00:02:03,586
and so on,

59
00:02:03,586 --> 00:02:05,563
you can add a env key.

60
00:02:06,810 --> 00:02:08,180
And below that,

61
00:02:08,180 --> 00:02:10,910
so indented below the env key

62
00:02:10,910 --> 00:02:14,410
you can set up all your environment key value pairs

63
00:02:14,410 --> 00:02:16,100
which you might need.

64
00:02:16,100 --> 00:02:18,860
Simply by adding a list of environment variables

65
00:02:18,860 --> 00:02:20,583
by using dashes here.

66
00:02:21,450 --> 00:02:22,520
So my first,

67
00:02:22,520 --> 00:02:24,450
and in this case only environment variable

68
00:02:24,450 --> 00:02:25,600
which I wanna set

69
00:02:25,600 --> 00:02:27,180
has a name,

70
00:02:27,180 --> 00:02:28,940
and that's something you need to provide

71
00:02:28,940 --> 00:02:31,090
the name of the environment variable

72
00:02:31,090 --> 00:02:35,690
of story underscore, folder.

73
00:02:35,690 --> 00:02:38,610
So that name you chose here in your code

74
00:02:38,610 --> 00:02:39,840
that's the name

75
00:02:39,840 --> 00:02:41,290
for the environment variable

76
00:02:41,290 --> 00:02:43,050
you wanna define here.

77
00:02:43,050 --> 00:02:45,130
And then of course, besides the name,

78
00:02:45,130 --> 00:02:46,220
we also need,

79
00:02:46,220 --> 00:02:47,230
a value.

80
00:02:47,230 --> 00:02:48,920
So that's the second key

81
00:02:48,920 --> 00:02:51,760
you need to provide for every environment variable.

82
00:02:51,760 --> 00:02:52,620
So name

83
00:02:52,620 --> 00:02:53,890
of the environment variable,

84
00:02:53,890 --> 00:02:54,750
and value

85
00:02:54,750 --> 00:02:56,580
for that environment variable.

86
00:02:56,580 --> 00:02:58,463
In this case, story.

87
00:02:59,730 --> 00:03:02,050
But of course you could choose a different name here,

88
00:03:02,050 --> 00:03:02,883
but then

89
00:03:02,883 --> 00:03:04,840
you should also bind a different folder

90
00:03:04,840 --> 00:03:05,673
with your

91
00:03:05,673 --> 00:03:06,583
volume here.

92
00:03:07,630 --> 00:03:10,970
But with that we now externalized this name,

93
00:03:10,970 --> 00:03:13,490
and we make it more flexible.

94
00:03:13,490 --> 00:03:16,940
Now, if we ever want to go for a different folder name

95
00:03:16,940 --> 00:03:19,870
we only need to make changes here

96
00:03:19,870 --> 00:03:20,900
in our

97
00:03:20,900 --> 00:03:22,240
containers pack,

98
00:03:22,240 --> 00:03:26,030
and we don't need to make any changes to app JS anymore

99
00:03:26,030 --> 00:03:29,283
because we are utilizing an environment variable here.

100
00:03:30,950 --> 00:03:32,110
Hence here now,

101
00:03:32,110 --> 00:03:33,330
if I

102
00:03:33,330 --> 00:03:35,250
update my image tag,

103
00:03:35,250 --> 00:03:37,800
or we set the image pull policy

104
00:03:37,800 --> 00:03:40,000
to always pull the updated image,

105
00:03:40,000 --> 00:03:41,230
which I don't have here,

106
00:03:41,230 --> 00:03:43,040
hence I changed the tag.

107
00:03:43,040 --> 00:03:45,090
Then we just need to

108
00:03:45,090 --> 00:03:47,120
build this image again,

109
00:03:47,120 --> 00:03:52,120
with a tag of academind/kub-data-demo,

110
00:03:52,160 --> 00:03:52,993
and then

111
00:03:52,993 --> 00:03:54,300
a tag of 2,

112
00:03:54,300 --> 00:03:56,890
so colon 2 here,

113
00:03:56,890 --> 00:03:58,560
hit enter,

114
00:03:58,560 --> 00:04:00,010
and once this is built, of course,

115
00:04:00,010 --> 00:04:04,580
docker push academind kub-data-demo,

116
00:04:04,580 --> 00:04:06,540
with tag 2.

117
00:04:06,540 --> 00:04:09,000
And now this is pushed to Docker Hub,

118
00:04:09,000 --> 00:04:10,200
so that now

119
00:04:10,200 --> 00:04:11,033
this will

120
00:04:11,033 --> 00:04:12,200
be pulled, and used

121
00:04:12,200 --> 00:04:15,330
if we apply our changes to the deployment.

122
00:04:15,330 --> 00:04:18,930
So let's wait for this push process to finish.

123
00:04:18,930 --> 00:04:23,207
And then let's apply this updated deployment.yaml file,

124
00:04:25,110 --> 00:04:27,173
so that the deployment is updated.

125
00:04:28,180 --> 00:04:30,260
Our old pods will be

126
00:04:30,260 --> 00:04:32,230
terminated eventually

127
00:04:32,230 --> 00:04:33,390
here you can see it,

128
00:04:33,390 --> 00:04:35,453
and the new pods are up and running.

129
00:04:37,850 --> 00:04:39,840
Now getting the data still works,

130
00:04:39,840 --> 00:04:41,470
and everything still works.

131
00:04:41,470 --> 00:04:42,780
But now under the hood,

132
00:04:42,780 --> 00:04:46,163
we are using our environment variables.

