How to specify Internal-IP for kubernetes worker node
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).
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.
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 kubelet
to check option if it’s applied.
And finally the kubectl get nodes
report correct IP.
Learn more
Kubelet option -> https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
How to reconfigure kubelet on live cluster -> https://kubernetes.io/docs/tasks/administer-cluster/reconfigure-kubelet/#understanding-how-the-kubelet-checkpoints-config