Volume Lifecycle Basics
Create and use persistent volumes
Create and use volumes with CSI by configuring specs you create for your storage class, PVC, and volumes.
In this example, we are using the
px-csi-db storage class out of the box. Please refer to CSI Enabled Storage Classes for a list of available CSI enabled storage classes offered by Portworx.
Create a PersistentVolumeClaim based on the
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: px-mysql-pvc spec: storageClassName: px-csi-db accessModes: - ReadWriteOnce resources: requests: storage: 2Gi
Create a volume by referencing the PVC you created. This example creates a MySQL deployment referencing the
px-mysql-pvcPVC you created in the previous step:
apiVersion: apps/v1 kind: Deployment metadata: name: mysql spec: selector: matchLabels: app: mysql strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 1 type: RollingUpdate replicas: 1 template: metadata: labels: app: mysql version: "1" spec: containers: - image: mysql:5.6 name: mysql env: - name: MYSQL_ROOT_PASSWORD value: password ports: - containerPort: 3306 volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: px-mysql-pvc
Create sharedv4 CSI-enabled volumes
Create sharedv4 CSI-enabled volumes by performing the following steps.
Create a sharedv4 PVC by creating the following
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: px-mysql-pvc spec: storageClassName: px-csi-db accessModes: - ReadWriteMany resources: requests: storage: 2Gi
kubectl apply -f shared-pvc.yaml
Clone volumes with CSI
You can clone CSI-enabled volumes, duplicating both the volume and content within it.
Create a PVC that references the PVC you wish to clone, specifying the
nameof the target PVC you wish to clone. The following spec creates a clone of the
px-mysql-pvcPVC in a YAML file named
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: clone-of-px-mysql-pvc spec: storageClassName: px-csi-db accessModes: - ReadWriteOnce resources: requests: storage: 2Gi dataSource: kind: PersistentVolumeClaim name: px-mysql-pvc
clonePVC.yamlspec to create the clone:
kubectl apply -f clonePVC.yaml
Migrate to CSI PVCs
Currently, you cannot migrate or convert PVCs created using the native Kubernetes driver to the CSI driver. However, this is not required, and both types of PVCs can co-exist on the same cluster.
Portworx, Inc. welcomes contributions to its CSI implementation, which is open-source with a repository located at OpenStorage. In addition, we also encourage contributions to the Kubernetes-CSI open source implementation.