Adding Persistent Storage to Minishift / CDK 3 in Minutes
Hi there! It’s been a while since I last wrote an article. 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. Anyway I’ll recap some useful links below, just to make sure you’ll get a working minishift/CDK3 before proceeding:
Minishift Github page – https://github.com/minishift/minishift
Everything you need to grow your career.
With your free Red Hat Developer program membership, unlock our library of cheat sheets and ebooks on next-generation application development.SIGN UP
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 in to 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 just created storage:
$ 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!
Alessandro Arrichiello is a Solution Architect for Red Hat Inc. He has a passion for GNU/Linux systems, that began at age 14 and continues today. He worked with tools for automating Enterprise IT: configuration management and continuous integration through virtual platforms. He’s now working on distributed cloud environment involving PaaS (OpenShift), IaaS (OpenStack) and Processes Management (CloudForms), Containers building, instances creation, HA services management, workflows build.
To learn more, visit our Join the Red Hat Developer Program (it’s free) and get access to related cheat sheets (e.g. containers), books (e.g. microservices), and product downloads that can help you with your microservices and/or container application development.
Join the Red Hat Developer Program (it’s free) and get access to related cheat sheets, books, and product downloads.