How to run Kubernetes without external DNS – Hostname could not be reached

centos8internal-dnskubernetes

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 192.168.0.1:53: 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 10.96.0.10:53: 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 
10.96.0.10:53: no such host]

I decided to edit the /etc/hosts file and add these entries

192.168.0.151 k8s-master
192.168.0.161 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.

  --kubelet-preferred-address-types=[InternalDNS,InternalIP,Hostname,ExternalDNS,ExternalIP]
  --kubelet-insecure-tls

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

Best Answer

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.

Related Topic