How does Kubernetes assign an IP to fieldPath: status.hostIP on a host with multiple interfaces and IPs

Viewed 727

The title says it all; how does Kubernetes assign an IP to fieldPath: status.hostIP on a host with multiple interfaces and IPs.

If My node has the following IPs

# ip a | grep "inet "
inet 127.0.0.1/8 scope host lo
inet 10.68.48.206/22 brd 10.68.51.255 scope global virbr0
inet 253.255.0.35/24 brd 253.255.0.255 scope global bond0.3900
inet 10.244.2.0/32 scope global flannel.1
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0

Kube picks 10.68.48.206 when I want it to pick 253.255.0.35, so how does it decide?

Is it based off of DNS hostname resolution?

nslookup ca-rain03
Server:     10.68.50.60
Address:    10.68.50.60#53

Or default route?

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.68.48.1      0.0.0.0         UG    0      0        0 virbr0
10.0.0.0        10.68.48.1      255.0.0.0       UG    0      0        0 virbr0
10.68.48.0      0.0.0.0         255.255.252.0   U     0      0        0 virbr0
10.244.0.0      10.244.0.0      255.255.255.0   UG    0      0        0 flannel.1
10.244.1.0      10.244.1.0      255.255.255.0   UG    0      0        0 flannel.1
169.254.0.0     0.0.0.0         255.255.0.0     U     1007   0        0 bond0
169.254.0.0     0.0.0.0         255.255.0.0     U     1045   0        0 bond0.3900
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
253.255.0.0     0.0.0.0         255.255.255.0   U     0      0        0 bond0.3900

Or something else? How can I pass the host IP of 253.255.0.35 into a pod?

Thanks

2 Answers

It's really picked up by the kubelet the configuration. For example, on pretty much all *nix systems it's managed by systemd. So you can see it like this :

systemctl cat kubelet
# Warning: kubelet.service changed on disk, the version systemd has loaded is outdated.
# This output shows the current version of the unit's original fragment and drop-in files.
# If fragments or drop-ins were added or removed, they are not properly reflected in this output.
# Run 'systemctl daemon-reload' to reload units.
# /lib/systemd/system/kubelet.service
[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=http://kubernetes.io/docs/

[Service]
ExecStart=/var/lib/minikube/binaries/v1.18.3/kubelet
Restart=always
StartLimitInterval=0
# Tuned for local dev: faster than upstream default (10s), but slower than systemd default (100ms)
RestartSec=600ms

[Install]
WantedBy=multi-user.target

# /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
[Unit]
Wants=docker.socket

[Service]
ExecStart=
ExecStart=/var/lib/minikube/binaries/v1.18.3/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --config=/var/lib/kubelet/c
onfig.yaml --container-runtime=docker --hostname-override=minikube --kubeconfig=/etc/kubernetes/kubelet.conf --node-ip=172.17.0.2 

[Install]

You can see the node IP is identified with the --node-ip=172.17.0.2 kubelet option.

✌️☮️

OK so there must have been something wierd in my k8 config. It is working as expected now, and status.hostIP is returning the correct IP

Related