我们注意到当我们exec -it
连接到 pod,在一定的空闲时间后连接被破坏。是否有任何选项可以让连接打开更长时间?
我看到有一个开放PR ,但想知道是否有解决此问题的方法。
最佳答案
最简洁的答案是不。这就是为什么:
Enabling TCP keepalive for console connections
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.
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
Custom Configuration of TCP Socket Keep-Alive Timeouts
Default values for these properties is:
tcp_keepalive_time = 7200 seconds tcp_keepalive_probes = 9 tcp_keepalive_intvl = 75 seconds
另一种可能的方法是在客户端启动某种代理服务器并通过它连接到 Kubernetes apiserver。
我自己没有测试过,这可能很棘手,但是 here是如何为 Nginx 启用 Keepalive 后端的示例。
关于kubernetes - kubectl 命令在空闲几分钟后断开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50691104/