WEBVTT

00:00.240 --> 00:03.400
In the last section, we finished up our persistent volume claim.

00:03.560 --> 00:06.960
I'm now going to flip over to my Postgres deployment file.

00:08.000 --> 00:10.240
So I'm going to find the template section of this.

00:10.280 --> 00:15.240
Remember this is the template that is used for every pod that is created by this deployment.

00:15.240 --> 00:17.960
And there's only ever going to be one pod at a time.

00:18.560 --> 00:23.520
We are going to update this template section and tell this pod that when it is created, it needs to

00:23.560 --> 00:26.720
request some type of long term storage.

00:26.720 --> 00:32.040
In other words, a persistent volume that meets all the requirements that were advertised by this persistent

00:32.040 --> 00:34.000
volume claim that we just put together.

00:34.800 --> 00:38.960
So inside of my Postgres deployment file, I'll find the template section.

00:38.960 --> 00:40.600
And then the spec inside there.

00:40.840 --> 00:44.480
And inside the spec we're going to add on a new key value pair.

00:44.920 --> 00:48.280
So I'm on the same indentation level as containers right here.

00:48.920 --> 00:51.040
And I'm going to say volumes.

00:52.080 --> 00:53.480
This is going to be an array.

00:53.480 --> 00:58.800
So I'll put a dash in and then I'll say name of Postgres storage.

00:59.520 --> 01:01.000
And then persistent.

01:01.560 --> 01:04.520
Persistent volume claim.

01:06.640 --> 01:07.920
Claim name.

01:08.120 --> 01:11.960
And this is going to be the name of the claim that we had just put together in the other file.

01:12.200 --> 01:15.360
It's name was database persistent volume claim.

01:15.920 --> 01:22.200
So the claim name will be database persistent volume claim.

01:26.680 --> 01:27.040
Okay.

01:27.040 --> 01:32.840
So this right here is what sets up the request on the pod to reach out to Kubernetes and say I need

01:32.840 --> 01:38.160
some type of long term storage that meets all the requirements that are laid out inside of this database

01:38.160 --> 01:40.040
persistent volume claim object.

01:40.040 --> 01:42.360
And that's what we just put together over here.

01:43.000 --> 01:47.600
So this line alone is what's going to make Kubernetes realize that it needs to go over to either the

01:47.600 --> 01:48.560
local hard drive.

01:48.680 --> 01:53.280
If we are in the case of your local environment or some cloud provider, in the case of being deployed

01:53.280 --> 02:00.360
in production and say, hey, I need to somehow source or somehow get some slice of storage that has

02:00.760 --> 02:03.970
this access mode and storage of two gigabytes.

02:04.730 --> 02:07.890
So all this is going to do right here is allocate that storage.

02:08.050 --> 02:12.930
Once we allocate that storage, once we get it available, we need to actually assign it for use by

02:12.930 --> 02:15.690
all the different containers that are in use by our pod.

02:16.090 --> 02:20.970
So in addition to this volume section right here, we're also going to add on some config to our container

02:20.970 --> 02:22.090
section as well.

02:22.850 --> 02:26.570
So inside my container section I'm going to add in a new line here.

02:26.570 --> 02:30.490
And I'm going to get on the same indentation level as name image and ports.

02:30.770 --> 02:33.330
And I'll say volume mounts.

02:34.490 --> 02:37.810
So this is going to say hey all right we just got access to the storage.

02:37.810 --> 02:40.970
And here's how I want it to be used inside of my container.

02:41.490 --> 02:44.290
So I'm going to add in a dash here because this is an array.

02:44.290 --> 02:46.730
We can have multiple volume mounts on a single container.

02:47.170 --> 02:53.610
I'll give it a name of Postgres Postgres storage.

02:53.650 --> 02:55.530
Now this right here is the most important part.

02:55.730 --> 03:00.410
Notice how the volume name and the volume mount name are identical.

03:00.610 --> 03:05.650
So when you put the name right here, it means go back out to the volumes entry Century and find some

03:05.650 --> 03:08.410
piece of storage that we just asked Kubernetes for.

03:08.650 --> 03:11.730
In this case, it's going to find this piece of storage right here.

03:11.890 --> 03:15.290
And that piece of storage is going to be used for this particular volume mount.

03:17.050 --> 03:19.370
We're then going to put in a mount path.

03:19.730 --> 03:24.570
The mount path is designating where inside the container this storage should be made available.

03:25.090 --> 03:28.170
So in other words we're going to put in a little folder reference right here.

03:28.170 --> 03:33.210
And then anything that the container stores at that folder or inside that directory will be actually

03:33.410 --> 03:35.210
stored inside of our volume.

03:35.410 --> 03:39.130
Remember this is at the end of the day, pretty darn similar to the Docker volumes that we had used

03:39.130 --> 03:39.770
previously.

03:40.250 --> 03:46.450
So for the mount path, we're going to designate the data directory that Postgres uses for storing data

03:46.450 --> 03:49.330
on the hard drive, because that's the actual data that we want to back up.

03:49.330 --> 03:53.090
We want to back up all the data that Postgres is storing on the hard drive.

03:53.690 --> 04:01.010
The default storage location for Postgres is var lib PostgreSQL slash data like so.

04:03.890 --> 04:06.770
Okay, now for a normal volume that would be it.

04:06.770 --> 04:10.970
So if this was just a normal application where we're just trying to set up some persistent storage,

04:10.970 --> 04:13.690
that's really all we have to do with Postgres.

04:13.730 --> 04:15.130
Postgres in particular.

04:15.170 --> 04:17.850
We're going to put in one additional little option here.

04:18.250 --> 04:22.890
So as an additional option I'm going to also put in sub path is Postgres like.

04:22.890 --> 04:29.610
So the sub path option means that any data inside the container that is stored inside of mount path

04:29.730 --> 04:35.810
is going to be stored inside of a folder called Postgres, inside of the actual persistent volume claim.

04:36.490 --> 04:41.610
So if we ran our application for some amount of time and then save some data to our Postgres database

04:41.610 --> 04:46.650
and then eventually opened up our persistent volume, we would see that all the data that was saved

04:46.650 --> 04:52.090
to this folder is nested inside of a folder called Postgres inside the persistent volume.

04:52.370 --> 04:55.570
Now, like I said, this is something very specific for Postgres.

04:55.610 --> 05:00.850
It's just because if you try to start up Postgres by default with something that it thinks is a volume

05:00.850 --> 05:03.610
mount, it's going to say, hey, I don't want to save data here.

05:04.010 --> 05:08.860
And so by having Postgres instead save data into a sub folder inside there.

05:08.860 --> 05:11.100
It's going to override that default behavior.

05:11.460 --> 05:14.740
Now saving data into a volume with Postgres is totally fine.

05:14.780 --> 05:15.420
Totally fine.

05:15.420 --> 05:19.900
It's just that Postgres in some cases thinks that you're not necessarily working with Docker.

05:19.940 --> 05:20.340
It gets.

05:20.380 --> 05:21.140
It's a long story.

05:21.140 --> 05:22.220
Let's just leave it at that.

05:22.300 --> 05:24.700
This is just some very particular stuff around Postgres.

05:24.740 --> 05:28.620
Probably not super interesting to you or what you're going to be working on in your own application.

05:28.620 --> 05:29.820
So I'm just going to stop right there.

05:30.220 --> 05:30.540
All right.

05:30.540 --> 05:31.580
So that's pretty much it.

05:32.420 --> 05:33.900
Let's do a very quick review here.

05:33.900 --> 05:39.740
We put together the persistent volume claim that tells Kubernetes that we want to find a storage option

05:39.740 --> 05:41.100
with these requirements.

05:41.540 --> 05:46.820
When we put together our Pod template we said we want to have a volume available that matches these

05:46.820 --> 05:47.660
requirements.

05:47.860 --> 05:53.300
And then inside the container we put together some actual options to say take that volume and make it

05:53.300 --> 05:56.180
available inside of this very particular container.

05:56.380 --> 05:57.620
So that's the entire story.

05:57.660 --> 05:58.980
Let's take a quick pause right here.

05:58.980 --> 06:03.620
When we come back to the next section, we're going to try to apply all these updated config files and

06:03.620 --> 06:06.260
just make sure that everything is working the way we expect.

06:06.260 --> 06:08.540
So quick pause and I'll see you in just a minute.
