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

<p>I see there is an open <a href="https://github.com/kubernetes/kubernetes/pull/63793/files" rel="nofollow noreferrer">PR</a>,  but wondering if there is any workaround for this issue.</p>

<p>The short answer is no. And that's why:</p>

<p><a href="https://stromasys.atlassian.net/wiki/spaces/KBP/pages/43221121/Enabling+TCP+keepalive+for+console+connections" rel="nofollow noreferrer">Enabling TCP keepalive for console connections</a></p>

<blockquote>
  <p>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 <strong>and</strong> by the application/program
  opening TCP connections.</p>
  
  <p>On Linux, edit the "/etc/sysctl.conf" file and add these lines:</p>

<pre><code>net.ipv4.tcp_keepalive_time = 200
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_keepalive_intvl = 50
</code></pre>
  
  <p>(feel free to adapt the values as you see fit). When done editing, you
  must make the new values known to the kernel:</p>

<pre><code># sysctl --load=/etc/sysctl.conf
</code></pre>
</blockquote>

<p><a href="http://coryklein.com/tcp/2015/11/25/custom-configuration-of-tcp-socket-keep-alive-timeouts.html" rel="nofollow noreferrer">Custom Configuration of TCP Socket Keep-Alive Timeouts</a></p>

<blockquote>
  <p>Default values for these properties is:</p>

<pre><code>tcp_keepalive_time = 7200 seconds
tcp_keepalive_probes = 9
tcp_keepalive_intvl = 75 seconds
</code></pre>
</blockquote>

<p>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 <a href="https://ma.ttias.be/enable-keepalive-connections-in-nginx-upstream-proxy-configurations/" rel="nofollow noreferrer">here</a> is an example of how to enable keepalives to backend for Nginx.</p>
