<p>I have a v1.8.4 deployment running nginx ingress controller. I had an ingress which works fine. But now I am trying to enable sticky sessions in it. I used <code>kubectl edit ing mying</code> to add these annotations:</p>

<pre><code>nginx.ingress.kubernetes.io/affinity: cookie
nginx.ingress.kubernetes.io/session-cookie-hash: md5
nginx.ingress.kubernetes.io/session-cookie-name: foobar
</code></pre>

<p>But sticky sessions are still not working. Nginx config does not have anything about sticky sessions. Also, <code>kubectl describe ing mying</code> does not show the annotations. What is going wrong here?</p>

<p>I also tried the example for sticky sessions <a href="https://github.com/kubernetes/ingress-nginx/tree/27c863085e2503e5f3249b596f24529fc2488baa/docs/examples/affinity/cookie" rel="nofollow noreferrer">here</a>.
Describing the ingress does not show the annotations.</p>

<p>Because item host(in ingress.yml) cannot be empty or wildzard (*.example.com).</p>

<p>Make sure your host such as test.example.com(if u don't have dns, please config it in your local hosts),then test </p>

<pre><code>curl -I  http://test.example.com/test/login.jsp
</code></pre>

<p>then u will see</p>

<pre><code>Set-Cookie: route=ebfcc90982e244d1d7ce029b98f8786b; Expires=Sat, 03-Jan-70 00:00:00 GMT; Max-Age=172800; Domain=test.example.com; Path=/test; HttpOnly
</code></pre>

<p>The official example：</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-test
  annotations:
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "route"
    nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"

spec:
  rules:
  - host: stickyingress.example.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /
</code></pre>
