So now let's add this EFS file system
as a volume.
And at the moment, this integration,
this driver provided by AWS for EFS
only works with persistent volumes.
So that's what I'll add here.
For that, we can add a new file here
in our kubernetes folder
and I'll name is users-pv.yaml.
Alternatively, of course, we add it into the same YAML file
as we used before.
And actually, let's do that.
I'll delete the new file
and go to users.yaml
and add my persistent volume here.
Add three dashes above the service
and then add the persistent volume here
by specifying an apiVersion of v1.
And setting the kind to PersistentVolume.
Make sure you don't have any typo here.
Also, by the way, now that I think about it,
make sure that you have a users folder,
an empty users folder in your users-api folder
so that when this is pushed,
when the updated image is pushed,
we also do have that folder there
so that writing to that folder succeeds.
Now, for the moment, however, let's go back to users.yaml
to this PersistentVolume definition, which we're adding.
And then add some metadata here.
Give it a name of efs-pv, for example,
for Elastic File System persistent volume.
And add a specification.
Now, here there are various things which we can set up.
For example, the capacity.
Though actually, in EFS's case,
that doesn't matter too much.
You find that here in the official docs
on the GitHub page as well.
You can specify a capacity
but due to the nature of EFS,
that doesn't really matter.
So here, I will just add a capacity,
a storage capacity of five gigabytes let's say.
And we also add a volumeMode of Filesystem.
And this does matter and is important.
volumeMode should be Filesystem
because EFS is a file system service.
Now, for the accessModes, here I wanna allow ReadWriteMany
so that multiple nodes can actually use that volume
so that if our pods would be distributed
across multiple nodes,
which could happen, we do have two nodes after all
so that all these pods could use that file system
and that volume.
And then also add a storageClassName of efs-sc here.
Last but not least, add the csi option here
and then nested below that,
the driver name, which is efs.csi.aws.com.
And identifier, you, by the way, find on the official docs
if you dive into the examples there.
And then add the volumeHandle option here
and set this equal to your file system ID.
So this ID for the created file system.
This should be added here as a volumeHandle value.
Now, let me come back to that StorageClass here.
Previously, we used the standard StorageClass.
Here we need a specific StorageClass
for the Elastic File System
but at the moment,
this doesn't exist yet on our Kubernetes cluster.
We can see this if we run kubectl get sc
to get a list of all storage classes.
There we see there is not efs-sc storage class.
To get that class,
we can go back to this GitHub repository
of the EFS driver
and here on the examples/kubernetes folder
on Static Provisioning,
there specs, you find the storageclass.yaml file
and you can just copy this code here
and add this as another resource definition
above the PersistentVolume.
This configures this StorageClass by pointing
at this driver.
The driver itself already was installed by us.
And with that, we have the StorageClass
and the PersistentVolume.
Now we just need to claim that volume from inside our pod,
from inside our container to be specific
so that our container uses this as a volume.
For that, in the deployment resource here
of our users.yaml file,
next to the containers option,
add a volumes option.
So on the same level as containers.
And there, add a dash
because I wanna register one volume here
and give it any name of your choice.
Like efs-vol.
And as a type, which is the next key you have to add here,
add persistentVolumeClaim.
And that's, of course, all something I already explained
in an earlier course section.
I'm just going through that slowly
so that we're all onboard.
Here, you should add a claimName
and here, we need to specify our persistentVolumeClaim name.
Now, of course, we haven't created a claim yet.
So let's also do that first.
Scroll up again and then maybe here,
above the service, add three more dashes
and between that, so between the PersistentVolume
and the Service,
add another definition with apiVersion: v1
of kind PersistentVolumeClaim.
With a capital P though.
And here, we wanna give that claim a name.
Maybe name it efs-pvc for PersistentVolumeClaim.
And give it a spec, a configuration
where we request the ReadWriteMany accessModes
and that should be accessModes here.
So we add the ReadWriteMany access mode here
with a dash.
We add a storageClassName of efs-sc
to use that StorageClass, which is getting created up there,
which is also used by the PersistentVolume
and we must use the same StorageClass here
for the claim as we use for the PersistentVolume itself.
And then let's add resources,
which we request here.
And let's request some storage
and actually here, I'll request the full five gigabytes.
Now we've got the claim created,
now we can use this claimName down there
when we wanna get access to the claim in our pod.
So that's the next thing we've gotta do here.
And with that access gained here,
on the container next to env,
so on the same level as env,
we can add our volumeMounts
to mount this volume into a specific path in the container.
Now, we can have multiple volumeMounts,
hence the dash here
and then we specify the name
of the volume which you wanna use.
So here, efs-vol.
And then as a second field,
the mountPath, so the path inside of the container.
And here, that's actually /app
because that's our working directory
into which this entire folder structure here is copied
and then /users because we're writing
to that users subfolder,
which I also created as an empty folder here.
So our mountPath in the container is /app/users.
And that should be all.
That should be the configuration we need here
to add this CSI EFS driver as a volume
to this deployment.
We created a StorageClass,
we created a PersistentVolume,
a PersistentVolumeClaim,
and we connected all of that to our pod
and then, of course, finally, to the container.