title: Kubernetes ingress controller strict round-robin
body: <p>I'm trying to set up an ingress controller in Kubernetes that will give me strict alternation between two (or more) pods running in the same service.</p>
  <p>My testing setup is a single Kubernetes node, with a deployment of two nginx pods.
  The deployment is then exposed with a NodePort service.</p>
  <p>I've then deployed an ingress contoller (I've tried both <a href="https://github.com/kubernetes/ingress-nginx" rel="nofollow noreferrer">Kubernetes Nginx Ingress Controller</a> and <a href="https://github.com/nginxinc/kubernetes-ingress" rel="nofollow noreferrer">Nginx Kubernetes Ingress Controller</a>, separately) and created an ingress rule for the NodePort service.</p>
  <p>I edited index.html on each of the nginx pods, so that one shows &quot;SERVER A&quot; and the other &quot;SERVER B&quot;, and ran a script that then <code>curl</code>s the NodePort service 100 times. It <code>grep</code>s &quot;SERVER x&quot; each time, appends it to an output file, and then tallies the number of each at the end.</p>
  <p>As expected, curling the NodePort service itself (which uses kube-proxy), I got completely random results-- anything from 50:50 to 80:20 splits between the pods.</p>
  <p>Curling the ingress controller, I consistently get something between 50:50 and 49:51 splits, which is great-- the default round-robin distribution is working well.</p>
  <p><strong>However</strong>, looking at the results, I can see that I've curled the same server up to 4 times in a row, but I need to enforce a strict alternation A-B-A-B. I've spent quite a researching this and trying out different options, but I can't find a setting that will do this. Does anyone have any advice, please?</p>
  <p>I'd prefer to stick with one of the ingress controllers I've tried, but I'm open to trying a different one, if it will do what I need.</p>