将一个或多个本地端口转发到pod。这个命令要求节点安装“socat”。
使用资源类型/名称,如deployment/mydeployment来选择pod。如果省略,资源类型默认为'pod'。
如果有多个pod匹配标准,将自动选择一个pod。转发会话结束
当选择的pod终止时,需要重新运行该命令来恢复转发。
代码语言:javascript复制Examples:
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
kubectl port-forward pod/mypod 5000 6000
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the
deployment
kubectl port-forward deployment/mydeployment 5000 6000
# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the service
kubectl port-forward service/myservice 5000 6000
# Listen on port 8888 locally, forwarding to 5000 in the pod
kubectl port-forward pod/mypod 8888:5000
# Listen on port 8888 on all addresses, forwarding to 5000 in the pod
kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000
# Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod
kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000
# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward pod/mypod :5000
--address=[localhost] 要监听的地址(逗号分隔)。只接受IP地址或本地主机,当提供了localhost时,kubectl将尝试在127.0.0.1和::1上绑定,如果两者都不绑定,则会失败可以绑定地址。
--pod-running-timeout=1m0s 大于0的等待时间长度(如5s、2m或3h),直到至少一个豆荚运行