diff --git a/deploy/charts/mysql-operator/templates/statefulset.yaml b/deploy/charts/mysql-operator/templates/statefulset.yaml index 2ff2e4c05..123c3d828 100644 --- a/deploy/charts/mysql-operator/templates/statefulset.yaml +++ b/deploy/charts/mysql-operator/templates/statefulset.yaml @@ -156,9 +156,19 @@ spec: nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.affinity }} + {{- if gt (int .Values.replicaCount) 1 }} affinity: - {{- toYaml . | nindent 8 }} + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 1 + podAffinityTerm: + labelSelector: + matchLabels: + {{ include "mysql-operator.selectorLabels" . | nindent 20 }} + topologyKey: kubernetes.io/hostname + {{- else if .Values.affinity }} + affinity: + {{- toYaml .Values.affinity | nindent 8 }} {{- end }} {{- with .Values.tolerations }} tolerations: