<p dir="auto">Hi,</p>
<p dir="auto">ClientIP affinity seems to have some issue on Container Engine. Once you scale down a replicas set linked to a service with session affinity and GCE external load balancer, sticky session doesn't work anymore.<br>
I tried to create a new cluster to be sure it wasn't any configuration related issue.</p>
<p dir="auto">Steps to reproduce :</p>
<ul dir="auto">
<li>Create a container cluster</li>
<li>Add a replica set (with a pod running http service that show a random id defined on launch) and a service with sessionAffinity set to "ClientIP"  and type "LoadBalancer"</li>
<li>scale replicaset to 0. Scale it back to 5.</li>
<li>Try to go on the url exposed on computer. Try the same thing on your phone on another network (for example your mobile data).<br>
The id on the phone change each time your reload the computer page.</li>
</ul>
<p dir="auto">Did i miss something ?</p>
<p dir="auto">Thanks for your help.</p>
<p dir="auto">It seems like the sessionAffinity stops working if the rc is deleted and created again after the service was created.  (Cluster with two machines on GCE)</p>
<p dir="auto">Steps to reproduce:</p>
<ul dir="auto">
<li>
<ol dir="auto">
<li>Used following files:</li>
</ol>
</li>
</ul>
<p dir="auto">ServerName.yaml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="apiVersion: v1
kind: ReplicationController
metadata:
  name: servername
  labels:
    name: servername
spec:
  replicas: 10
  selector:
    name: servername
  template:
    metadata:
      labels:
        name: servername
    spec:
      containers:
      - name: app
        image:  fibheap/printhostname
        imagePullPolicy: &quot;Always&quot;
        ports:
             - containerPort: 80"><pre class="notranslate"><code class="notranslate">apiVersion: v1
kind: ReplicationController
metadata:
  name: servername
  labels:
    name: servername
spec:
  replicas: 10
  selector:
    name: servername
  template:
    metadata:
      labels:
        name: servername
    spec:
      containers:
      - name: app
        image:  fibheap/printhostname
        imagePullPolicy: "Always"
        ports:
             - containerPort: 80
</code></pre></div>
<p dir="auto">ServerNameSv.yaml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="apiVersion: v1
kind: Service
metadata:
  name: servername
  labels:
    name: servername
spec:
  ports:
    # the port that this service should serve on
    - port: 80
      targetPort: 80
  selector:
    name: servername
  type: LoadBalancer
  sessionAffinity: ClientIP"><pre class="notranslate"><code class="notranslate">apiVersion: v1
kind: Service
metadata:
  name: servername
  labels:
    name: servername
spec:
  ports:
    # the port that this service should serve on
    - port: 80
      targetPort: 80
  selector:
    name: servername
  type: LoadBalancer
  sessionAffinity: ClientIP
</code></pre></div>
<p dir="auto">Dockerfile</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="FROM google/nodejs

WORKDIR /app

ADD ./main.js /app/main.js

EXPOSE 80
CMD [&quot;node&quot;, &quot;--harmony&quot;, &quot;./main.js&quot;]"><pre class="notranslate"><code class="notranslate">FROM google/nodejs

WORKDIR /app

ADD ./main.js /app/main.js

EXPOSE 80
CMD ["node", "--harmony", "./main.js"]
</code></pre></div>
<p dir="auto">main.js</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="// Load the http module to create an http server.
var http = require('http');
var os = require('os');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (req, res) {
  res.writeHead(200, {&quot;Content-Type&quot;: &quot;text/plain&quot;});
  var ip = req.headers['x-forwarded-for'] ||
     req.connection.remoteAddress ||
     req.socket.remoteAddress ||
     req.connection.socket.remoteAddress;

  res.end(&quot;CIP:&quot; + ip + &quot;  Remote Server:&quot; + os.hostname());
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(80);

// Put a friendly message on the terminal
console.log(&quot;Server running at http://127.0.0.1:80/&quot;);"><pre class="notranslate"><code class="notranslate">// Load the http module to create an http server.
var http = require('http');
var os = require('os');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (req, res) {
  res.writeHead(200, {"Content-Type": "text/plain"});
  var ip = req.headers['x-forwarded-for'] ||
     req.connection.remoteAddress ||
     req.socket.remoteAddress ||
     req.connection.socket.remoteAddress;

  res.end("CIP:" + ip + "  Remote Server:" + os.hostname());
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(80);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:80/");
</code></pre></div>
<hr>
<ul dir="auto">
<li>
<ol start="2" dir="auto">
<li>create rc and service (describe service to get IP and assure ClientIP is set)</li>
</ol>
</li>
<li>
<ol start="3" dir="auto">
<li>curl multiple times from loadbalancer ip -&gt; pod name should stay the same</li>
</ol>
</li>
<li>
<ol start="4" dir="auto">
<li>delete rc and create again</li>
</ol>
</li>
<li>
<ol start="5" dir="auto">
<li>curl again multiple time -&gt; pod name changes</li>
</ol>
</li>
</ul>
<p dir="auto">This is in particularly a show stoping bug for us as we cannot recreate the service without loosing the external IP. <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="90811174" data-permission-text="Title is private" data-url="https://github.com/kubernetes/kubernetes/issues/10323" data-hovercard-type="issue" data-hovercard-url="/kubernetes/kubernetes/issues/10323/hovercard" href="https://github.com/kubernetes/kubernetes/issues/10323">#10323</a></p>
<p dir="auto">Please let me know if that helps for reproducing. Please feel free to use docker repository fibheap/printhostname directly</p>