How to uniquely identify a Kubernetes node using Kubernetes API and the node operating system?

4/20/2020

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. Identify a unique value for a node in a Kubernetes cluster.
  2. Get the same ID for a node from two different places - The Kubernetes API and from the node itself.

Identifying a node:

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

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.

Getting the same node ID using 2 different methods:

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.

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?

-- yoav hizki
ibm-cloud
iks
kubernetes

1 Answer

4/20/2020

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.

-- coderanger
Source: StackOverflow