How to specify Internal-IP for kubernetes worker node

Kan Rangsan
2 min readJul 28, 2019

--

Background

I’m following kubernetes the hard way guide using vagrant+virtual box for my test cluster. The worker node VMs have two IP address, one is NAT address (10.0.2.15) for internet access and other one is Host-Only address (192.168.56.x).

NAT and Host-Only address

The problem is if we don’t specify the IP, kubelet service on worker node will pick up the NAT address represent as the node IP. This is not gonna work because each node use Host-Only address to communicate each other. We need to change INTERNAL-IP to be Host-Only address, not NAT.

Should be Host-Only address instead of NAT IP

How I fixed it

I’ve tried the kubectl edit node <nodename> command but didn’t work. NAT address still appear. We need to tell kubelet to pick up the right address. Here’s what I did. SSH to worker node, find the kubelet systemd service file, add the node-ip option then reload systemd daemon and restart kubelet service.

[devops@node06 ~]$ cat /etc/systemd/system/kubelet.service
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/kubernetes/kubernetes
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/local/bin/kubelet \
--config=/var/lib/kubelet/kubelet-config.yaml \
--docker=unix:///var/run/docker.sock \
--docker-endpoint=unix:///var/run/docker.sock \
--image-pull-progress-deadline=2m \
--kubeconfig=/var/lib/kubelet/kubeconfig \
--network-plugin=cni \
--register-node=true \
--node-ip=192.168.56.126 \
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
[devops@node06 ~]$ sudo systemctl daemon-reload
[devops@node06 ~]$ sudo systemctl restart kubelet

Verify

By running systemd status kubeletto check option if it’s applied.

node-ip option to specify IP address

And finally the kubectl get nodes report correct IP.

Host-Only IP is shown in kubectl get nodes command

--

--