官术网_书友最值得收藏!

Port forwarding

Now we can use that name to ask kubectl to set up a proxy that will forward all traffic from a local port we specify to a port associated with the Pod we determine. Get the full name of the Pod that was created with your deployment by looking at the Pods using the following command:

kubectl get pods

In my example, the result was flask-1599974757-b68pw, which can then be used with the port-forward command:

kubectl port-forward flask-1599974757-b68pw 5000:5000

The output should be something like the following:

Forwarding from 127.0.0.1:5000 -> 5000
Forwarding from [::1]:5000 -> 5000

This is forwarding any and all traffic that gets created on your local machine at TCP port 5000 to TCP port 5000 on the Pod flask-1599974757-b68pw.

You will note that you don't have a Command Prompt back yet, which is because the command is actively running to keep this particular tunnel we've requested alive. If we cancel or quit the kubectl command, typically by pressing Ctrl + C, then port forwarding will immediately end. kubectl proxy works in the same fashion, so when you use commands such as kubectl port-forward or kubectl proxy, you will probably want to open another Terminal window to run that command in by itself.

While the command is still running, open a browser and put in this URL: http://localhost:5000. The response should come back that says Index Page. When we invoked the kubectl run command, I specifically choose port 5000 to match the default from Flask.

主站蜘蛛池模板: 西华县| 鲁甸县| 寻乌县| 泸西县| 酉阳| 赤壁市| 红桥区| 亳州市| 琼结县| 马关县| 息烽县| 囊谦县| 抚宁县| 凌海市| 凤城市| 江华| 拉孜县| 房山区| 阿鲁科尔沁旗| 扶风县| 滨州市| 肥乡县| 澳门| 伊金霍洛旗| 冕宁县| 巴林右旗| 大化| 肥城市| 珲春市| 荆门市| 文安县| 蕉岭县| 晋城| 随州市| 山丹县| 邳州市| 应用必备| 日土县| 广灵县| 含山县| 宁阳县|