Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race when updating hosts file? #74

Closed
rmja opened this issue Aug 13, 2019 · 7 comments · Fixed by #76
Closed

Race when updating hosts file? #74

rmja opened this issue Aug 13, 2019 · 7 comments · Fixed by #76

Comments

@rmja
Copy link
Contributor

rmja commented Aug 13, 2019

I am observing a peculiar issue when running kubefwd with multiple services.

Im an running on Windows with Docker Desktop.

Docker Desktop adds the following entry in the hosts file during installation "127.0.0.1 kubernetes.docker.internal" and it is this host that is specified in the cluster section in the .kube\config file (seen by kubectl config view). The result is that the port-forwarding commands are sent to https://kubernetes.docker.internal:6443/....

However, if kubefwd forwards multiple services, it happens at random that the following error is returned when forwarding services:

ERROR: error upgrading connection: error sending request: Post https://kubernetes.docker.internal:6443/api/v1/namespaces/default/pods/mypod-6dd464d68b-mhk29/portforward?timeout=32s: dial tcp: lookup kubernetes.docker.internal: no such host

Whether the error is shown for a pod or not seems random, however if a selector is specified so that only one service is selected, then the error never shows.

If I update the .kube\config file to have server: https://localhost:6443 then forwarding starts correctly everytime.

I have tried removing the call to pfo.Hostfile.Save() and it seems to solve the problem.

@cjimti
Copy link
Member

cjimti commented Aug 14, 2019

If I update the .kube\config file to have server: https://localhost:6443 then forwarding starts correctly everytime.

That is strange since localhost and kubernetes.docker.internal are both aliases in /etc/hosts unless windows handle this differently. If kubefwd errors on kubernetes.docker.internal and not localhost then I can't see how it could be the /etc/hosts writes.

I have not personally run into this problem on my mac. I don't typically run local clusters but I do use my /etc/hosts for a ton of other aliases and have not experienced interference. If any other windows users have this issue I would be curious.e.

Using 127.0.0.1 to connect to your Docker Desktop is going to be your best option for the time being if the /etc/hosts writes are causing DNS lookup to fail.

@rmja
Copy link
Contributor Author

rmja commented Feb 10, 2020

@cjimti This bug has reappeared after upgrading from 1.9.1 to 1.11.1.

@rmja
Copy link
Contributor Author

rmja commented Feb 10, 2020

More specifically, 1.10.0 works, 1.11.0 does not.

@rmja
Copy link
Contributor Author

rmja commented Apr 17, 2020

@cjimti Could you please re-open this issue?

@cjimti
Copy link
Member

cjimti commented Apr 17, 2020

Is there a reason to use kubernetes.docker.internal rather than localhost? I don't really know of a work-around for your situation since kubefwd must be able to write to /etc/hosts and if other processes like Docker Desktop are trying to add entries at the same time it will be a problem.

Is there a solution that you have in mind or something I am missing?

@rmja
Copy link
Contributor Author

rmja commented Apr 17, 2020

The thing is that #76 fixed the issue, at least for me on Windows. But I can see that it has been replaced with a different mechanism in the newer versions. I can simply stay on 1.10.0 for the time being...

@cjimti
Copy link
Member

cjimti commented Apr 17, 2020

I'll re-open the ticket and explore any possible solutions but can't promise anything in the short term.

Is there an option to prevent Docker Desktop from adding kubernetes.docker.internal 127.0.0.1 every time? If so you can add it once manually and never have to worry about it.

@cjimti cjimti reopened this Apr 17, 2020
@cjimti cjimti closed this as completed Oct 19, 2020
D3-LucaPiombino pushed a commit to CodeCoil/kubefwd that referenced this issue Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants