# Find out the node role, am I running on control plane or worker node

**URL:** <https://discuss.kubernetes.io/t/find-out-the-node-role-am-i-running-on-control-plane-or-worker-node/29280>\
**Category:** General Discussions\
**Tags:** development\
**Created:** [August 4, 2024, 6:52pm UTC](https://discuss.kubernetes.io/t/find-out-the-node-role-am-i-running-on-control-plane-or-worker-node/29280 "2024-08-04T18:52:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramu\_Mangalarapu](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/ramu_mangalarapu/32/15514_2.png) [@Ramu\_Mangalarapu](https://discuss.kubernetes.io/u/Ramu_Mangalarapu)\
**Post date:** [August 4, 2024, 6:52pm UTC](https://discuss.kubernetes.io/t/find-out-the-node-role-am-i-running-on-control-plane-or-worker-node/29280/1 "2024-08-04T18:52:29Z")

</div>

### Cluster information:

Kubernetes version: 1.28  
Cloud being used: (put bare-metal, KVM)  
Installation method: kubeadm  
Host OS: Ubuntu 22.04.3 LTS  
CNI and version: using an image: [docker.io/calico/cni:v3.26.4](http://docker.io/calico/cni:v3.26.4)  
CRI and version: containerd://1.7.9

Hi everyone,

I need help identifying if a pod is running on a control plane node or a worker node programmatically using the Kubernetes API.

I have a program written in Go that runs on all cluster nodes(including the control plane).  
The program must perform different actions based on whether it runs on a control plane or worker node.  
I’m using the Kubernetes client-go library. For control plane nodes, I’ve seen that different Kubernetes distributions use different labels (e.g., `node-role.kubernetes.io/master`, `node-role.kubernetes.io/control-plane`, `node.kubernetes.io/microk8s-controlplane`).

However, not all distributions consistently use these labels. I’ve also considered checking for control plane-specific taints; some distributions do not have taints.

Reference link of distributions: [Certified Kubernetes Software Conformance | CNCF](https://www.cncf.io/training/certification/software-conformance/)

Is there any API in the K8s API server that I can use to find out if my code is running on the control plane or worker node?

Thank you.

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [August 5, 2024, 6:57pm UTC](https://discuss.kubernetes.io/t/find-out-the-node-role-am-i-running-on-control-plane-or-worker-node/29280/2 "2024-08-05T18:57:17Z")

</div>

You probably should be using pod affinity to control what goes where deterministically and have different workloads configured for these different tasks you’re describing.

> **[Assigning Pods to Nodes](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity)**
>
> You can constrain a Pod so that it is restricted to run on particular node(s), or to prefer to run on particular nodes. There are several ways to do this and the recommended approaches all use label selectors to facilitate the selection. Often, you...
