1
00:00:02,100 --> 00:00:05,390
So we defined our host Persistent Volume

2
00:00:05,390 --> 00:00:07,810
and that's the first part of the equation.

3
00:00:07,810 --> 00:00:10,070
The second part is to claim

4
00:00:10,070 --> 00:00:13,550
because this just defines the volume in the cluster,

5
00:00:13,550 --> 00:00:15,090
but in order to use it,

6
00:00:15,090 --> 00:00:17,360
we now also need a claim

7
00:00:17,360 --> 00:00:21,210
and that claim then needs to be made by the pods

8
00:00:21,210 --> 00:00:23,712
that want to use this volume.

9
00:00:23,712 --> 00:00:26,220
Therefore, we gotta do two things.

10
00:00:26,220 --> 00:00:29,400
We first of all have to configure this claim

11
00:00:29,400 --> 00:00:31,813
and then we have to use it on all the pods

12
00:00:31,813 --> 00:00:33,970
that do wanna use it.

13
00:00:33,970 --> 00:00:38,400
So I'll start by adding the host-pvc.yaml file,

14
00:00:38,400 --> 00:00:39,760
which is to claim

15
00:00:39,760 --> 00:00:41,610
that's what the C stands for,

16
00:00:41,610 --> 00:00:43,793
for this host Persistent Volume.

17
00:00:44,640 --> 00:00:47,180
And again, we could merge this all into one

18
00:00:47,180 --> 00:00:49,580
or multiple bigger yaml files,

19
00:00:49,580 --> 00:00:53,300
I'm just splitting it up here across multiple yaml files

20
00:00:53,300 --> 00:00:55,283
to keep this a bit more manageable.

21
00:00:56,180 --> 00:01:00,770
So what should go into this claim file now?

22
00:01:00,770 --> 00:01:03,230
As always, we started with the apiVersion

23
00:01:03,230 --> 00:01:05,209
and that should be v1 here again,

24
00:01:05,209 --> 00:01:08,113
just as for the Persistent Volume itself,

25
00:01:08,965 --> 00:01:12,670
then we need a kind, to make Kubernetes aware

26
00:01:12,670 --> 00:01:15,480
of which kind of resource we are creating here.

27
00:01:15,480 --> 00:01:19,910
And a claim is also a resource, everything is a resource

28
00:01:19,910 --> 00:01:21,900
in a Kuberenetes world.

29
00:01:21,900 --> 00:01:26,900
So here we add PersistentVolumeClaim, written like this.

30
00:01:27,790 --> 00:01:30,850
Again, make sure you have no typo in here,

31
00:01:30,850 --> 00:01:32,513
otherwise this will not work.

32
00:01:33,660 --> 00:01:37,610
Next, we add metadata and we give this claim a name.

33
00:01:37,610 --> 00:01:42,610
This name will later be important for using it in a pod.

34
00:01:42,850 --> 00:01:46,443
And here I'll name it, host-pvc.

35
00:01:47,640 --> 00:01:49,380
Now thereafter, you might've guessed it,

36
00:01:49,380 --> 00:01:51,700
we have to spec, the specification,

37
00:01:51,700 --> 00:01:54,590
the configuration for this claim.

38
00:01:54,590 --> 00:01:56,910
And here we of course need to specify

39
00:01:56,910 --> 00:02:00,330
which Persistent Volume we wanna claim.

40
00:02:00,330 --> 00:02:01,960
Now, here we only have one,

41
00:02:01,960 --> 00:02:04,290
but we could have multiple Persistent Volumes,

42
00:02:04,290 --> 00:02:07,810
which also could use different types, If you needed that.

43
00:02:07,810 --> 00:02:09,880
And in real big applications,

44
00:02:09,880 --> 00:02:14,030
you will of course often have multiple Persistent Volumes.

45
00:02:14,030 --> 00:02:17,800
To connect our claim to this Persistent Volume,

46
00:02:17,800 --> 00:02:22,370
in the spec of the claim, we can add a VolumeName key,

47
00:02:22,370 --> 00:02:25,590
and then simply use the name we used here

48
00:02:25,590 --> 00:02:30,030
for the Persistent Volume, in my case, host-pv,

49
00:02:30,030 --> 00:02:32,483
so that this volume will be claimed here.

50
00:02:33,840 --> 00:02:35,370
Now, I will say when it comes

51
00:02:35,370 --> 00:02:37,264
to claiming Persistent Volumes,

52
00:02:37,264 --> 00:02:41,300
Kubernetes, again offers you a lot of flexibility.

53
00:02:41,300 --> 00:02:43,720
You cannot just claim by name,

54
00:02:43,720 --> 00:02:47,330
there are other ways of claiming by resource,

55
00:02:47,330 --> 00:02:48,180
you could say.

56
00:02:48,180 --> 00:02:51,870
So that you don't claim one specific Persistent Volume,

57
00:02:51,870 --> 00:02:53,690
but if you had different volumes,

58
00:02:53,690 --> 00:02:54,607
you could just say,

59
00:02:54,607 --> 00:02:57,500
"I want the volume with that much space

60
00:02:57,500 --> 00:03:00,242
and this and that configuration."

61
00:03:00,242 --> 00:03:03,110
It would be beyond the scope of this course

62
00:03:03,110 --> 00:03:07,390
and all the more and more kind of an administrator's task

63
00:03:07,390 --> 00:03:08,460
to dive into that.

64
00:03:08,460 --> 00:03:10,520
Therefore, we're not going to do that,

65
00:03:10,520 --> 00:03:13,110
but if you dive into the official documentation

66
00:03:13,110 --> 00:03:14,910
for Persistent Volumes,

67
00:03:14,910 --> 00:03:18,330
and also in the examples you find on the Kubernetes' page,

68
00:03:18,330 --> 00:03:20,310
you will also see different ways

69
00:03:20,310 --> 00:03:23,290
of claiming a Persistent Volume.

70
00:03:23,290 --> 00:03:24,740
Claiming it by name however,

71
00:03:24,740 --> 00:03:26,640
is of course very straightforward

72
00:03:26,640 --> 00:03:29,633
and therefore all the perfect for this use case here.

73
00:03:30,700 --> 00:03:32,000
So now we made it clear

74
00:03:32,000 --> 00:03:34,670
which Persistent Volume we wanna use.

75
00:03:34,670 --> 00:03:37,750
Now we need to provide more information here.

76
00:03:37,750 --> 00:03:40,710
For example, we also need accessModes again,

77
00:03:40,710 --> 00:03:44,280
and now we need to define the modes which we wanna use here

78
00:03:44,280 --> 00:03:47,137
for claiming this volume.

79
00:03:47,137 --> 00:03:50,150
Now you could again, list multiple modes here,

80
00:03:50,150 --> 00:03:53,250
but I only want to claim by the only supported way,

81
00:03:53,250 --> 00:03:56,688
which is ReadWriteOnce access mode here.

82
00:03:56,688 --> 00:04:00,000
But if you would use this claim on different pods

83
00:04:00,000 --> 00:04:03,070
and some pods only need read access,

84
00:04:03,070 --> 00:04:05,070
other need read-write access.

85
00:04:05,070 --> 00:04:07,760
You could specify multiple access modes here

86
00:04:07,760 --> 00:04:09,770
for the claim as well.

87
00:04:09,770 --> 00:04:13,005
Next, we can add the resources key here,

88
00:04:13,005 --> 00:04:17,089
which is basically the counterpart to the capacity here.

89
00:04:17,089 --> 00:04:20,930
And we can now specify which resources we wanna get

90
00:04:20,930 --> 00:04:22,710
for this claim.

91
00:04:22,710 --> 00:04:27,160
The resources object has a request key nested below it,

92
00:04:27,160 --> 00:04:31,100
and there you then can request storage.

93
00:04:31,100 --> 00:04:34,390
Again, that's the counterpart to this capacity.

94
00:04:34,390 --> 00:04:37,330
So since I have a storage of one gigabyte

95
00:04:37,330 --> 00:04:40,570
as a capacity in this Persistent Volume,

96
00:04:40,570 --> 00:04:44,320
that's also the maximum I can request here.

97
00:04:44,320 --> 00:04:47,800
So I will actually request one gigabyte of storage here,

98
00:04:47,800 --> 00:04:51,590
but we could also request less for this claim.

99
00:04:51,590 --> 00:04:55,100
If we had multiple claims to the same Persistent Volume,

100
00:04:55,100 --> 00:04:57,950
we might wanna request less, so that in total

101
00:04:57,950 --> 00:05:01,010
we don't request more than we got available.

102
00:05:01,010 --> 00:05:02,590
This could lead to errors,

103
00:05:02,590 --> 00:05:04,740
if we then try to use all these claims

104
00:05:04,740 --> 00:05:07,770
on our pods and we started writing more data

105
00:05:07,770 --> 00:05:09,830
than we have capacity.

106
00:05:09,830 --> 00:05:13,980
And that is it, this is a Persistent Volume Claim.

107
00:05:13,980 --> 00:05:15,640
Now, as you can clearly tell

108
00:05:15,640 --> 00:05:20,210
this still doesn't establish a connection to a pod though.

109
00:05:20,210 --> 00:05:25,070
Instead does this now a claim which can now be used by pods

110
00:05:25,070 --> 00:05:29,740
to make that claim to that Persistent Volume.

111
00:05:29,740 --> 00:05:32,620
So we need to go back to the deployment yaml file

112
00:05:32,620 --> 00:05:36,420
and now connect our pod here to this claim

113
00:05:36,420 --> 00:05:40,100
so that ultimately it reaches out to this Persistent Volume

114
00:05:40,100 --> 00:05:42,780
and gets its volume.

115
00:05:42,780 --> 00:05:46,240
And we established this connection still through

116
00:05:46,240 --> 00:05:49,440
the volumes key in our pod spec.

117
00:05:49,440 --> 00:05:52,883
So in the deployment yaml file, this volumes key.

118
00:05:53,840 --> 00:05:58,580
We can keep our name here, but now the type is different

119
00:05:58,580 --> 00:06:00,400
instead of hostPath,

120
00:06:00,400 --> 00:06:04,340
which created a host path volume just for this pod,

121
00:06:04,340 --> 00:06:08,253
we now use the persistentVolumeClaim type here.

122
00:06:11,770 --> 00:06:13,890
And this does what the name implies,

123
00:06:13,890 --> 00:06:18,210
now the volume type for this pod is this claim.

124
00:06:18,210 --> 00:06:20,540
So we will use the volume created

125
00:06:20,540 --> 00:06:25,540
or accessed by this claim as a volume for this pod now.

126
00:06:25,780 --> 00:06:28,430
And you could use this in different pods of course,

127
00:06:28,430 --> 00:06:30,530
you can use one of the same claim

128
00:06:30,530 --> 00:06:32,423
in different types of pods.

129
00:06:33,430 --> 00:06:35,250
So here we were making this claim

130
00:06:35,250 --> 00:06:38,040
and we now just need to specify the claim name

131
00:06:38,040 --> 00:06:42,350
as a nested option below this persistentVolumeClaim type,

132
00:06:42,350 --> 00:06:44,740
because otherwise, of course, Kubernetes doesn't know

133
00:06:44,740 --> 00:06:46,940
which claim we might wanna make.

134
00:06:46,940 --> 00:06:49,300
Here, we only have one, but again,

135
00:06:49,300 --> 00:06:51,890
in bigger projects and bigger clusters,

136
00:06:51,890 --> 00:06:55,000
you of course might have multiple claims.

137
00:06:55,000 --> 00:06:58,453
So here it's this claim with this name here.

138
00:06:58,453 --> 00:07:01,830
And therefore I will use host-pvc

139
00:07:01,830 --> 00:07:04,083
as a claim name for this volume.

140
00:07:05,310 --> 00:07:06,980
We don't need to change anything

141
00:07:06,980 --> 00:07:10,560
about the volumeMounts here because we still mounted

142
00:07:10,560 --> 00:07:12,220
in the same way as before.

143
00:07:12,220 --> 00:07:15,550
Now, it's just a volume not created specifically

144
00:07:15,550 --> 00:07:19,283
for this pod, but instead for the entire cluster.

145
00:07:20,150 --> 00:07:22,310
And that of course was a lot of talking

146
00:07:22,310 --> 00:07:23,870
and a lot of work.

147
00:07:23,870 --> 00:07:26,610
But with that, if we now apply everything

148
00:07:26,610 --> 00:07:28,190
and start everything,

149
00:07:28,190 --> 00:07:30,470
we should be able to have our application up

150
00:07:30,470 --> 00:07:31,730
and running again.

151
00:07:31,730 --> 00:07:36,730
But now data should be fully independent from our pods.

152
00:07:36,810 --> 00:07:40,360
Just as before with the host path as I will admit,

153
00:07:40,360 --> 00:07:44,640
but now theoretically all is independent from our nodes.

154
00:07:44,640 --> 00:07:48,570
Not for this host path demo here, as I explained.

155
00:07:48,570 --> 00:07:51,470
There we still have this node dependency,

156
00:07:51,470 --> 00:07:53,740
but as I also mentioned multiple times,

157
00:07:53,740 --> 00:07:56,770
what you learned about setting up Persistent Volumes

158
00:07:56,770 --> 00:08:00,330
and persistentVolumeClaims will also hold true,

159
00:08:00,330 --> 00:08:03,170
if you would use a different volume type here.

160
00:08:03,170 --> 00:08:07,000
And then you would have real node independence.

161
00:08:07,000 --> 00:08:08,593
So let's give this a try now.

