<p>I'm running a wordpress / woocommerce site on GCE Kubernetes and having trouble scaling because of session persistence.</p>

<p>The LoadBalancer (GCE Ingress) sends all traffic to a reverse proxy that then sends the traffic to different services I have set up, one of which is wordpress. </p>

<p>If I use <code>SessionAffinity: ClientIP</code> on the WordPress service all of the traffic goes to one pod and the others are ignored. This seems to because the service is seeing the LoadBalancer's ip address rather than the Client's. This is in spite of  <code>externalTrafficPolicy: Local</code> set on both nginx reverse proxy and the wordpress NodePort services.</p>

<p>I've also tried using the wordpress service as the default backend and I managed to get traffic to go to all pods but lost session affinity.</p>

<p>The Ingress also performs TLS termination, which I've seen can effect ClientIP visibility, but I think that issue is resolved by the external traffic policy.</p>

<p>We are also using Cloudflare, I'm wondering if that could have an effect. But we are using the ngx_http_realip_module to try to get the correct Client IP address. </p>

<p>I had a similar issue in one of the PHP services deployed in my cluster. Sessions are evil :) but sometimes you do need to use them. You can cluster your session data in PHP in couple ways, so that you do not need to use sticky sessions on loadbalancer(s).</p>

<ul>
<li>shared RWX volume in your pod(s) that will keep the session files available to all instances in your deployment. Unless you use something like S3 for wordpress uploads, you probably already do something similar for binaries, as I suggest for session files.</li>
<li>session handler with Memcached or Redis as the session storage (this is what I have now)</li>
<li>you can even keep them in your MySQL, same as WP database, although I've seen that it can be of significant performance impact.</li>
</ul>

<p>You can find simple mamcache example <a href="http://php.net/manual/en/memcached.sessions.php" rel="noreferrer">here</a>. If you'd need a clustered storage, you could look into Redis clustering, or, as I would, into Couchbase</p>
