Minikube: Persistent Storage

30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we will be dynamically creating storage and using it with our application. This is useful when the data that an application (e.g. a database) requires does not need to be pre-staged, or it is inserted via the application.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Start Minikube Using the Correct Driver

Run the command:

sudo minikube start --vm-driver none
Create the Persistent Volume Claim Taking Note of the Claim Name

Make sure that the name of the claim matches the claimName in the pod file:

cd ~/dynamic
cat ./mysql-volume.yaml

While still in the dynamic directory
Create the volume:

sudo kubectl apply -f  ./mysql-volume.yaml
Create the MySQL Container

Verify that the volume target name in the mysql-pod.yaml matches the claim name from the previous step

cd ~/dynamic
cat ./mysql-pod.yaml

Run the command:

sudo kubectl apply -f ~/dynamic/mysql-pod.yaml

Ensure the container is started (it might take a couple of minutes to show (READY):

sudo kubectl get po

We’ll need the IP of the container, so let’s run that same command, but with an extra option:

sudo kubectl get po -o wide

Make a note of that IP, because we’ll need it in a minute.

Install the MySQL Client and Connect to the Service Using the root Password for MySQL

This will install the latest version of the database client:

sudo apt install -y mysql-client

Before we can log into the database though, we’ll need the root password. Look for it in the pod YAML using this:

cat ~/dynamic/mysql-pod.yaml

Look beneath the line that says MYSQL_ROOT_PASSWORD.

Now, with that password and the IP from a minute ago, let’s log in:

mysql -h <IP_ADDRESS> -u root -p<MYSQL_ROOT_PASSWORD>
Create a Database Once Logged into MySQL

From the mysql command prompt get a list of the default databases:

show databases;

Create a new database, to ensure things are working correctly:

create database example;

Show the databases again to see if our new one is there:

show databases;

Now exit MySQL:


Additional Resources

Our company has determined that it needs an available database solution that works within a Kubernetes cluster. We have decided to implement this using dynamically allocated storage. We will need to create a persistent volume claim, and then deploy a MySQL container that uses the claim as its persistent store. Once the database pod is deployed, we need to install the MySQL client, then connect to the pod and create an example database to ensure that the database server is operating correctly.

Logging In

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

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!