当前位置: 首页 > 文档资料 > Kubernetes 指南 >

7. 实践案例 - 端口转发

优质
小牛编辑
133浏览
2023-12-01

端口转发是 kubectl 的一个子功能,通过 kubectl port-forward 可以将本地端口转发到指定的 Pod。

使用方法

  1. # Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
  2. kubectl port-forward mypod 5000 6000
  3. # Listen on port 8888 locally, forwarding to 5000 in the pod
  4. kubectl port-forward mypod 8888:5000
  5. # Listen on a random port locally, forwarding to 5000 in the pod
  6. kubectl port-forward mypod :5000
  7. # Listen on a random port locally, forwarding to 5000 in the pod
  8. kubectl port-forward mypod 0:5000