I am trying to get the name of the master (control-plane) node in my Kubernetes cluster using kubectl
. I want the command to return only the name of the node without any additional information.
I have tried the following command:
kubectl get nodes --selector=node-role.kubernetes.io/master
However, this returns a table with additional details. I would like to extract only the node name.
What is the correct kubectl
command to achieve this?
I am trying to get the name of the master (control-plane) node in my Kubernetes cluster using kubectl
. I want the command to return only the name of the node without any additional information.
I have tried the following command:
kubectl get nodes --selector=node-role.kubernetes.io/master
However, this returns a table with additional details. I would like to extract only the node name.
What is the correct kubectl
command to achieve this?
1 Answer
Reset to default 0With kubernetes-v1.31.0
, this works:
kubectl get nodes --selector=node-role.kubernetes.io/master= --output=jsonpath='{.items[0].metadata.name}'