Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make kubernetes work with dynamic ip address

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

like image 358
S Andrew Avatar asked Mar 13 '18 06:03

S Andrew


People also ask

How can I get Kubernetes cluster IP from outside?

To reach the ClusterIp from an external computer, you can open a Kubernetes proxy between the external computer and the cluster. You can use kubectl to create such a proxy. When the proxy is up, you're directly connected to the cluster, and you can use the internal IP (ClusterIp) for that Service .

How are IP addresses assigned in Kubernetes?

Kubernetes assigns an IP address (the Pod IP) to the virtual network interface in the Pod's network namespace from a range of addresses reserved for Pods on the node. This address range is a subset of the IP address range assigned to the cluster for Pods, which you can configure when you create a cluster.


1 Answers

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.

like image 175
Anton Kostenko Avatar answered Sep 17 '22 02:09

Anton Kostenko