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

查看:167
本文介绍了空闲几分钟后,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套接字保持活动超时的配置

这些属性的默认值为:

Default values for these properties is:

tcp_keepalive_time = 7200 seconds
tcp_keepalive_probes = 9
tcp_keepalive_intvl = 75 seconds

另一种可能的方法是在客户端启动某种代理服务器,并通过它连接到Kubernetes apiserver. 我没有亲自测试过,可能会比较棘手,但是

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天全站免登陆