Volume lifecycle basics in Rancher
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
px-csi-dbStorageClass:kind: PersistentVolumeClaimapiVersion: v1metadata:name: px-mysql-pvcspec:storageClassName: px-csi-dbaccessModes:- ReadWriteOnceresources: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/v1kind: Deploymentmetadata:name: mysqlspec:selector:matchLabels:app: mysqlstrategy:rollingUpdate:maxSurge: 1maxUnavailable: 1type: RollingUpdatereplicas: 1template:metadata:labels:app: mysqlversion: "1"spec:containers:- image: mysql:5.6name: mysqlenv:- name: MYSQL_ROOT_PASSWORDvalue: passwordports:- containerPort: 3306volumeMounts:- name: mysql-persistent-storagemountPath: /var/lib/mysqlvolumes:- name: mysql-persistent-storagepersistentVolumeClaim: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
shared-pvc.yamlfile:kind: PersistentVolumeClaimapiVersion: v1metadata:name: px-mysql-pvcspec:storageClassName: px-csi-dbaccessModes:- ReadWriteManyresources:requests:storage: 2Gi
-
Apply the
shared-pvc.yamlfile: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
dataSourcewith thekindandnameof the target PVC you wish to clone. The following spec creates a clone of thepx-mysql-pvcPVC in a YAML file namedclonePVC.yaml:kind: PersistentVolumeClaimapiVersion: v1metadata:name: clone-of-px-mysql-pvcspec:storageClassName: px-csi-dbaccessModes:- ReadWriteOnceresources:requests:storage: 2GidataSource:kind: PersistentVolumeClaimname: px-mysql-pvc
-
Apply the
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.