Search code examples
kubernetes

Kubernetes: How do I know what node I'm on?


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

Solution

  • 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"