Setup different Internal IP for worker nodes

7/1/2019

I want to setup a kubernetes cluster locally where I would like to have 1 master node and 2 worker nodes. I have managed to do that but I am not able to access pods or see any logs of a specific pod because Internal IP address is the same for all nodes.

vagrant@k8s-head:~$ kubectl get nodes -o wide
NAME         STATUS   ROLES    AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
k8s-head     Ready    master   5m53s   v1.15.0   10.0.2.15     <none>        Ubuntu 16.04.6 LTS   4.4.0-151-generic   docker://18.6.2
k8s-node-1   Ready    <none>   4m7s    v1.15.0   10.0.2.15     <none>        Ubuntu 16.04.6 LTS   4.4.0-151-generic   docker://18.6.2
k8s-node-2   Ready    <none>   2m28s   v1.15.0   10.0.2.15     <none>        Ubuntu 16.04.6 LTS   4.4.0-151-generic   docker://18.6.2

In order to resolve this problem I have found out that following things should be done:
- add KUBELET_EXTRA_ARGS=--node-ip=<IP_ADDRESS> in /etc/default/kubelet file
- restart kubelet by running:
sudo systemctl daemon-reload && sudo systemctl restart kubelet

The problem is that /etc/default/kubelet file is missing on this location and I am not able to add this additional parameter. Tried with creating file manually but it looks like it is not working when I restart kubelet, IP address is still the same.

Anyone faced this issue with missing /etc/default/kubelet file or if there is another easier way to setup different Internal IP addresses?

-- Boban Djordjevic
kubelet
kubernetes

1 Answer

7/1/2019

It is normal to have the same IP in every node for the Kubernetes Cluster running in VirtualBox, the reason is that it is a NAT newtork not intended for communication between virtual machines, the 10.0.2.15 IP is NATed when accessing the outside world.

The following diagram shows the networks that are created in a Kubernetes Cluster on top of VirtualBox, as you can see, every node has the same IP in the NAT newtork but different IPs on the other networks:

Kubernetes Cluster Networks

In order to access the PODs you can use a NodePort and the HOST ONLY network.

See a full example and download the code at Building a Kubernetes Cluster with Vagrant and Ansible (without Minikube). It is a tutorial that explains how to launch a Kubernetes cluster using Ansible playbooks, Vagrant and VirtualBox.

It uses Calico for networking and it includes another tutorial for installing Istio if you need a micro service mesh.

-- Javier Ruiz
Source: StackOverflow