Kubernetes:我怎么知道我在哪个节点上? [英] Kubernetes: How do I know what node I'm on?

查看:181
本文介绍了Kubernetes:我怎么知道我在哪个节点上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我进入Kubernetes节点,如何确定该节点的UUID,以便可以查询主API特定于该节点的信息?

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?

到目前为止已经尝试过

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

推荐答案

有很多与kubernetes节点相关的不同ID和名称,这取决于您要查找的内容.如果要查询API服务器以获取节点信息,则最有可能寻找节点名称.节点名称通常与主机名相同,但如果不是最简单的查找方法,则是查询kubelet以获取正在运行的Pod,并查看它们在哪个节点上运行:

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"

其他ID可以通过查询节点规范来找到:

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

最后,可以从API服务器查询externalIDproviderID:

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

如果以上操作均失败,并且您可以访问api服务器,则只需查找与所需节点的主机名匹配的节点即可.

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"

这篇关于Kubernetes:我怎么知道我在哪个节点上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆