<p>My Kubernetes cluster uses a replicaSet to run N similar pods. Each pod can only handles one websocket connection du to resource limitations. My Kubernetes uses a nginx ingress controller.</p>

<p>Is there any way to make nginx dispatch only one incoming websocket connection per pod and in case of lack of available pods, refuses the incoming connection ?</p>

user1886318
<p>I'm not super familiar with the Kubernetes Nginx ingress setup, but assuming it exposes some of the Nginx configuration options for setting up groups of servers, in the <code>server</code> function there's a parameter called <code>max_conns</code> that will let you limit the number of connections to a given server. Assuming there's a mapping in the ingress controller, it should be possible to set <code>max_conns=1</code> for each server that's getting created and added to the Nginx configuration under the hood.</p>

<p><a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server" rel="nofollow noreferrer">http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server</a></p>

<p>Edit: a little cursory research and it looks like this is indeed possible. It looks like you can specify this in a <code>ConfigMap</code> as <code>nginx.org/max-conns</code> according to the master list of parameters here: <a href="https://github.com/nginxinc/kubernetes-ingress/blob/master/docs/configmap-and-annotations.md" rel="nofollow noreferrer">https://github.com/nginxinc/kubernetes-ingress/blob/master/docs/configmap-and-annotations.md</a></p>
