<p>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?</p>

Arjun
<p>In general, the easiest way to check if node is master or worker is to check if it has label <code>node-role.kubernetes.io/control-plane</code> (<a href="https://v1-20.docs.kubernetes.io/docs/setup/release/notes/#urgent-upgrade-notes" rel="noreferrer">or before Kubernetes <code>v1.20</code></a>: <code>node-role.kubernetes.io/master</code>):</p>
<p>Since Kubernetes <code>v1.20</code>:</p>
<pre><code>kubectl get nodes -l 'node-role.kubernetes.io/control-plane'
</code></pre>
<p>Before Kubernetes <code>v1.20</code>:</p>
<pre><code>kubectl get nodes -l 'node-role.kubernetes.io/master'
</code></pre>
<p>To get workers we can use negation for above expressions (since Kubernetes <code>v1.20</code>):</p>
<pre><code>kubectl get nodes -l '!node-role.kubernetes.io/control-plane'
</code></pre>
<p>Before Kubernetes <code>v1.20</code>:</p>
<pre><code>kubectl get nodes -l '!node-role.kubernetes.io/master'
</code></pre>
<p>Another approach is to use command <code>kubectl cluster-info</code> which will print IP address of the <code>control-plane</code>:</p>
<pre><code>Kubernetes control plane is running at https://{ip-address-of-the-control-plane}:8443
</code></pre>
<p>Keep in mind that for some cloud provided solutions it may work totally different. For example, <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture" rel="noreferrer">in GKE, nodes don't have any roles by default and IP address returned by <code>kubectl cluster-info</code> is address of the API Server</a>, not listed in <code>kubectl get nodes</code> command so always remember to double-check docs provided by your Kubernetes cluster provider.</p>
