Create and use VolumePlacementStrategies in Rancher
Create your VolumePlacementStrategy along with your other storage resources:
Prerequisites
- Portworx version: 2.1.2 and above
Construct a VolumePlacementStrategy spec
-
Create a YAML file containing the following common fields. All VolumePlacementStrategy CRDs use these fields:
apiVersionasportworx.io/v1beta2kindasVolumePlacementStrategymetadata.namewith the name of your strategy
Add any of the following affinity or antiaffinity sections to the spec:
This example adds a volumeAffinity rule to colocate Postgres volumes for performance:
apiVersion: portworx.io/v1beta2kind: VolumePlacementStrategymetadata:name: postgres-volume-affinityspec:volumeAffinity:- matchExpressions:- key: appoperator: Invalues:- postgres -
Save and apply your spec with the
kubectl applycommand:kubectl apply -f yourVolumePlacementStrategy.yaml
Create other storage specs
Use a StorageClass
You can associate your VolumePlacementStrategy with a StorageClass and then reference that StorageClass in your PVC.
-
Create a StorageClass that references the VolumePlacementStrategy you created in the Construct a VolumePlacementStrategy spec steps above by specifying the
placement_strategyparameter with the name of your VolumePlacementStrategy:apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:name: postgres-storage-classprovisioner: pxd.portworx.comparameters:placement_strategy: "postgres-volume-affinity" -
Save and apply your StorageClass with the
kubectl applycommand:kubectl apply -f yourVolumePlacementStrategy.yaml -
Create a PVC which references the StorageClass you created above, specifying the
storageClasskind: PersistentVolumeClaimapiVersion: v1metadata:name: postgres-pvcspec:storageClassName: postgres-storage-classaccessModes:- ReadWriteOnceresources:requests:storage: 2Gi -
Save and apply your PVC with the
kubectl applycommand:kubectl apply -f yourPVC.yaml
Reference a VolumePlacementStrategy directly in a PVC
You can reference your VolumePlacementStrategy directly in your PVC using an annotation.
-
Create a PVC which references the VolumePlacementStrategy you created in the Construct a VolumePlacementStrategy spec steps above by specifying
placement_strategyas an annotation with the name of your VolumePlacementStrategy:kind: PersistentVolumeClaimapiVersion: v1metadata:annotations:placement_strategy: "postgres-volume-affinity"name: postgres-pvcspec:storageClassName: postgres-storage-classaccessModes:- ReadWriteOnceresources:requests:storage: 2Gi -
Save and apply your PVC with the
kubectl applycommand:kubectl apply -f yourPVC.yaml
Once you've applied your volumePlacementStrategy, StorageClass, and PVC, Portworx deploys volumes according to the rules you defined. Portworx also follows VolumePlacementStrategies when it restores volumes.