天天看点

kubectl port-forward配置

port-forward命令参数说明

# kubectl port-forward --help
Forward one or more local ports to a pod.

Examples:
  # Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
  kubectl port-forward mypod 5000 6000

  # Listen on port 8888 locally, forwarding to 5000 in the pod
  kubectl port-forward mypod 8888:5000

  # Listen on a random port locally, forwarding to 5000 in the pod
  kubectl port-forward mypod :5000

Options:
  -p, --pod='': Pod name

Usage:
  kubectl port-forward POD [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N] [options]      
  • 看完参数说明后你应该觉得他无法bind指定网卡啦,但是还是希望你们看一下官方文档,因为这些命令会继一些命令的

port-forward辅助工具安装

  • 安装socat
  • 安装nsenter
$  wget https://www.kernel.org/pub/linux/utils/util-linux/v2.27/util-linux-2.27.tar.gz
$ tar -zxvf util-linux-2.27.tar.gz
$ cd util-linux-2.27
$ ./configure --without-ncurses && make nsenter
cp nsenter /usr/local/bin      
  • 测试port-forward命令
kubectl port-forward $POD_NAME hostPort:containerPort      

继续阅读