that’s where stateful sets come into play. Stateful sets are similar to deployment sets, as in they create PODs
based on a template. But with some differences.
1.
2. With stateful sets, pods are created in a sequential order.
3. After the first pod is deployed, it must be in a running and ready state before the next pod is deployed.
4. So that helps us ensure master is deployed first and then slave 1 and then slave 2.
Stateful sets assign a unique ordinal index to each POD – a number starting from 0 for the first pod and
increments by 1.
5.
6. Each Pod gets a name derived from this index, combined with the stateful set name.
7. So the first pod gets mysql-0, the second pod mysql-1 and third mysql-2.
8. SO no more random names. You can rely on these names going forward.
9. We can designate the pod with the name mysql-0 as the master, and any other pods as slaves.
Pod mysql-2 knows that it has to perform an initial clone of data from the pod mysql-1. If you scale up by
deploying another pod, mysql-3, then it would know that it can perform a clone from mysql-2.
10.
To enable continuous replication, you can now point the slaves to the master at mysql-0. Even if the master
fails, and the pod is recreated is created, it would still come up with the same name.
11.
12. Stateful sets maintain a sticky identity for each of their pods.
13. The master is now always the master and available at the address mysql-0.
14. And that is why you need stateful sets