Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow custom podAffinity and podAntiAffinity rules on postgres pods #2811

Open
sourcehawk opened this issue Dec 5, 2024 · 0 comments

Comments

@sourcehawk
Copy link

sourcehawk commented Dec 5, 2024

Feature request

This feature request involves enabling advanced pod scheduling capabilities through the following

  • Enabling custom podAffinity rules on postgres pods
  • Enabling custom podAntiAffinity rules on postgres pods

Problem description

Currently the postgresql crd only allows specifying the anti affinity topology constraint for scheduling the postgres pods to specific nodes. Due to this limitation it is not possible to further configure affinity and anti affinity rules for these pods.

These are important features for many use cases where pods should be scheduled according to further constraints. An example of such a case would be to select nodes according to selected resource allocation strategies defined by labels, such as using a dedicated node for a postrges instance (without resource allocation constraints) vs a node where postgres instances can share resources with other pods according to resource requests and limits.

A postgres instance schedulable to a dedicated instance:

spec:
  # Allows the pod to be scheduled on a node with specified taint 
  # The taint being 'cluster-resource-strategy=dedicated:NoSchedule'
  tolerations:
    - key: cluster-resource-strategy
      operator: Equal
      value: dedicated
      effect: NoSchedule
  affinity:
   # Ensures that the pod is scheduled on a node with the same resource strategy
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: cluster-resource-strategy
                operator: In
                values:
                  - dedicated
    # Prevents other pods with the same 'dedicated' label from being scheduled
    # effectively making it a "dedicated" node
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchLabels:
              cluster-resource-strategy: dedicated
          topologyKey: kubernetes.io/hostname # Default in current postgresql deployment

A postgres instance schedulable to shared nodes:

affinity:
  # Ensures that the pod is scheduled on a node with the same resource strategy
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
        - matchExpressions:
            - key: cluster-resource-strategy
              operator: In
              values:
                - shared

Additional information

  • Which image of the operator are you using?

    ghcr.io/zalando/spilo-16:3.3-p1

  • Where do you run it - cloud or metal? Kubernetes or OpenShift?

    anywhere

  • Are you running Postgres Operator in production?

    yes

  • Type of issue?

    Feature request

@sourcehawk sourcehawk changed the title Feature: Allow custom podAffinity and podAntiAffinity rules on postgres pods Feature: Allow custom podAffinity, podAntiAffinity and toleration rules on postgres pods Dec 5, 2024
@sourcehawk sourcehawk changed the title Feature: Allow custom podAffinity, podAntiAffinity and toleration rules on postgres pods Feature: Allow custom podAffinity and podAntiAffinity rules on postgres pods Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant