Is there any shortcut or kubectl command or REST API call to get a list of worker nodes only. ( not including the master nodes )
Update: For the masters we can do like this:
kubectl get nodes --selector=node-role.kubernetes.io/master
for the workers I dont see any such label created by default. Can we do get by reversing or do != kind of thing on selector.
We can't grep it either:
C02W84XMHTD5:ucp iahmad$ kubectl get nodes | grep worker
C02W84XMHTD5:ucp iahmad$
C02W84XMHTD5:ucp iahmad$ kubectl get nodes -o wide| grep worker
C02W84XMHTD5:ucp iahmad$
C02W84XMHTD5:ucp iahmad$ kubectl get nodes -o yaml | grep worker
C02W84XMHTD5:ucp iahmad$
C02W84XMHTD5:ucp iahmad$ kubectl get nodes -o json | grep worker
C02W84XMHTD5:ucp iahmad$
My use case is that want to get this list every minute to update the external load balancer pools, in case new nodes are added, removed from the cluster. Indeed I can label them myself but if there is some default built in way of doing this would be useful
You can get roles/labels of your nodes by
in my case, I do have three nodes each having the given roles and labels:
Only host01 has the label
controlplane, worker
andetcd
. The other two haveetcd
andworker
(Scroll right to see the labels as well).So I can get all worker nodes by
To exclude
controlplane
s, you can exclude them with a second label by!=true
Please adapt that to your labels or set labels accordingly to your cluster. In my case it is a Rancher 2.0 cluster. The labels are automatically created by Rancher when added a node.
The API for that is in Rancher at (with the filter already appended):