【问题标题】:kubectl port-forward does not return when connection lost连接丢失时 kubectl port-forward 不返回
【发布时间】:2021-11-21 04:54:06
【问题描述】:

kubectl port-forward 中的help 表示The forwarding session ends when the selected pod terminates, and rerun of the command is needed to resume forwarding.

虽然它不会在 pod 终止时自动重新连接,但命令也不会返回,只会挂起错误:

E0929 11:57:50.187945   62466 portforward.go:400] an error occurred forwarding 8000 -> 8080: error forwarding port 8080 to pod a1fe1d167955e1c345e0f8026c4efa70a84b9d46029037ebc5b69d9da5d30249, uid : network namespace for sandbox "a1fe1d167955e1c345e0f8026c4efa70a84b9d46029037ebc5b69d9da5d30249" is closed
Handling connection for 8000
E0929 12:02:44.505938   62466 portforward.go:400] an error occurred forwarding 8000 -> 8080: error forwarding port 8080 to pod a1fe1d167955e1c345e0f8026c4efa70a84b9d46029037ebc5b69d9da5d30249, uid : failed to find sandbox "a1fe1d167955e1c345e0f8026c4efa70a84b9d46029037ebc5b69d9da5d30249" in store: not found

我希望它返回,以便我可以处理此错误并制作将重新运行它的脚本。

有什么办法或解决方法吗?

【问题讨论】:

    标签: bash shell kubernetes command-line-interface kubectl


    【解决方案1】:

    根据Kubernetes Issues page on GitHub 上描述的信息,我可以假设这是您的情况的正常行为:在删除 pod 时无法取消端口转发连接,因为服务器上的 REST 连接器内部没有连接管理一边。

    即使 pod 不存在,从 kubectl 一直到挂起的 kubelet 都保持着连接。

    我们将在端口转发上代理一个 websocket 连接 kubectl->kubeapiserver->kubelet。

    【讨论】:

    • 你好@WytrzymałyWiktor!它确实解释了为什么它不返回但没有解决问题:)
    【解决方案2】:

    递归函数?

    kpf(){ kubectl port-forward $type/$object $LOCAL:$REMOTE $ns || kpf; }
    

    同时检查this

    【讨论】:

    • 问题是kubectl port-forward没有返回,所以它不起作用
    猜你喜欢
    • 2019-07-22
    • 1970-01-01
    • 2020-05-13
    • 2023-03-12
    • 2021-06-02
    • 1970-01-01
    • 2022-06-11
    • 2019-01-06
    相关资源
    最近更新 更多