From 258b3ad2533874a4a1b23bdc4b86f3d28bc1cbe6 Mon Sep 17 00:00:00 2001 From: Petrus Repo Date: Fri, 7 Aug 2026 10:52:18 +0300 Subject: [PATCH] fix: Spread CNPG instances across distinct nodes The three CNPG clusters hardcoded anti-affinity on topology.kubernetes.io/zone. Single-zone clusters have one value for that key, and many nodes carry no zone label at all, so the spread was a no-op and instances co-scheduled onto one node. Spread on kubernetes.io/hostname instead, which every node has, and expose podAntiAffinityType and topologyKey as values. The default "preferred" keeps small and single-node clusters working, since instances co-schedule rather than sit Pending when nodes run out. keycloak-config runs a single instance, so this is a no-op there today and matters only if its instance count is ever raised. --- .../eai-infra/airm-cnpg/0.1.0/templates/cnpg-cluster.yaml | 3 ++- sources/eai-infra/airm-cnpg/0.1.0/values.yaml | 6 ++++++ .../eai-infra/aiwb-cnpg/0.1.0/templates/cnpg-cluster.yaml | 3 ++- sources/eai-infra/aiwb-cnpg/0.1.0/values.yaml | 6 ++++++ sources/keycloak-config/templates/keycloak-cluster.yaml | 3 ++- sources/keycloak-config/values.yaml | 6 ++++++ 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sources/eai-infra/airm-cnpg/0.1.0/templates/cnpg-cluster.yaml b/sources/eai-infra/airm-cnpg/0.1.0/templates/cnpg-cluster.yaml index 539a08d5..b049a061 100644 --- a/sources/eai-infra/airm-cnpg/0.1.0/templates/cnpg-cluster.yaml +++ b/sources/eai-infra/airm-cnpg/0.1.0/templates/cnpg-cluster.yaml @@ -11,7 +11,8 @@ metadata: spec: affinity: enablePodAntiAffinity: true - topologyKey: topology.kubernetes.io/zone + podAntiAffinityType: {{ .Values.podAntiAffinityType | quote }} + topologyKey: {{ .Values.topologyKey | quote }} bootstrap: initdb: database: {{ .Values.database }} diff --git a/sources/eai-infra/airm-cnpg/0.1.0/values.yaml b/sources/eai-infra/airm-cnpg/0.1.0/values.yaml index 2e452863..f236fecc 100644 --- a/sources/eai-infra/airm-cnpg/0.1.0/values.yaml +++ b/sources/eai-infra/airm-cnpg/0.1.0/values.yaml @@ -7,6 +7,12 @@ database: "airm" username: "airm_user" image: "ghcr.io/cloudnative-pg/postgresql:17.2" instances: 1 +# Spread instances across distinct nodes. "preferred" schedules them apart when +# nodes allow it and falls back to co-scheduling otherwise, so a cluster with +# fewer nodes than instances still comes up. Set "required" to make the spread +# binding, which leaves surplus instances Pending until nodes are added. +podAntiAffinityType: "preferred" +topologyKey: "kubernetes.io/hostname" userSecretName: "airm-cnpg-user" superuserSecretName: "airm-cnpg-superuser" sharedBuffers: "256MB" diff --git a/sources/eai-infra/aiwb-cnpg/0.1.0/templates/cnpg-cluster.yaml b/sources/eai-infra/aiwb-cnpg/0.1.0/templates/cnpg-cluster.yaml index 539a08d5..b049a061 100644 --- a/sources/eai-infra/aiwb-cnpg/0.1.0/templates/cnpg-cluster.yaml +++ b/sources/eai-infra/aiwb-cnpg/0.1.0/templates/cnpg-cluster.yaml @@ -11,7 +11,8 @@ metadata: spec: affinity: enablePodAntiAffinity: true - topologyKey: topology.kubernetes.io/zone + podAntiAffinityType: {{ .Values.podAntiAffinityType | quote }} + topologyKey: {{ .Values.topologyKey | quote }} bootstrap: initdb: database: {{ .Values.database }} diff --git a/sources/eai-infra/aiwb-cnpg/0.1.0/values.yaml b/sources/eai-infra/aiwb-cnpg/0.1.0/values.yaml index a6e4fccf..119bac20 100644 --- a/sources/eai-infra/aiwb-cnpg/0.1.0/values.yaml +++ b/sources/eai-infra/aiwb-cnpg/0.1.0/values.yaml @@ -7,6 +7,12 @@ database: "aiwb" username: "aiwb_user" image: "ghcr.io/cloudnative-pg/postgresql:17.2" instances: 3 +# Spread instances across distinct nodes. "preferred" schedules them apart when +# nodes allow it and falls back to co-scheduling otherwise, so a cluster with +# fewer nodes than instances still comes up. Set "required" to make the spread +# binding, which leaves surplus instances Pending until nodes are added. +podAntiAffinityType: "preferred" +topologyKey: "kubernetes.io/hostname" userSecretName: "aiwb-cnpg-user" superuserSecretName: "aiwb-cnpg-superuser" sharedBuffers: "256MB" diff --git a/sources/keycloak-config/templates/keycloak-cluster.yaml b/sources/keycloak-config/templates/keycloak-cluster.yaml index 128e766d..a794a406 100644 --- a/sources/keycloak-config/templates/keycloak-cluster.yaml +++ b/sources/keycloak-config/templates/keycloak-cluster.yaml @@ -66,7 +66,8 @@ metadata: spec: affinity: enablePodAntiAffinity: true - topologyKey: topology.kubernetes.io/zone + podAntiAffinityType: {{ .Values.cnpg.podAntiAffinityType | quote }} + topologyKey: {{ .Values.cnpg.topologyKey | quote }} bootstrap: initdb: database: keycloak diff --git a/sources/keycloak-config/values.yaml b/sources/keycloak-config/values.yaml index 8f577f31..ca2df535 100644 --- a/sources/keycloak-config/values.yaml +++ b/sources/keycloak-config/values.yaml @@ -9,3 +9,9 @@ cnpg: # so node maintenance stalls until someone disables it by hand. # Set true or false to override. enablePDB: null + # Spread instances across distinct nodes. "preferred" schedules them apart + # when nodes allow it and falls back to co-scheduling otherwise, so a cluster + # with fewer nodes than instances still comes up. Set "required" to make the + # spread binding, which leaves surplus instances Pending until nodes exist. + podAntiAffinityType: "preferred" + topologyKey: "kubernetes.io/hostname"