I am using a windows laptop where a vagrant box is installed, where I have a kubectl client that manages some external kubernetes cluster.
For debugging purposes I would like to do a port-forwarding via kubectl and access this port from the host machine. This works perfectly from inside vagrant to the kubernetes cluster, but obviously something doesn't work in conjunction with the vagrant port forwarding from host to vagrant.
Here my setup:
Port-Forwarding in Vagrant:
config.vm.network "forwarded_port", guest: 8080, host: 8080, auto_correct:false
start nginx container in kubernetes:
kubectl run -i -t --image nginx test
forward port to localhost (inside vagrant):
kubectl port-forward test-64585bfbd4-zxpsd 8080:80
test nginx running inside vagrant-box:
vagrant@csbox:~$ curl http://localhost:8080 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
Works.
Now going a level up - on the windows host:
PS U:\> Invoke-WebRequest http://localhost:8080 Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a receive. At line:1 char:1 + Invoke-WebRequest http://localhost:8080 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Works Not.
From my understanding - just looking at the port forwardings everything should be okay. Do you have any ideas why this doesn't work like expected?