title: What Azure Kubernetes (AKS) 'Time-out' happens to disconnect connections in/out of a Pod in my Cluster?
body: <p>I have a working Cluster with services that all respond behind a helm installed Ingress nGinx running on Azure AKS. <strong><em>This ended up being Azure specific.</em></strong></p>
  
  <blockquote>
    <p>My question is: 
    Why does my connection to the services / pods in this cluster periodically get severed (apparently by some sort of idle timeout), and why does that connection severing appear to also coincide with my Az AKS Browse UI connection getting cut?</p>
  </blockquote>
  
  <p>This is an effort to get a final answer on what exactly triggers the time-out that causes the local 'Browse' proxy UI to disconnect from my Cluster (more background on why I am asking to follow).</p>
  
  <p>When working with Azure AKS from the Az CLI you can launch the local Browse UI from the terminal using:</p>
  
  <p><code>az aks browse --resource-group &lt;resource-group&gt; --name &lt;cluster-name&gt;</code></p>
  
  <p>This works fine and pops open a browser window that looks something like this (yay):</p>
  
  <p><a href="https://i.stack.imgur.com/pCr3t.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pCr3t.png" alt="Azure AKS Disconnects Connections entering pods"></a></p>
  
  <p>In your terminal you will see something along the lines of:</p>
  
  <ol>
  <li>Proxy running on <a href="http://127.0.0.1:8001/" rel="noreferrer">http://127.0.0.1:8001/</a> Press CTRL+C to close the tunnel... </li>
  <li>Forwarding from 127.0.0.1:8001 -> 9090 Forwarding from</li>
  <li>[::1]:8001 -> 9090 Handling connection for 8001 Handling connection for 8001 Handling connection for 8001</li>
  </ol>
  
  <p>If you leave the connection to your Cluster idle for a few minutes (ie. you don't interact with the UI) you should see the following print to indicate that the connection has timed out:</p>
  
  <blockquote>
    <p>E0605 13:39:51.940659    5704 portforward.go:178] lost connection to pod</p>
  </blockquote>
  
  <p>One thing I still don't understand is whether OTHER activity inside of the Cluster can prolong this timeout but regardless once you see the above you are essentially at the same place I am... which means we can talk about the fact that it looks like all of my other connections OUT from pods in that server have also been closed by whatever timeout process is responsible for cutting ties with the AKS browse UI.</p>
  
  <h2>So what's the issue?</h2>
  
  <p>The reason this is a problem for me is that I have a Service running a Ghost Blog pod which connects to a remote MySQL database using an npm package called 'Knex'.  As it happens the newer versions of Knex have a bug (which has yet to be addressed) whereby if a connection between the Knex client and a remote db server is cut and needs to be restored — it doesn't re-connect and just infinitely loads.</p>
  
  <h1>nGinx Error 503 Gateway Time-out</h1>
  
  <p>In my situation that resulted in nGinx Ingress giving me an Error 503 Gateway time-out.  This was because Ghost wasn't responding after the Idle timeout cut the Knex connection — since Knex wasn't working properly and doesn't restore the broken connection to the server properly.</p>
  
  <p><strong><em>Fine.</em></strong>
  I rolled back Knex and everything works great.</p>
  
  <blockquote>
    <p>But why the heck are my pod connections being severed from my Database to begin with?  </p>
  </blockquote>
  
  <p>Hence this question to hopefully save some future person days of attempting to troubleshoot phantom issues that relate back to Kubernetes (maybe Azure specific, maybe not) cutting connections after a service / pod has been idle for some time.</p>