<p>When setting the following annotations:</p>

<pre><code>nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "ALPHA"
nginx.ingress.kubernetes.io/session-cookie-path: /
</code></pre>

<p>Where do they end up in nginx.conf?</p>

<p>I'm comparing nginx.conf before and after by using a difftool but the config is identical.</p>

<p>If I e.g. add a:</p>

<pre><code>nginx.ingress.kubernetes.io/rewrite-target /$1
</code></pre>

<p>nginx.conf gets updated.</p>

<p>Results in:</p>

<pre><code>rewrite "(?i)/myapp(/|$)(.*)" /$2 break;
</code></pre>

<p>The short answer is that these settings exist in memory of the <a href="https://github.com/openresty/lua-nginx-module" rel="nofollow noreferrer">lua nginx module</a> used by nginx-ingress.</p>

<p>The longer answer and explanation of how this works is in the documentation at <a href="https://kubernetes.github.io/ingress-nginx/how-it-works" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/how-it-works</a>. Particularly:</p>

<blockquote>
  <p>Though it is important to note that we don't reload Nginx on changes that impact only an upstream configuration (i.e Endpoints change when you deploy your app). We use <a href="https://github.com/openresty/lua-nginx-module" rel="nofollow noreferrer">https://github.com/openresty/lua-nginx-module</a> to achieve this. Check below to learn more about how it's done.</p>
</blockquote>

<p>The referenced below section then mentions:</p>

<blockquote>
  <p>On every endpoint change the controller fetches endpoints from all the services it sees and generates corresponding Backend objects. It then sends these objects to a Lua handler running inside Nginx. The Lua code in turn stores those backends in a shared memory zone. Then for every request Lua code running in balancer_by_lua context detects what endpoints it should choose upstream peer from and applies the configured load balancing algorithm to choose the peer.</p>
</blockquote>

<p>The backend object in question has the session and cookie information. The code for receiving this is at <a href="https://github.com/kubernetes/ingress-nginx/blob/57a0542fa356c49a6afb762cddf0c7dbf0b156dd/rootfs/etc/nginx/lua/balancer/sticky.lua#L151-L166" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/blob/57a0542fa356c49a6afb762cddf0c7dbf0b156dd/rootfs/etc/nginx/lua/balancer/sticky.lua#L151-L166</a>. In particular, there is this line in the sync function:</p>

<pre><code>ngx_log(INFO, string_format("[%s] nodes have changed for backend %s", self.name, backend.name))
</code></pre>

<p>Which indicates you should see a log entry for the change in the nginx log when making a change like this to the backends.</p>
