I use kubefwd - Kubernetes Service Forwarding to port-forward elasticsearch service from k8s and into my local Mac environment. I also inherit following versions and cannot deviate from it:
% head -1 docker-compose.override.yml
version: '2.2'
% docker-compose-v1 --version
docker-compose version 1.29.2, build 5becea4c
% docker-compose --version
Docker Compose version v2.6.0
%
Where in order to connect to the host, one needs to use āhost.docker.internalā, however in my case since kubefwd mapped ports to ā127.1.27.Xā IP, I believe something like nc/netcat could help to close the gap between āhostā and ālocalhostā, but Iām unable to get it to work too(
Thank you for trying to help me, I do appreciate your time
I did try using āhost.docker.internalā, unfortunately that didnāt do the trick( as kubefwd maps ports to the ā127.1.27.Xā IP range, which isnāt same as what host.docker.internal IP is.
So you donāt want to access your local machine from a Kubernetes pod, but instead you want to access a Kubernetes service from a container running on your machine on Docker Desktop.
It was not clear to me. This is why I suggested SSH remote port forwards.
Since kubefwd doesnāt do more than changing your hosts file and and forwarding ports from your host machine to Kubernetes services like kubectl port-forward, the application which wants to access those services must be on the same network as kubefwd is running on. If you run kubefwd on your host machine, then your containers must be on the host network. As Docker Desktop runs containers in a virtual machine, this is not enough. You could however run kubefwd in a container running on the host network, which means the network of the virtual machine. I just donāt know how you could mount the hosts file from the virtual machine into the kubefwd container properly, but it would better on Windows since there is no /etc/hosts on the host machine.
An other and for me is the preferred way is not changing anything in the virtual machine, since it could break the whole Docker Desktop, so I would run kubefwd in the network namespace of the container you are running on Docker Desktop.
Since kubefwd and the app container shares the same hosts file, kubefwd would probably be able to change it and since they share the same loopback interface, the local ip addresses would work.
If you have multiple containers on your machine and you donāt want to run multiple kubefwd instances, then it is much more complicated and I donāt know the answer. I donāt see how netcat could help here, but if it can, I would like to know that too Although I still think that you would rather use a more secure way to forward ports like SSH forwarding.