Default antiAffinityTopologyKey is not good for high availability
Activity
Show:
Oksana Grishchenko August 20, 2024 at 9:20 AM
The default affinity settings are:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
topologyKey: kubernetes.io/hostname
weight: 1
PG spec: used in
.instances
,.proxy.pgbouncer
PSMDB spec: used in `.replsets`
PXC spec: used in
.pxc
,.haproxy
/.proxysql
(depending on which one is used. for now only.haproxy
is used in Everest).
Examples:
apiVersion: pgv2.percona.com/v2
kind: PerconaPGCluster
...
spec:
...
instances:
- affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
topologyKey: kubernetes.io/hostname
weight: 1
...
proxy:
pgBouncer:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
topologyKey: kubernetes.io/hostname
weight: 1
apiVersion: psmdb.percona.com/v1
kind: PerconaServerMongoDB
...
spec:
...
replsets:
- affinity:
advanced:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
topologyKey: kubernetes.io/hostname
weight: 1
...
apiVersion: pxc.percona.com/v1
kind: PerconaXtraDBCluster
...
spec:
...
haproxy:
affinity:
advanced:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
topologyKey: kubernetes.io/hostname
weight: 1
...
pxc:
affinity:
advanced:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
topologyKey: kubernetes.io/hostname
weight: 1
We set
antiAffinityTopologyKey: none
by default which means that two or more DB pods can run on the same k8s node and if that node goes down the whole DB cluster can go down.For start we could set
antiAffinityTopologyKey: "kubernetes.io/hostname"
which would be a sane default if giving the option to change this would come later.I’m about missing this section from the k8s operators:
affinity: antiAffinityTopologyKey: "kubernetes.io/hostname" # advanced: # nodeAffinity: # requiredDuringSchedulingIgnoredDuringExecution: # nodeSelectorTerms: # - matchExpressions: # - key: kubernetes.io/e2e-az-name # operator: In # values: # - e2e-az1 # - e2e-az2