14

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
  • 5,592
  • 27
  • 115
  • 237
  • Hi, `--apiserver-advertise-address string : The IP address the API Server will advertise it's listening on. Specify '0.0.0.0' to use the address of the default network interface.` you can try with `--apiserver-advertise-address=0.0.0.0` – Suresh Vishnoi Mar 13 '18 at 10:19
  • @SureshVishnoi Hi. What do you mean by default network interface. On the machine I am using, it has `eth0` and `wlan0`. By using `0.0.0.0`, which interface will it pick up. If the IP changes, will I be able to access the cluster.? Thanks – S Andrew Mar 13 '18 at 10:21
  • As I understand, Api-server need to bind with an IP address so If you do not specify the specific IP address then it will take IP address from eth0. Eth0 get an IP address from DHCP client. – Suresh Vishnoi Mar 13 '18 at 10:24
  • @SureshVishnoi I think this should work then, I am trying it , will let you know. – S Andrew Mar 13 '18 at 10:25
  • Yea, Let's see :) – Suresh Vishnoi Mar 13 '18 at 10:26
  • @SureshVishnoi No. I restarted my router, so the ip address changed and with the new ip, when I ran `kubectl get nodes` it says `Unable to connect to the server: dial tcp :6443: getsockopt: no route to host`. Is there any way we can get it working using `hostname` instead of `ip address` because hostname will always be same. – S Andrew Mar 13 '18 at 10:33
  • ohh ok , I have added a link [kubeadm-initializing-your-master](https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#24-initializing-your-master).perhaps it might give us some knowledge – Suresh Vishnoi Mar 13 '18 at 10:36
  • you can try with `kubeadm reset --apiserver-advertise-address=NEW_IP` if it works or not – Suresh Vishnoi Mar 13 '18 at 10:47
  • With that approach, I'll have to run that command in all the nodes which is not feasible if we have many nodes. – S Andrew Mar 13 '18 at 10:50
  • yea That's true, I found this issue of the github [issue](https://github.com/kubernetes/kubernetes/pull/59288) – Suresh Vishnoi Mar 13 '18 at 10:54
  • Here is the same situation which you are encountering.[kubeadm-issue](https://github.com/kubernetes/kubeadm/issues/338) – Suresh Vishnoi Mar 13 '18 at 10:56
  • Is there any way we can init kubeadm using hostname instead of ip address because hostname will always be same. I see there is an option of `--node-name` in kubeadm init but do not know if this we solve my issue. – S Andrew Mar 13 '18 at 10:56
  • As I understand, till now there is no flag yet. Perhaps in next release we will resolve the issue. – Suresh Vishnoi Mar 13 '18 at 10:58

1 Answers1

4

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.

sanster_23
  • 800
  • 10
  • 17
Anton Kostenko
  • 8,200
  • 2
  • 30
  • 37