This guide provides step by step instructions for configuring Portworx storage as a backend for persistent volumes created on your Kubernetes cluster.
This tutorial will use a Platform9 Managed Kubernetes Free Tier cluster, however you can use this tutorial to configure Portworx storage on any other Kubernetes cluster of your choice.
Once Portworx installation is running you need to create a storage class with the fowling configuration, this can be applied via the Platform9 UI using the Storage Class dashboards.
xxxxxxxxxx
kind StorageClass
apiVersion storage.k8s.io/v1
metadata
name portworx-csi-sc
provisioner pxd.portworx.com
parameters
repl"1"
Next, enter the details for the storage class.
Finally, review the configuration, ensure it matches the example below including the replication parameter at the bottom of the YAML spec. Once the YAML is correct click Complete and Platform9 will create the storage class.
xxxxxxxxxx
kind StorageClass
apiVersion storage.k8s.io/v1
metadata
name portworx-csi-sc
provisioner pxd.portworx.com
parameters
repl"1"
You Portworx storage class is now created and should be listed under the Storage Classes tab.
You can test the CSI based storage class by creating a Kubernetes Persistent Volume Claim (PVC) with the following YAML spec and applying it to your cluster. Copy the YAML to a file locally and use kubectl to add the PVC. Ensure the StorageClassName matches the storage class that you created above
xxxxxxxxxx
kind PersistentVolumeClaim
apiVersion v1
metadata
name px-mysql-pvc
spec
storageClassName portworx-csi-sc
accessModes
ReadWriteOnce
resources
requests
storage 2Gi
Create the PVC from the YAML file with the command below:
xxxxxxxxxx
kubectl apply -f pvc-test-portworx.yaml
xxxxxxxxxx
persistentvolumeclaim/px-mysql-pvc created
To view the state of the PVC run
xxxxxxxxxx
kubectl get pvc px-mysql-pvc
xxxxxxxxxx
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
px-mysql-pvc Bound pvc-81fae0ac-fda5-43e3-a760-d93359079896 2Gi RWO portworx-csi-sc 8s
The following YAML spec creates an example MySQL application that uses the new PVC.
xxxxxxxxxx
apiVersion apps/v1
kind Deployment
metadata
name mysql
spec
selector
matchLabels
app mysql
strategy
rollingUpdate
maxSurge1
maxUnavailable1
type RollingUpdate
replicas1
template
metadata
labels
app mysql
version"1"
spec
containers
image mysql5.6
name mysql
env
name MYSQL_ROOT_PASSWORD
value password
ports
containerPort3306
volumeMounts
name mysql-persistent-storage
mountPath /var/lib/mysql
volumes
name mysql-persistent-storage
persistentVolumeClaim
claimName px-mysql-pvc
Use Kubectl to apply the spec.
xxxxxxxxxx
kubectl apply -f mysql-example.yaml
Run the following command to view the running deployment:
kubectl get all -n default
NAME READY STATUS RESTARTS AGE
pod/mysql-67f5996b5f-jwctm 1/1 Running 0 3m53s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.21.0.1 <none> 443/TCP 98m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/mysql 1/1 1 1 3m53s
NAME DESIRED CURRENT READY AGE
replicaset.apps/mysql-67f5996b5f 1 1 1 3m53s