1
votes

I am testing k8s on ubuntu using virtual box.

I have two nodes, one is master, another is worker node.

I deployed a pod containing nginx server container for test.

I can access the webpage deployed by the pod on master node with commands below

kubectl port-forward nginx-server 8080:80

curl localhost:8080

but I want to open this page on my host os(windows10) using chrome web browser enter image description here

This is how I set port-forwading on virtual-box...

1
Do you have kubectl installed and configured to access this cluster on your Windows host ? - mario

1 Answers

1
votes

simply answer your question, use address args for the kubectl command:

kubectl port-forward --address 0.0.0.0 nginx-server 8080:80

here is the explanation:

  1. kubectl port-forward bind to localhost by default
  2. the port forward for your virtual box is bind to 10.100.0.104
  3. 0.0.0.0 will bind the port to both localhost and 10.100.0.104
  4. change 0.0.0.0 to 10.100.0.104 will also work for 10.100.0.104 access, but not the localhost

and also, when exposing a port, you could use a NodePort service: https://kubernetes.io/docs/concepts/services-networking/service/#nodeport