<p>We are currently using 2 Nodes, but we may need more in the future.</p>
<p>The StatefulSets is a <a href="https://hub.kubeapps.com/charts/bitnami/mariadb-galera" rel="nofollow noreferrer">mariadb-galera</a> is current replica is at 2.</p>
<p>When we'll had a new Nodes we want the replica to be a 3, f we don't need it anymore and we delete it or a other Node we want it to be a 2.</p>
<p>In fact, if we have 3 Nodes we want 3 replica one on each Nodes.</p>
<p>I could use <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/#spread-constraints-for-pods" rel="nofollow noreferrer">Pod Topology Spread Constraints</a> but we'll have a bunch of &quot;notScheduled&quot; pods.</p>
<p>Is there a way to adapt the number of Replica automatically, every time a nodes is add or remove?</p>

<blockquote>
<p>When we'll had a new Nodes we want the replica to be a 3, f we don't need it anymore and we delete it or a other Node we want it to be a 2.</p>
</blockquote>
<p>I would recommend to do it the other way around. Manage the replicas of your <em>container workload</em> and let the number of nodes be adjusted after that.</p>
<p>See e.g. <a href="https://github.com/kubernetes/autoscaler" rel="nofollow noreferrer">Cluster Autoscaler</a> for how this can be done, it depends on what cloud provider or environment your cluster is using.</p>
<p>It is also important to specify your <a href="https://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-resource/" rel="nofollow noreferrer">CPU and Memory requests</a> such that it occupy the whole nodes.</p>
<p>For MariaDB and similar workload, you should use <code>StatefulSet</code> and not <code>DaemonSet</code>.</p>
