I am installing a k8s cluster on CentOS 8 Hyper-V virtual machines. I used my router DHCP server to give them static IP addresses, but I have no DNS.

When I was ready to setup kubernetes I ran sudo kubeadm init

I received the following warnings

[WARNING Hostname]: hostname "k8s-master" could not be reached
[WARNING Hostname]: hostname "k8s-master": lookup k8s-master on no such host

Hoping this would not matter, and that I could be using the static IP adresses I continued setting up the k8s dashboard. No information is available in the dashboard, and probably due to the following errors in the metric server

E0914 19:22:32.513517       1 manager.go:111] unable to fully collect
 metrics: [unable to fully scrape metrics from source kubelet_summary:k8s-
worker1: unable to fetch metrics from Kubelet k8s-worker1 (k8s-worker1): Get
 https://k8s-worker1:10250/stats/summary?only_cpu_and_memory=true: dial tcp: 
lookup k8s-worker1 on no such host, unable to fully scrape 
metrics from source kubelet_summary:k8s-master: unable to fetch metrics from
 Kubelet k8s-master (k8s-master): Get https://k8s-master:10250/stats
/summary?only_cpu_and_memory=true: dial tcp: lookup k8s-master on no such host]

I decided to edit the /etc/hosts file and add these entries k8s-master k8s-worker1

This did not solve my problem. My virtual machines are able to ping each other by hostname, but nslookup doesn't work.

I don't know the mechanism that k8s uses to resolve hostnames, and what else I can do to let k8s work without an external dns. Any help is very much appreciated.

Note: I have 'fixed; my issue by adding the following arguments in the metrics-server deployment.


However I would still like to know if this can still be fixed using hostnames, and how the hostname resolution works in kubernetes.

  • You are fighting an uphill battle trying to run a cluster using only /etc/hosts, as you have discovered. You can either use dnsmasq or you can be adventurous and expose your CoreDNS outside the cluster via a NodePort and then point your Node's /etc/resolv.conf at it (since it is very cheap to make CoreDNS answer to all kinds of fake zones); I personally would go the first route, since putting out a fire in the 2nd mechanism would be some hair pulling – mdaniel Sep 15 at 2:45
  • I decided to buy a Raspberry Pi and install Pi-hole. – Robert Sep 15 at 16:51
  • Can you post is as an answer - according to stackexchange policy - to more visible for community ? – Malgorzata Sep 22 at 8:05

Taking @msdaniel his comment as input, I have used a Raspberry Pi as a DNS server and this solved many problems for me. I no longer need to use Samba to communicate the hostnames through netbios, I don't need to edit my hosts file, and of course I can just use the default k8s preferred address types.

So the answer is, just use a DNS for your network, even if it is a simple one like Pi-hole. It prevents a lot of headaches.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.