Volume Placement Strategies in OKE
When you provision volumes, Portworx places them throughout the cluster and across configured failure domains to provide fault tolerance. While this default manner of operation works well in many scenarios, you may wish to control how Portworx handles volume and replica provisioning more explicitly. You can do this by creating VolumePlacementStrategy CRDs.
Within a VolumePlacementStrategy CRD, you can specify a series of rules which control volume and volume replica provisioning on nodes and pools in the cluster based on the labels they have.
Understand the VolumePlacementStrategy spec
You can define your VolumePlacementStrategy by creating a spec containing affinity rule sections. Affinity rules instruct Portworx on where to place volumes and volume replicas within your cluster and come in two flavors: affinity and antiaffinity.
replicaAffinity
The replicaAffinity
section allows you to specify rules relating replicas within a volume. You can use these rules to place replicas of a volume on nodes or pools which match the specified labels in the rule. You can constrain the replicas to be allocated in a certain failure domain by specifying the topology key used to define the failure domain.
replicaAntiAffinity
The replicaAntiAffinity
section allows you to specify a dissociation rule for replicas within a volume. You can use this to allocate replicas across failure domains by specifying the topology key of the failure domain.
volumeAffinity
The volumeAffinity
section allows you to colocate volumes by specifying rules that place replicas of a volume together with those of another volume for which the specified labels match.
volumeAntiAffinity
The volumeAntiAffinity
section allows you to specify dissociation rules between 2 or more volumes that match the given labels. Use this when you want to exclude failure domains, nodes or storage pools that match the given labels for one or more volumes.
For more information on specific rules, see the following sections of the CRD reference guide:
Example
apiVersion: portworx.io/v1beta2
kind: VolumePlacementStrategy
metadata:
name: <your_strategy_name>
spec:
replicaAffinity: <1>
matchExpressions: <2>
key: media_type <3>
operator: In <4>
values:
- "SSD" <5>
The example above instructs Portworx to perform the following:
replicaAffinity
directs Portworx to create replicas under the preferred conditions defined beneath itmatchExpressions
is a list of label selector requirements and the requirements are ANDed.key
specifies themedia_type
label, directing Portworx to create replicas on pools which have the "media_type" labeloperator
specifies theIn
operator, directing Portworx to create replicas in the media typevalues
specifies theSSD
label, directing Portworx to create replicas on SSD pools