3

In K8s, every cluster has a set of nodes, some are master and others are worker nodes. How can we know if a node is a master or a worker?

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Arjun
  • 6,501
  • 10
  • 32
  • 34

4 Answers4

5

In general, the easiest way to check if node is master or worker is to check if it has label node-role.kubernetes.io/control-plane (or before Kubernetes v1.20: node-role.kubernetes.io/master):

Since Kubernetes v1.20:

kubectl get nodes -l 'node-role.kubernetes.io/control-plane'

Before Kubernetes v1.20:

kubectl get nodes -l 'node-role.kubernetes.io/master'

To get workers we can use negation for above expressions (since Kubernetes v1.20):

kubectl get nodes -l '!node-role.kubernetes.io/control-plane'

Before Kubernetes v1.20:

kubectl get nodes -l '!node-role.kubernetes.io/master'

Another approach is to use command kubectl cluster-info which will print IP address of the control-plane:

Kubernetes control plane is running at https://{ip-address-of-the-control-plane}:8443

Keep in mind that for some cloud provided solutions it may work totally different. For example, in GKE, nodes don't have any roles by default and IP address returned by kubectl cluster-info is address of the API Server, not listed in kubectl get nodes command so always remember to double-check docs provided by your Kubernetes cluster provider.

Mikolaj S.
  • 2,850
  • 1
  • 5
  • 17
2

If your cluster is part of an EKS cluster, the master node WILL NOT be available/presented as part of the get nodes command noted below

kubectl get nodes

This documentation also has more information

djmonki
  • 3,020
  • 7
  • 18
1

You can use kubectl get nodes to list all nodes. Given by the roles control-plane or master you can identify the node. master will be replaced with control-plane in future releases.

By default all other nodes without a role should be the worker nodes.

Also if you need a bit more information about your nodes you can call kubectl get nodes -o wide.

Manuel
  • 1,928
  • 2
  • 16
  • 26
  • One more thing. Some cloud provider do not show you the master node in a managed environment (i.e. GKE). This depends on provider and setup of the kubernetes cluster. – Manuel Sep 24 '21 at 07:34
1

The node which api-server, kube-controller-management and kube-scheduler running on is the master node.

vincent pli
  • 349
  • 1
  • 6