kubernetes-retired / contrib

[EOL] This is a place for various components in the Kubernetes ecosystem that aren't part of the Kubernetes core.
Apache License 2.0
2.46k stars 1.68k forks source link

Discussion: Simplify leader election code #3002

Closed micw closed 5 years ago

micw commented 5 years ago

Hello, before I switched to K8S, I was using Rancher 1.x as my private coud platform. They had a very simple leader detection algorith. I'd like to discuss if that would also work for K8S, so that we could maybe simplify the election code a lot (and removing the requirement to have write access to the cluster API).

The algorithm is just:

This works because these serial numbers are always ascending, so if the leader instance terminates, the next instance becomes the leader.

On K8S we could use the resourceVersion which also seems to be strictly ascending. That means after querying a service endpoint, we could directly decide who the leader is.

What do you think about this?