How to make kubernetes work with dynamic ip address

3/13/2018

I have created a kubernetes cluster where I have a master node and two worker nodes. I initialised master node using below command

sudo kubeadm init --token-ttl=0 --apiserver-advertise-address=192.168.0.27

192.168.0.27 is the ip address of master node. Then I used the generated token to start my worker nodes. Now the problem is that my network is in DHCP and the ip address changes sometime due to which it starts showing below error:

Unable to connect to the server: dial tcp 192.168.0.27:6443: getsockopt: no route to host

It shows above error because at the time of initializing the master node, I have used the ip address and after the ip address changes, its not able to access it.

Is it possible to configure master and other nodes in some way so that they can work regardless of any ip address change.

Thanks

-- S Andrew
kubernetes
networking
nodes

1 Answer

3/18/2018

As @Suresh Vishnoi mentioned, it is not possible to set a DNS name in current stable versions of Kubernetes because of implementation.

But, merge request with that feature - new key for DNS name instead of IP address are already merged into Kubernetes master and available from version v1.10.0-beta.4.

In your case, it is not possible to use DNS name for discovery, but, you can set up your DHCP server for associate IP address from DHCP pool to MAC address of your master, which will able you to using all features of DHCP, but an address of your master will be always same.

Standard Linux dhcpd DHCP server you can configure like that (replace a mac address and IP to which one you need):

host KubeMaster { hardware ethernet 00:1F:6A:21:71:3F; fixed-address 10.0.0.101; }

If you using any router or different OS for your DHCP server, then please check their documentation.

-- Anton Kostenko
Source: StackOverflow