在看到port-forward的功能时非常的兴奋,因为可以解决一个容器22端口通过代理的方式暴露到宿主,经过一列软件的安装测试后发现,容器端口只能暴露到localhost网卡,好坑,但是还是记录一下整个操作过程,还可以通过VPN或者代理服务器访问
+
# 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]
yum -y install socat
$ 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
kubectl port-forward $POD_NAME hostPort:containerPort