kubectl command disconnects after few minutes of idle time

与世无争的帅哥 提交于 2019-12-08 07:12:53

问题


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?

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


回答1:


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

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

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.



来源:https://stackoverflow.com/questions/50691104/kubectl-command-disconnects-after-few-minutes-of-idle-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!