Skip to main content

Minikube: Using Local Storage

Hands-On Lab

 

Photo of Michael McClaren

Michael McClaren

Linux Training Architect I in Content

Length

00:30:00

Difficulty

Beginner

In this hands-on lab, we will be creating a static volume and then mapping that volume into our pod on our Kubernetes cluster. We will be using predefined YAML files for this, and manually building each object from those files.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Minikube: Using Local Storage

Introduction

In this hands-on lab, we will be creating a static volume and then mapping that volume into our pod on our Kubernetes cluster. We will be using predefined YAML files for this, and manually building each object from those files.

The Scenario

We have been tasked with creating a persistent store for the development of a web application. The development team no longer wants to have to reconfigure the web container each time that they change the deployment. Instead, they want the home directory of the container to be mounted so that they can update the index file externally. We will need to create a volume that is mapped locally so that it can be used to store the index.html file for the Nginx container. Then we will need to create a PersistentVolumeClaim and map that claim to the Nginx Pod.

Logging In

Use the credentials provided on the hands-on lab overview page, and log in as cloud_user.

Start the Minikube Cluster (Remember to Use the Correct Driver)

Issue this command:

sudo minikube start --vm-driver none

Using the Provided YAML files, Create a Volume with a Local Mapping and then a Claim and Pod for that Volume

Locate the local folder in the cloud_user home directory, and get into it:

ls
cd local

In this directory inspect the pv-hostPath-volume.yaml (with cat) and locate the local mapping:

hostPath:
path: "/home/cloud_user/html"

Create the directory indicated in the hostPath:

mkdir /home/cloud_user/html

In this directory create an index.html file:

echo 'This is the local index' >> /home/cloud_user/html/index.html

Create the volume and PersistentVolumeClaim and ensure that they are bound:

kubectl apply -f /home/cloud_user/local/pv-hostPath-volume.yaml
kubectl apply -f /home/cloud_user/local/pv-hostPath-claim.yaml

kubectl get pv  # this output should show the volume status as Available
kubectl get pvc # this output should show Bound

Now let's create the Nginx pod and then run curl on the pod IP to ensure that the custom index loads:

kubectl apply -f /home/cloud_user/local/pv-hostPath-pod.yaml
kubectl get po -o wide

There's going to be an IP address in the output of that command. We need it in this next command:

curl <IP_ADDRESS>

We should see what we put in the index.html file earlier. Now, to see the power of what we've done here, let's append to that file:

echo 'this is a new line' >> /home/cloud_user/html/index.html

Then we'll run that curl command again, and see that our new content is showing up -- without having to restart the container!

Conclusion

We're done. We've given the development team exactly what they wanted. Now they can just edit whatever is in the local storage (in this case index.html) and not have to bother with reconfiguring a container. Congratulations!