question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add nodes ip resolve to HA's api-server's /etc/hosts

See original GitHub issue

Hi, After create the HA,I notice that when I use kubectl port-forward or exec to some container, if the container locates on other nodes rather than on api-server node, dns lookup fails. The message shows that:

kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443
error: error upgrading connection: error dialing backend: dial tcp: lookup machine5 on 127.0.0.53:53: server misbehaving

After some digging, I found that after microk8s join, the node only add mater’s ip and itself’s ip to the /etc/hosts, so lookup the hostname of other node would failed due to the config of the lan router.

So I add all nodes to the /etc/file of the node which api-server is on.

So maybe add all nodes hostname automaticly to /etc/hosts would be nice.

Thanks in advance

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
PAStheLoDcommented, Nov 20, 2020

The problem is that CoreDNS does not resolve the hostname of the nodes (and even though the feature was requested it was marked as WONTFIX basically), and thus there really isn’t any service that knows it besides the k8s apiserver.

Editing the hosts file is not ideal, but at least can be done with this on each node:

microk8s kubectl get nodes -o wide | awk '{ print $6 " " $1 }' | tail -n +2 | grep -v $(hostname)  >> /etc/hosts

If your nodes going to change frequently, then probably you need to put something like this into a CRON script (or systemd timer unit). It’s the same as the previous one-liner with before-after guard lines to be able to replace multiple lines.

perl -i -p0e 's/## microk8s nodes begin.*## microk8s nodes end//s' /etc/hosts
echo '## microk8s nodes begin' >> /etc/hosts
microk8s kubectl get nodes -o wide | awk '{ print $6 " " $1 }' | tail -n +2 | grep -v $(hostname)  >> /etc/hosts
echo '## microk8s nodes end' >> /etc/hosts

It’s also possible to somehow put all this into the Corefile of CoreDNS (which is basically in the coredns configmap in the kube-system NS), and use the in-cluster DNS service from the hosts, but it’s left as exercise for the reader, because it seems even more fragile than manipulating the hosts file.

3reactions
tobiasmuehlcommented, Mar 8, 2022

To give some weight to this issue, it is one of only 2 reasons why I migrated everything from microk8s to k3s

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add nodes ip resolve to HA's api-server's /etc/hosts #1566
I have been using RKE clusters and I don't see this problem. ubuntu@k-one:~$ microk8s kubectl port-forward po/argocd-server-86f7f94488-2zntt ...
Read more >
Adding entries to Pod /etc/hosts with HostAliases - Kubernetes
Adding entries to a Pod's /etc/hosts file provides Pod-level override of hostname resolution when DNS and other options are not applicable.
Read more >
Using hostAliases to Configure /etc/hosts in a Pod - 华为云
If DNS or other related settings are inappropriate, you can use hostAliases to overwrite the resolution of the host name at the pod...
Read more >
How should the /etc/hosts file be set up on RHEL cluster nodes?
Resolution. In Red Hat Enterprise Linux with the High Availability Add-On, the /etc/hosts file should be used to define the IP address and ......
Read more >
Kubeadm join not working with the hostname of the device
It actually using a hostname for discovery - lookup device1.local on ... has to be an apiserver hostname, resolvable on all your nodes, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found