If I ssh into a Kubernetes node, how do I figure out the UUID for the node so I can query the master API for information specific to the node?
Tried this so far
root 13020 2.5 1.0 410112 41660 ? Ssl Jan25 26:04 /usr/bin/kubelet --logtostderr=true --v=0 --api_servers=http://10.32.140.181:8080 --address=0.0.0.0 --port=10250 --allow_privileged=false --maximum-dead-containers=1 --max-pods=14
[achang@p3dlwsbkn50d51 ~]$ curl -Gs http://localhost:10255/pods/
404 page not found
There are lots of different IDs and names tied to kubernetes nodes, it depends on which you are looking for. If you want to query the API server for node info, you're most likely looking for the node name. The node name is often the same as the hostname, but if not the easiest way to find it is to query the kubelet for running pods, and see what node they're running on:
$ curl -Gs http://localhost:10255/pods/ | grep -o '"nodeName":"[^"]*"' | head -n 1
"nodeName":"e2e-test-stclair-minion-8o3b"
Other IDs can be found by querying the node spec:
$ curl -Gs http://localhost:10255/spec/ | grep -oE '(machine_|system_uu|boot_)id":.*'
machine_id": "",
system_uuid": "CB7FAAA0-3A53-5FE4-4285-D33D03FEBA6C",
boot_id": "8b89b8f5-5fbb-4cc0-82e4-7c57ec11f656",
Finally, externalID
and providerID
can be queried from the API server:
$ kubectl get nodes e2e-test-stclair-minion-8o3b -o=jsonpath="externalID:{.spec.externalID}; providerID:{.spec.providerID}"
EDIT:
If the above fails and you have access to the api server, you can just look for the node that matches the hostname of the desired node:
$ NODEHOST="your-host"
$ kubectl get nodes | grep "hostname=$NODEHOST"
You can obtain the node name adding wide output option to kubectl :
// List all pods in plain-text output format and includes additional information (such as node name).
$ kubectl get pods -o wide
more options : https://kubernetes.io/docs/user-guide/kubectl-overview/
I found current kubernetes node (I check minikube, gke node pool) has file /etc/machine-id
, which cat /etc/machine-id
is unique for each kubernetes nodes and match with correspond kubectl get nodes -o json | jq -r .items[].status.nodeInfo.machineID
.
because it does not need API invocation, I think this way is easier to combine with shell or container.
kubelet is the entity running in each node and is like the "host agent" with which kube-api-server interacts to get the node specific information and also to do the node specific tasks.
Kubelet has the information about the node name. Typically, the node name is given with "--hostname-override" option when starting the kubelet.
So, the following command would give the node name if --hostname-override is set.
ps -eaf | grep kubelet | tr ' ' '\n' | grep "--hostname-override" | awk -F= ' { print $2 } '
Else, there must be kubelet APIs to give this information, but kubelet APIs are undocumented and hence it is better not to suggest them in stackoverflow