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
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
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.