【问题标题】:kubernetes port-forward sticks on [::1]:8080->8080kubernetes 端口转发坚持 [::1]:8080->8080
【发布时间】:2021-12-03 21:24:15
【问题描述】:

我正在尝试为 Kubernetes 的 nginx 入口控制器转发端口 8080。我正在运行命令:

kubectl -n nginx-ingress port-forward nginx-ingress-768dfsssd5bf-v23ja 8080:8080 --request-timeout 0
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

它永远挂在::1 上。有没有我可以查看的日志以了解其挂起的原因?

【问题讨论】:

    标签: nginx kubernetes


    【解决方案1】:

    嗯,这是预期的行为 - 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 &
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    • 1970-01-01
    • 2020-05-14
    • 2015-06-01
    相关资源
    最近更新 更多