Skip to content

Cinder Volumes

Cinder Volumes

Warning

This documentation is deprecated, please check here for its new home

This tutorial explains how to mount cinder volumes in containers in Magnum.

For all examples we'll use a previously created volume on OpenStack:

$ openstack volume create --size 2 myvolume

$ openstack volume show myvolume | grep '| id'
| id | 242de616-95a0-4bd7-9bfa-166022509788 |

We'll require the ID of the volume later.

Additional documentation is available in the upstream Magnum guide.

Docker Swarm

We rely on a docker volume driver called rexray for integration in Docker Swarm.

Simply pass rexray as volume driver and the ID of the volume.

$ docker run -it --volume-driver rexray -v 242de616-95a0-4bd7-9bfa-166022509788:/mydata

Kubernetes

Below is an example of a kubernetes application definition.

You can either refer to an existing cinder volume (via its ID):

$ cat nginx-cinder.yaml
apiVersion: v1
kind: Pod
metadata:
  name: web
spec:
  containers:
    - name: web
      image: nginx
      ports:
        - name: web
          containerPort: 80
          hostPort: 8081
          protocol: TCP
      volumeMounts:
        - name: myvolume
          mountPath: "/usr/share/nginx/html"
  volumes:
    - name: myvolume
      cinder:
        # Enter the volume ID below
        volumeID: 242de616-95a0-4bd7-9bfa-166022509788
        fsType: ext4

$ kubectl create -f nginx-cinder.yaml

Or alternatively, rely on dynamic volume provisioning by defining a volume claim.

You can defined multiple StorageClass objects mapping Cinder volume types, as defined here.

In this example we define two StorageClass objects (standard and io1), and create a volume claim for a standard volume of 1GB.

$ cat nginx-cinder.yaml

kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: standard
provisioner: kubernetes.io/cinder
parameters:
  type: standard
---
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
  name: io1
provisioner: kubernetes.io/cinder
parameters:
  type: io1
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
  annotations:
    volume.beta.kubernetes.io/storage-class: standard
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi # pass here the size of the volume
---
apiVersion: v1
kind: Pod
metadata:
  name: web
spec:
  containers:
    - name: web
      image: nginx
      ports:
        - name: web
          containerPort: 80
          hostPort: 8081
          protocol: TCP
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: mypd
  volumes:
    - name: mypd
      persistentVolumeClaim:
        claimName: myclaim

$ kubectl create -f nginx-cinder.yaml
$ kubectl get pvc
NAME      STATUS    VOLUME                                     CAPACITY   ACCESSMODES   AGE
myclaim   Bound     pvc-e93fc7ad-1ae2-11e7-a49c-02163e018bf2   1Gi        RWO           4s

$ kubectl get pv
NAME                                       CAPACITY   ACCESSMODES   STATUS     CLAIM             REASON    AGE
pvc-e93fc7ad-1ae2-11e7-a49c-02163e018bf2   1Gi        RWO           Bound      default/myclaim             7m

In this case a new cinder volume will be created and attached to the web pod.

Full documentation on storage classes, persistent volume and claims is available here.


Last update: June 1, 2022