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.
Join the DZone community and get the full member experience.Join For Free
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:
And here's the minishift GitHub page – https://github.com/minishift/minishift.
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 "https://192.168.42.58:8443" as "system:admin" using existing credentials. You have access to the following projects and can switch between them with 'oc project <projectname>': default kube-system * myproject openshift openshift-infra Using project "myproject".
Let’s switch to project “default”:
$ oc project default Now using project "default" on server "https://192.168.42.69:8443".
Finally, create your first PersistentVolume:
$ cat << PV | oc create -f - apiVersion: v1 kind: PersistentVolume metadata: name: registry spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce storageClassName: slow hostPath: path: /mnt/sda1/var/lib/minishift/openshift.local.volumes/pv/registry PV
Pay attention to two things here:
- Storage capacity: It’s not calculated automatically! You should care about disk size and free space.
- 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 metadata: name: registryclaim spec: accessModes: - ReadWriteOnce resources: requests: storage: 5Gi storageClassName: slow selector: name: registry PVC
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 NAME STATUS VOLUME CAPACITY ACCESSMODES AGE 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!
Published at DZone with permission of Alessandro Arrichiello, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.