<p>I got the task to setup a Kubernetes setup in place 2 days ago with no background in that technology. So sorry if my questions or setup are not good.</p>

<p>The topology is quite simple, a <em>public IP</em>, a dedicated <em>HA proxy</em> configured to forward requests to a <strong>Kubernetes services</strong> containing a deployment of 2 pods. (Stickiness required!)</p>

<pre><code> Service setup
   {
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "api-admin2",
    "namespace": "default",
    "selfLink": "/api/v1/namespaces/default/services/api-admin2",
    "uid": "98121d0d-698b-11e8-8d90-262e68d4dba8",
    "resourceVersion": "245163",
    "creationTimestamp": "2018-06-06T13:14:50Z",
    "labels": {
      "app": "api-admin"
    },
    "annotations": {
      "service.beta.kubernetes.io/azure-load-balancer-internal": "true"
    }
  },
  "spec": {
    "ports": [
      {
        "protocol": "TCP",
        "port": 80,
        "targetPort": 6543,
        "nodePort": 31302
      }
    ],
    "selector": {
      "app": "api-admin"
    },
    "clusterIP": "10.100.22.118",
    "type": "LoadBalancer",
    "sessionAffinity": "ClientIP",
    "externalTrafficPolicy": "Local",
    "healthCheckNodePort": 32660,
    "sessionAffinityConfig": {
      "clientIP": {
        "timeoutSeconds": 10800
      }
    }
  },
  "status": {
    "loadBalancer": {
      "ingress": [
        {
          "ip": "10.100.21.97"
        }
      ]
    }
  }
}
</code></pre>

<p>The traffic arrives on pods but not in round robin, the entire traffic goes to the same pod. To have traffic going to another pod, I have to stop the one getting it... Which is not the purpose of this...</p>

<p>Any idea how to have the traffic properly loadbalanced with stickiness ? </p>

<p>Thanks !</p>

<p>from the service documentation for <a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs" rel="nofollow noreferrer">proxy mode: IPVS</a>: </p>

<blockquote>
  <p>In any of these proxy model, any traffic bound for the Service’s
  IP:Port is proxied to an appropriate backend without the clients
  knowing anything about Kubernetes or Services or Pods. <code>Client-IP</code> based
  session affinity can be selected by setting
  service.spec.sessionAffinity to <code>“ClientIP”</code> (the default is <code>“None”</code>),
  and you can set the max session sticky time by setting the field
  <code>service.spec.sessionAffinityConfig.clientIP.timeoutSeconds</code> if you have
  already set <code>service.spec.sessionAffinity to “ClientIP”</code> (the default is
  “10800”).</p>
</blockquote>

<p>In your configuration the session affinity which is responsible for choosing the pod is set to clientIP which means 10800 is the sticky time, all the traffic will be forwarded to the same pod for 3 hours if they are coming from the same client. </p>

<p>If you want to specify time, as well, this is what needs to be changed:</p>

<pre><code> sessionAffinityConfig:
    clientIP:
      timeoutSeconds: _TIME_
</code></pre>

<p>This will allow you to change the time of sickness, so if you changed <em>TIME</em> to 10 the service will switch pods every 10 seconds. </p>
