嗯,这是预期的行为 - kubectl port-forward 没有得到 daemonized by default。来自official Kubernetes documentation:
注意: kubectl port-forward 不会返回。要继续练习,您需要打开另一个终端。
所有日志都会显示在kubectl port-forward命令输出中:
user@shell:~$ kubectl port-forward deployment/nginx-deployment 80:80
Forwarding from 127.0.0.1:80 -> 80
Including errors:
Handling connection for 88
Handling connection for 88
E1214 01:25:48.704335 51463 portforward.go:331] an error occurred forwarding 88 -> 82: error forwarding port 82 to pod a017a46573bbc065902b600f0767d3b366c5dcfe6782c3c31d2652b4c2b76941, uid : exit status 1: 2018/12/14 08:25:48 socat[19382] E connect(5, AF=2 127.0.0.1:82, 16): Connection refused
如果您没有任何日志,则表示您没有尝试连接,或者您指定了错误的地址/端口。
如前所述,您可以打开一个新的终端窗口,也可以通过在命令末尾添加& 来运行kubectl port-forward in the background:
kubectl -n nginx-ingress port-forward nginx-ingress-768dfsssd5bf-v23ja 8080:8080 --request-timeout 0 &
如果你想在后台运行kubectl port-forward并将所有日志保存到文件中,你可以在最后使用nohup command + &:
nohup kubectl -n nginx-ingress port-forward nginx-ingress-768dfsssd5bf-v23ja 8080:8080 --request-timeout 0 &