I have initiated master using the hostname instead of ip address like below:
sudo kubeadm init --token-ttl=0 --apiserver-advertise-address=device1.local
Although I am using hostname instead of ip address, the token it generated contains ip address but it should contain hostname.
kubeadm join --token 2083f8.06a02c04e6d63e1e 192.168.1.2:6443 --discovery-token-ca-cert-hash sha256:e08f6f4fccf9cc7341e3eca040f4437de397a4347a4bdeb1cf354b440cdcc3ee
I used the above token on other node which I want to add but replaced the ip address with hostname device1.local
and ran the command but it showed below error:
[discovery] Failed to request cluster info, will try again: [Get https://device1.local:6443/api/v1/namespaces/kube-public/configmaps/cluster-info: dial tcp: lookup device1.local on 192.168.1.1:53: no such host]
Both the device can ping each other using hostname. Also if I try to access https://pi1.local:6443/api/v1/namespaces/kube-public/configmaps/cluster-info
I get some info about the cluster on browser but kubeadm is not able to find it.
How can I use hostname instead of using the ip address. How can I make kubeadm init
to generate token which contains hostname.?
Thanks
It actually using a hostname for discovery - lookup device1.local on 192.168.1.1:53: no such host
- that means that it cannot resolve host device1.local
using DNS server 192.168.1.1:53
.
So, you doing it right, just check that hostname which you using as apiserver-advertise-address
, which has to be an apiserver hostname, resolvable on all your nodes, by nslookup device1.local
, as example.