Portworx Enterprise

PX-Backup

Create and use VolumePlacementStrategies


Create your VolumePlacementStrategy along with your other storage resources:

Prerequisities

  • Portworx version: 2.1.2 and above

Construct a VolumePlacementStrategy spec

  1. Create a YAML file containing the following common fields. All VolumePlacementStrategy CRDs use these fields:

    • apiVersion as portworx.io/v1beta2
    • kind as VolumePlacementStrategy
    • metadata.name with 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/v1beta2
      kind: VolumePlacementStrategy
      metadata:
      name: postgres-volume-affinity
      spec:
      volumeAffinity:
        - matchExpressions:
          - key: app
            operator: In
            values:
              - postgres
  2. Save and apply your spec with the kubectl apply command:

      kubectl apply -f yourVolumePlacementStrategy.yaml

Create other storage specs

  1. Create a StorageClass that references the VolumePlacementStrategy you created in the Construct a VolumePlacementStrategy spec steps above by specifying the placement_strategy parameter with the name of your VolumePlacementStrategy:

      apiVersion: storage.k8s.io/v1
      kind: StorageClass
      metadata:
        name: postgres-storage-class
      provisioner: kubernetes.io/portworx-volume
      parameters:
        placement_strategy: "postgres-volume-affinity"
  2. Save and apply your StorageClass with the kubectl apply command:

      kubectl apply -f yourVolumePlacementStrategy.yaml
  3. Create a PVC which references the StorageClass you created above, specifying the storageClass

      kind: PersistentVolumeClaim
      apiVersion: v1
      metadata:
         name: postgres-pvc
      spec:
         storageClassName: postgres-storage-class
         accessModes:
           - ReadWriteOnce
         resources:
           requests:
             storage: 2Gi
  4. Save and apply your PVC with the kubectl apply command:

      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.



Last edited: Wednesday, Jun 10, 2020