If install k8s cluster with 2 masters for HA, are they all work at the same time or only one work?
If use the official way:
https://kubernetes.io/docs/tasks/administer-cluster/highly-available-master/
It depends on the service of Kubernetes Control Plane:
--leader-elect
flag.You can see more details about the --leader-elect
flag here: https://kubernetes.io/docs/reference/generated/kube-controller-manager/
You can also find examples of HA in this guide: https://github.com/kelseyhightower/kubernetes-the-hard-way/blob/master/docs/08-bootstrapping-kubernetes-controllers.md
Disclaimer: I assume that for you, master does include Etcd.
Please do not install 2 masters for HA. Running two nodes is no HA at all :) In fact, a bit counterintuitively maybe, when you run EtcD on two nodes, the probability of experiencing an outage that immobilizes your cluster is two times higher, not lower. Etcd requires a quorum of servers to be active, that usually means that you need 50%+1 nodes to be active for HA to keep the service up. Out of 2 nodes 50%+1 is... well... 2. The minimum reasonable number of nodes in HA for consensus based replication is 3.
In Etcd cluster, all the nodes are active and take part of consensus protocol. API server is a really simple service that can run in parallel in as many places as you want, it is the underlying etcd that takes care of state reconciling. Manager-controller and Scheduler on the other hand contain election logic within them selves (so adding more of them does not increase performance, only the outage resilience)