Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

virtualbox - How to connect kubernetes pod server on guest os from host os

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...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...