kubectl 命令在空闲几分钟后断开连接 [英] kubectl command disconnects after few minutes of idle time

查看:36
本文介绍了kubectl 命令在空闲几分钟后断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们注意到当我们 exec -it 连接到一个 Pod 时,在一定的空闲时间后连接被破坏.是否有任何选项可以让连接打开更长时间?

We noticed when we exec -it to connect into a pod, after certain idle time the connection get destroyed. Is there any option to leave the connection open longer?

我看到有一个开放的 PR,但想知道是否有此问题的任何解决方法.

I see there is an open PR, but wondering if there is any workaround for this issue.

推荐答案

简短的回答是否定的.这就是为什么:

The short answer is no. And that's why:

启用 TCP keepalive用于控制台连接

TCP keepalive 是一个 TCP 选项,它导致数据包通过即使没有交通运输,也能建立连接.它应该是在连接的两端启用.必须启用 TCP keepalive在操作系统级别由应用程序/程序打开 TCP 连接.

TCP keepalive is a TCP option that causes packets to be exchanged over a connection even if there is no traffic to transport. It should be enabled on both ends of the connection. TCP keepalive must be enabled at the operating-system level and by the application/program opening TCP connections.

在 Linux 上,编辑/etc/sysctl.conf"文件并添加以下几行:

On Linux, edit the "/etc/sysctl.conf" file and add these lines:

net.ipv4.tcp_keepalive_time = 200
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_intvl = 50

(随意调整您认为合适的值).完成编辑后,您必须让内核知道新值:

(feel free to adapt the values as you see fit). When done editing, you must make the new values known to the kernel:

# sysctl --load=/etc/sysctl.conf

自定义TCP Socket Keep-Alive超时配置

这些属性的默认值为:

tcp_keepalive_time = 7200 seconds
tcp_keepalive_probes = 9
tcp_keepalive_intvl = 75 seconds

另一种可能的方法是在客户端启动某种代理服务器,并通过它连接到 Kubernetes apiserver.我自己还没有测试过它可能很棘手,但是 这里 是如何为 Nginx 启用 keepalive 到后端的示例.

The other possible way is to start some kind of proxy server on the client side and connect to Kubernetes apiserver through it. I haven’t tested it myself and it could be tricky, but here is an example of how to enable keepalives to backend for Nginx.

这篇关于kubectl 命令在空闲几分钟后断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆