Over a million developers have joined DZone.

Adding Persistent Storage to Minishift/CDK 3 in Minutes

DZone's Guide to

Adding Persistent Storage to Minishift/CDK 3 in Minutes

Adding persistent storage to your minishift or CDK 3 project is simple and straightforward. You just need to keep an eye on your VM's available room.

· Cloud Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

Today, I want to show you how to easily setup some persistent storage for your projects in minishift/CDK 3 (Red Hat’s Containers Development Kit 3).


First, let’s start planning what you’ll need:

  • A working minishift or CDK 3.

That’s all, I swear!

I won’t go deep into how to set up a minishift or CDK 3. There are many articles on the Internet to cover this. Still, I’ll recap some useful links below, just to make sure you’ll get a working minishift/CDK3 before proceeding:

Using Red Hat Container Development Kit 3 Beta

And here's the minishift GitHub page – https://github.com/minishift/minishift.

Let’s Start!

Once you’ve successfully set up a working minishift/CDK3, you’re now ready to move forward, creating the underlying storage for your Persistent Volumes (PVs).

First of all, connect to your running minishift/CDK3:

$ minishift ssh
[docker@minishift ~]$ sudo -i
[root@minishift ~]#

Ok, now we’re ready to create our first persistent volume backend directory for hosting Docker Registry files:

[root@minishift ~]# mkdir -p /mnt/sda1/var/lib/minishift/openshift.local.volumes/pv
[root@minishift ~]# mkdir /mnt/sda1/var/lib/minishift/openshift.local.volumes/pv/registry
[root@minishift ~]# chmod 777 -R /mnt/sda1/var/lib/minishift/openshift.local.volumes/pv

Perfect! We can now move to the PersistentVolume creation for our Docker Registry container.

First, log out from your minishift/CDK3 VM and then log into your Openshift via oc-client:

$ oc login -u system:admin
Logged into "" as "system:admin" using existing credentials.

You have access to the following projects and can switch between them with 'oc project <projectname>':

 * myproject

Using project "myproject".

Let’s switch to project “default”:

$ oc project default
Now using project "default" on server "".

Finally, create your first PersistentVolume:

$ cat << PV | oc create -f -
apiVersion: v1
kind: PersistentVolume
 name: registry
  storage: 5Gi
  - ReadWriteOnce
 storageClassName: slow
  path: /mnt/sda1/var/lib/minishift/openshift.local.volumes/pv/registry

Pay attention to two things here:

  1. Storage capacity: It’s not calculated automatically! You should care about disk size and free space.
  2. Usage of Volume type “hostPath”: The storage is on the minishift/CDK3 virtual disk, you should take care of permissions!

Ok, now we’re ready to create our first PersistentVolumeClaim, to be bound with a PersistentVolume resource:

$ cat << PVC | oc create -f -
kind: PersistentVolumeClaim
apiVersion: v1
 name: registryclaim
  - ReadWriteOnce
   storage: 5Gi
 storageClassName: slow
  name: registry

As you can see from the PersistentVolumeClaim definition, we match the PersistentVolume by the name “registry”.

We can now look at the result by checking the output of the following commands:

$ oc get pvc
registryclaim Bound  registry 5Gi      RWO         8s

Finally, we can patch the current registry DeploymentConfig adding the storage we just created:

$ oc volume dc/docker-registry --add --name=registry-storage -t pvc --claim-name=registryclaim --overwrite
deploymentconfig "docker-registry" updated

That’s all! You can repeat these steps as many times as you want! But pay attention to your VM’s free space!

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

cloud ,persistent data ,minishift ,red hat CDK ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}