<p>I have an application that accepts TCP traffic (not HTTP) and I'd like the ability to have the traffic load balanced to it. However, one requirement is that when a client makes a connection, we do not close that connection under any circumstances (ideally) since we are dealing with some clients with older technology.</p>
<p>I've set up the kubernetes nginx ingress controller, but it isn't behaving how I'm hoping/expecting. What I would like is: If the connection to one of the upstream servers closes, then the client connection remains open for some amount of time while nginx picks a new upstream server and starts sending data to it. I am not concerned about the stream's data being split across different upstream servers, I just need the connection to stay open from the client's perspective during something like a redeploy.</p>
<p>What is actually happening is that from my client's perspective, currently when the upstream server app closes the connection, my connection is closed and I have to reconnect.</p>
<p>The ingress controller has this configuration, which I thought would accomplish what I want, but it doesn't seem to be working as expected:</p>
<pre><code>
       server {
               preread_by_lua_block {
                       ngx.var.proxy_upstream_name=&quot;tcp-my-namespace-my-service-7550&quot;;
               }

               listen                  7550;

               proxy_timeout           600s;
               proxy_next_upstream     on;
               proxy_next_upstream_timeout 600s;
               proxy_next_upstream_tries   3;

               proxy_pass              upstream_balancer;

       }

</code></pre>
<p>Any help at all is greatly appreciated and I'm happy to provide more info.</p>

<p>What you describe is how nginx works out of the box with http. However</p>
<ol>
<li>Nginx has a detailed understanding of http</li>
<li>HTTP is a message based protocol i.e. uses requests and replies</li>
</ol>
<p>Since nginx knows nothing about the protocol you are using, even if it uses a request/reply mechanism with no implied state, nginx does not know  whether it has received a request not to to replay it elsewhere.</p>
<p>You need to implement a protol-aware mitm.</p>
