Skip to content
logo
Percona Operator for MySQL
Anti-affinity and tolerations
Initializing search
    percona/k8sps-docs
    percona/k8sps-docs
    • Welcome
      • Design and architecture
      • Install with Helm
      • Install on Minikube
      • System Requirements
      • Install on Google Kubernetes Engine (GKE)
      • Install on Amazon Elastic Kubernetes Service (AWS EKS)
      • Generic Kubernetes installation
      • Backup and restore
      • Application and system users
      • Anti-affinity and tolerations
        • Affinity and anti-affinity
          • Simple approach - use topologyKey of the Percona Operator for MySQL
          • Advanced approach - use standard Kubernetes constraints
      • Labels and annotations
      • Changing MySQL Options
      • Exposing the cluster
      • Transport Encryption (TLS/SSL)
      • Telemetry
      • Horizontal and vertical scaling
      • Monitor with Percona Monitoring and Management (PMM)
      • Add sidecar containers
      • Monitor Kubernetes
      • Custom Resource options
      • Percona certified images
      • Copyright and licensing information
      • Trademark policy
      • Release notes index
      • Percona Operator for MySQL 0.5.0 (2023-03-30)
      • Percona Operator for MySQL 0.4.0 (2023-01-30)
      • Percona Operator for MySQL 0.3.0 (2022-09-29)
      • Percona Operator for MySQL 0.2.0 (2022-06-30)
      • Percona Distribution for MySQL Operator based on Percona Server for MySQL 0.1.0 (2022-01-25)

    • Affinity and anti-affinity
      • Simple approach - use topologyKey of the Percona Operator for MySQL
      • Advanced approach - use standard Kubernetes constraints

    Binding Distribution for MySQL components to Specific Kubernetes Nodes¶

    The Operator does good job automatically assigning new Pods to nodes with sufficient to achieve balanced distribution across the cluster. Still there are situations when it worth to ensure that pods will land on specific nodes: for example, to get speed advantages of the SSD equipped machine, or to reduce costs choosing nodes in a same availability zone.

    That’s why mysql section of the deploy/cr.yaml file contain keys which can be used to configure node affinity.

    Affinity and anti-affinity¶

    Affinity makes Pod eligible (or not eligible - so called “anti-affinity”) to be scheduled on the node which already has Pods with specific labels. Particularly this approach is good to to reduce costs making sure several Pods with intensive data exchange will occupy the same availability zone or even the same node - or, on the contrary, to make them land on different nodes or even different availability zones for the high availability and balancing purposes.

    Percona Operator for MySQL provides two approaches for doing this:

    • simple way to set anti-affinity for Pods, built-in into the Operator,

    • more advanced approach based on using standard Kubernetes constraints.

    Simple approach - use topologyKey of the Percona Operator for MySQL¶

    Percona Operator for MySQL provides the antiAffinityTopologyKey option, which may have one of the following values:

    • kubernetes.io/hostname - Pods will avoid residing within the same host,

    • topology.kubernetes.io/zone - Pods will avoid residing within the same zone,

    • topology.kubernetes.io/region - Pods will avoid residing within the same region,

    • none - no constraints are applied.

    The following example forces Percona Server for MySQL Pods to avoid occupying the same node:

    affinity:
      antiAffinityTopologyKey: "kubernetes.io/hostname"
    

    Advanced approach - use standard Kubernetes constraints¶

    Previous way can be used with no special knowledge of the Kubernetes way of assigning Pods to specific nodes. Still in some cases more complex tuning may be needed. In this case advanced option placed in the deploy/cr.yaml file turns off the effect of the topologyKey and allows to use standard Kubernetes affinity constraints of any complexity:

    affinity:
       advanced:
         podAffinity:
           requiredDuringSchedulingIgnoredDuringExecution:
           - labelSelector:
               matchExpressions:
               - key: security
                 operator: In
                 values:
                 - S1
             topologyKey: topology.kubernetes.io/zone
         podAntiAffinity:
           preferredDuringSchedulingIgnoredDuringExecution:
           - weight: 100
             podAffinityTerm:
               labelSelector:
                 matchExpressions:
                 - key: security
                   operator: In
                   values:
                   - S2
               topologyKey: kubernetes.io/hostname
         nodeAffinity:
           requiredDuringSchedulingIgnoredDuringExecution:
             nodeSelectorTerms:
             - matchExpressions:
               - key: kubernetes.io/e2e-az-name
                 operator: In
                 values:
                 - e2e-az1
                 - e2e-az2
           preferredDuringSchedulingIgnoredDuringExecution:
           - weight: 1
             preference:
               matchExpressions:
               - key: another-node-label-key
                 operator: In
                 values:
                 - another-node-label-value
    

    See explanation of the advanced affinity options in Kubernetes documentation.

    Contact Us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: 2023-08-31
    Percona LLC and/or its affiliates, © 2009 - 2023
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better. Read more about Percona Cookie Policy.