In this post I will share how to use the Portworx Container Storage Interface (CSI) with the Oracle Container Engine for Kubernetes, more commonly known as Oracle Kubernetes Engine (OKE) to Create, Snapshot, Clone, Resize, Restore and Delete Kubernetes Persistent Volume Claims (PVCs)
Create a StorageClass (SC)
Let’s start by creating a new Portworx Storage Class to protect data by replicating data across three Oracle Cloud Infrastructure (OCI) Availability Domains (ADs) in my local Region and also enable volume expansion, using the below.
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: px-ora-csi
provisioner: pxd.portworx.com
parameters:
repl: "3"
io_profile: "db"
priority_io: "high"
allowVolumeExpansion: True
% kubectl describe sc/px-ora-csi Name: px-ora-csi IsDefaultClass: No Annotations: kubectl.kubernetes.io/last-applied-configuration={"allowVolumeExpansion":true,"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{},"name":"px-ora-csi"},"parameters":{"io_profile":"db","priority_io":"high","repl":"3"},"provisioner":"pxd.portworx.com"} Provisioner: pxd.portworx.com Parameters: io_profile=db,priority_io=high,repl=3 AllowVolumeExpansion: True MountOptions: <none> ReclaimPolicy: Delete VolumeBindingMode: Immediate Events: <none>
Create a Persistent Volume Claim (PVC)
Using the Kubernetes px-ora-csi Portworx Storage Class we can now create a PVC, the code below will create a 2GB Read Write Once volume called px-csi-pvc.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: px-csi-pvc
spec:
storageClassName: px-ora-csi
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
% kubectl get pvc -o wide NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE px-csi-pvc Bound pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31 2Gi RWO px-ora-csi 12s Filesystem
Using pxctl v l -v we can see the Portworx volume and confirm the HA as a value of three.
% pxctl v l -v Defaulted container "portworx" out of: portworx, csi-node-driver-registrar ID NAME SIZE HA SHARED ENCRYPTED PROXY-VOLUME IO_PRIORITY STATUS SNAP-ENABLED 1038744805908792656 pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31 2 GiB 3 no no no MEDIUM up - detached no
Create PVC Snapshot
Using the below we can perform a snapshot of PVC px-csi-pvc and call it px-csi-snapshot.
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: px-csi-snapshot
spec:
volumeSnapshotClassName: px-csi-snapclass
source:
persistentVolumeClaimName: px-csi-pvc
% kubectl get volumesnapshot,volumesnapshotdatas NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE volumesnapshot.snapshot.storage.k8s.io/px-csi-snapshot false px-csi-pvc px-csi-snapclass snapcontent-2adaf6bc-21f2-4927-ac85-3db50722b2a8 3s
Again using pxctl v l, but this time with -s we can limit output to snapshots.
% pxctl v l -s Defaulted container "portworx" out of: portworx, csi-node-driver-registrar ID NAME SIZE HA SHARED ENCRYPTED PROXY-VOLUME IO_PRIORITY STATUS SNAP-ENABLED 1164254571127115 snapshot-2adaf6bc-21f2-4927-ac85-3db50722b2a8 2 GiB 3 no no no MEDIUM up - detached no
Create PVC Clone
We can easily create a thin PVC clone using the Portworx CSI, for example
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: clone-of-px-csi-pvc
spec:
storageClassName: px-ora-csi
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
dataSource:
kind: PersistentVolumeClaim
name: px-csi-pvc
Apply the above, and then use get kubectl get pvc to see the newly created clone.
% kubectl get pvc -o wide NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE clone-of-px-csi-pvc Bound pvc-e73ca8c4-640b-41d9-898a-b58d43c92993 2Gi RWO px-ora-csi 20s Filesystem px-csi-pvc Bound pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31 2Gi RWO px-ora-csi 51m Filesystem
Using pxctl v l again, but this time with -v we can limit output to volumes.
% pxctl v l -v Defaulted container "portworx" out of: portworx, csi-node-driver-registrar ID NAME SIZE HA SHARED ENCRYPTED PROXY-VOLUME IO_PRIORITY STATUS SNAP-ENABLED 1038744805908792656 pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31 2 GiB 3 no no no MEDIUM up - detached no 1113587129248929594 pvc-e73ca8c4-640b-41d9-898a-b58d43c92993 2 GiB 3 no no no MEDIUM up - detached no
Resize PVC
As we set the StorageClass AllowVolumeExpansion to True we can dynamically resize volumes, using kubectl edit, for example kubectl edit pvc/px-csi-pvc and update the storage spec.
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"PersistentVolumeClaim","metadata":{"annotations":{},"name":"px-csi-pvc","namespace":"default"},"spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"2Gi"}},"storageClassName":"px-ora-csi"}}
pv.kubernetes.io/bind-completed: "yes"
pv.kubernetes.io/bound-by-controller: "yes"
volume.beta.kubernetes.io/storage-provisioner: pxd.portworx.com
creationTimestamp: "2022-06-14T11:57:24Z"
finalizers:
- kubernetes.io/pvc-protection
- provisioner.storage.kubernetes.io/cloning-protection
name: px-csi-pvc
namespace: default
resourceVersion: "13770681"
uid: c4b9724a-42dc-41ae-a7c0-24852355ac31
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: px-ora-csi
volumeMode: Filesystem
volumeName: pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 2Gi
phase: Bound
Use get kubectl get pvc to see the expanded volume.
% kubectl get pvc -o wide NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE clone-of-px-csi-pvc Bound pvc-e73ca8c4-640b-41d9-898a-b58d43c92993 2Gi RWO px-ora-csi 19m Filesystem px-csi-pvc Bound pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31 10Gi RWO px-ora-csi 70m Filesystem
Using pxctl v l again, but this time with -v to limit output to volumes.
% pxctl v l -v Defaulted container "portworx" out of: portworx, csi-node-driver-registrar ID NAME SIZE HA SHARED ENCRYPTED PROXY-VOLUME IO_PRIORITY STATUS SNAP-ENABLED 1038744805908792656 pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31 10 GiB 3 no no no MEDIUM up - detached no 1113587129248929594 pvc-e73ca8c4-640b-41d9-898a-b58d43c92993 2 GiB 3 no no no MEDIUM up - detached no
Restore PVC
From our Kubernetes cluster use kubectl apply to restore the a PVC from a Snapshot, for example.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: px-csi-pvc-restored
spec:
storageClassName: px-ora-csi
dataSource:
name: px-csi-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
Use get kubectl get pvc to see the restored volume.
% kubectl get pvc -o wide NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE VOLUMEMODE clone-of-px-csi-pvc Bound pvc-e73ca8c4-640b-41d9-898a-b58d43c92993 2Gi RWO px-ora-csi 45m Filesystem px-csi-pvc Bound pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31 10Gi RWO px-ora-csi 95m Filesystem px-csi-pvc-restored Bound pvc-4f62a250-c860-49b9-8db4-c75bfbf09287 2Gi RWO px-ora-csi 24s Filesystem
Using pxctl v l with -v to limit output to volumes.
% pxctl v l -v Defaulted container "portworx" out of: portworx, csi-node-driver-registrar ID NAME SIZE HA SHARED ENCRYPTED PROXY-VOLUME IO_PRIORITY STATUS SNAP-ENABLED 387219043213102983 pvc-4f62a250-c860-49b9-8db4-c75bfbf09287 2 GiB 3 no no no MEDIUM up - detached no 1038744805908792656 pvc-c4b9724a-42dc-41ae-a7c0-24852355ac31 10 GiB 3 no no no MEDIUM up - detached no 1113587129248929594 pvc-e73ca8c4-640b-41d9-898a-b58d43c92993 2 GiB 3 no no no MEDIUM up - detached no
Delete PVC
To delete a PVC just perform a kubectl delete pvc, for example kubectl delete pvc/px-csi-pvc
% kubectl delete pvc/px-csi-pvc persistentvolumeclaim "px-csi-pvc" deleted
Summary
In this post I shared how we can use the Portworx CSI driver to Create, Snapshot, Clone, Resize, Restore and Delete Persistent Volume Claims on the Oracle Cloud Infrastructure (OCI) Oracle Kubernetes Engine (OKE)
In my next post I will share how to use Stork to perform GroupSnapshots and Restores.