toper
toper

Reputation: 53

I want to get the host MAC address in kubernetes pod where that pod runing on

I want to get the MAC address of the host in the POD, the POD network doesn't use hostnetwork. I found that the node UID's suffix is the host' MAC address and I want to find the source where this UID value get from?

The suffix of uid (525400a9edd3) is the MAC address(ether 52:54:00:a9:ed:d3) of that host?

kubectl get nodes node1 -o yaml
apiVersion: v1
kind: Node
metadata:
...
  uid: 96557f0f-fea6-11e8-b826-525400a9edd3
...
ifconfig eth0
        eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.68.1  netmask 255.255.0.0  broadcast 172.16.255.255
        inet6 fe80::5054:ff:fea9:edd3  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:a9:ed:d3  txqueuelen 1000  (Ethernet)

Could you help me to find how node uid is created accros the source code?

I want to know the host MAC address in kubernetes pod where that pod runing on.

Upvotes: 5

Views: 7023

Answers (2)

Stryker
Stryker

Reputation: 6130

Pods are likely running within a node.

To get the node MAC address run arp NodeName on your controlplane node:

Start by getting the list of nodes and their names

kubectl get nodes -owide

root@controlplane:~# k get nodes -owide
NAME           STATUS   ROLES                  AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
controlplane   Ready    control-plane,master   35m   v1.20.0   10.4.57.3     <none>        Ubuntu 18.04.5 LTS   5.4.0-1057-gcp   docker://19.3.0
node01         Ready    <none>                 35m   v1.20.0   10.4.57.6     <none>        Ubuntu 18.04.5 LTS   5.4.0-1057-gcp   docker://19.3.0

Run arp NODENAME (on the controlplane) to get the MAC address of the node you want. In this case, we are getting the MAC address for node01.

arp node01

Output

root@controlplane:~# arp node01
Address                  HWtype  HWaddress           Flags Mask            Iface
10.4.57.5                ether   02:42:0a:04:39:04   C                     eth0

Upvotes: 2

Alassane Ndiaye
Alassane Ndiaye

Reputation: 4777

You can look at any of the solutions posted here to see where you can find the MAC address from your filesystem. Then you simply need to mount that file into your container using a hostpath volume, and read the info from there.

Upvotes: 2

Related Questions