如何使用Kubernetes API和节点操作系统唯一地标识Kubernetes节点? [英] How to uniquely identify a Kubernetes node using Kubernetes API and the node operating system?

查看:102
本文介绍了如何使用Kubernetes API和节点操作系统唯一地标识Kubernetes节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个在Kubernetes环境中运行的组件.一种是使用Kubernetes API列出集群中的所有节点,另一种是将运行该节点的节点的详细信息报告给第一个.

I have 2 components that run in a Kubernetes environment. One is listing all the nodes in the cluster (using Kubernetes API) and the other is reporting details of the node it runs on to the first one.

我希望我的第一个组件将报告的节点从第二个组件匹配到第一个组件列表中的一个节点.

I want my first component to match the reported node from the second component to a node in the first component's list.

要做到这一点,我需要做两件事:

In order to do that, I need 2 things:

  1. 确定Kubernetes集群中节点的唯一值.
  2. 从两个不同的位置-Kubernetes API和节点本身获取节点的相同ID.

标识节点:

我正在尝试识别Kubernetes节点.但是我仍然无法获得节点的唯一标识符.

I'm trying to identify a Kubernetes node. But I still can't get a unique identifier for a node.

起初,我认为字段机器ID是唯一的,但不是(克隆节点时已复制).然后,我创建了一个由_组成的标识公式.

At first, I thought the field machine-id was unique, but it's not (Copied when cloning node). Then I created an identification formula, consist of _.

该公式不是唯一的,但到目前为止,它已经运行良好.

This formula is not unique but it has been working pretty well for now.

使用2种不同的方法获取相同的节点ID:

使用Kubernetes API以及通过在节点操作系统上运行命令来获取节点的machine_id和主机名非常容易.我面临的问题是,在某些情况下,ID不匹配.特别是,主机名不相同.使用Kubernetes API获取主机名不会返回该节点的真实主机名.我一直在IKS和ICP上遇到这个问题.

It's pretty easy to get a node's machine_id and hostname using the Kubernetes API, and also by running the commands on the node's operating system. The problem I'm facing is that for some cases, the IDs don't match. In particular, the hostname is not identical. Getting the hostname using the Kubernetes API doesn't return the real hostname of the node. I've been facing this issue on IKS and ICP.

是否有一种正常的方法来获取Kubernetes节点的唯一ID?通过在节点上运行命令并使用API​​会返回相同的结果?

Is there a normal way to get a unique ID for the Kubernetes node? One that will return the same result by running the command on the node and using the API?

推荐答案

您将使用节点名称,就像API对象上的名称一样.您可以使用带有字段ref或向下api卷的env var将其传递给DaemonSet进程.

You would use the node name, as in the name on the API object. You can pass it in to the DaemonSet process using an env var with a field ref or a downward api volume.

这篇关于如何使用Kubernetes API和节点操作系统唯一地标识Kubernetes节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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