<p>I have a haproxy as a load balancer running in k8s with a route to a service with two running pods. I want the server naming inside haproxy to correspond to the pod names behind my service. If I'm not mistaken the following configmap / annotation value should do exactly this: <code>https://haproxy-ingress.github.io/docs/configuration/keys/#backend-server-naming</code>. But for me it doesn't and for the life of me I can't find out why. The relevant parts of my configuration look like this:</p>
<p>controller deployment:</p>
<pre><code>kind: Deployment
metadata:
  labels:
    run: haproxy-ingress
  name: haproxy-ingress
  namespace: haproxy-controller
spec:
  replicas: 2
  selector:
    matchLabels:
      run: haproxy-ingress
  template:
    metadata:
      labels:
        run: haproxy-ingress
    spec:
      serviceAccountName: haproxy-ingress-service-account
      containers:
        - name: haproxy-ingress
          image: haproxytech/kubernetes-ingress
          args:
            - --configmap=haproxy-controller/haproxy-ingress
            - --configmap-errorfiles=haproxy-controller/errorfile-conf
            - --default-ssl-certificate=haproxy-controller/haproxy-tls
            - --ingress.class=haproxy
</code></pre>
<p>controller service:</p>
<pre><code>kind: Service
metadata:
  labels:
    run: haproxy-ingress
  name: haproxy-ingress
  namespace: haproxy-controller
spec:
  selector:
    run: haproxy-ingress
  type: ClusterIP
  ports:
    - name: https
      port: 443
      protocol: TCP
      targetPort: 443
</code></pre>
<p>controller configmap:</p>
<pre><code>kind: ConfigMap
metadata:
  name: haproxy-ingress
  namespace: haproxy-controller
data:
  server-ssl: &quot;true&quot;
  scale-server-slots: &quot;2&quot;
  cookie-persistence: &quot;LFR_SRV&quot;
  backend-server-naming: &quot;pod&quot;
  backend-config-snippet: |
    cookie LFR_SRV indirect nocache insert maxidle 10m httponly secure
</code></pre>
<p>backend server ingress:</p>
<pre><code>kind: Ingress
metadata:
  name: liferay-dxp
  namespace: backend
  annotations:
    kubernetes.io/ingress.class: &quot;haproxy&quot;
spec:
  tls:
    - secretName: backend-tls
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: backend
                port:
                  number: 443
</code></pre>
<p>The generated backend part of the haproxy.conf looks like this:</p>
<pre><code>  mode http
  balance roundrobin
  option forwardfor
  cookie LFR_SRV indirect nocache insert
  ###_config-snippet_### BEGIN                                                                                                                                          
  cookie LFR_SRV indirect nocache insert maxidle 10m httponly secure
  ###_config-snippet_### END
  server SRV_1 10.xx.xx.xx:443 check ssl alpn h2,http/1.1 weight 128 cookie SRV_1 verify none
  server SRV_2 10.xx.xx.xx:443 check ssl alpn h2,http/1.1 weight 128 cookie SRV_2 verify none
</code></pre>
<p>Everything works fine except <code>backend-server-naming: &quot;pod&quot;</code>. I also can't get any of the session-cookie-* properties from <a href="https://haproxy-ingress.github.io/docs/configuration/keys/#affinity" rel="nofollow noreferrer">here</a> to work. Because of that I used the <code>backend-config-snippet</code> to overwrite the cookie line in the generated haproxy.conf with my custom one (I added <code>maxidle 10m httponly secure</code>). What am I doing wrong?</p>

<p>Here are a few hints to help you out solving your issue.</p>
<h2>Be sure you know the exact version of your haproxy-ingress controller:</h2>
<p>Looking at the manifest files you shared, it's hard to tell which exact version of <code>haproxy-ingress-controller</code> container you are running in your cluster (btw, it's against best practices in production envs to leave it w/o tag, read more on it <a href="https://kubernetes.io/docs/concepts/containers/images/#image-pull-policy" rel="nofollow noreferrer">here</a>).</p>
<p>For <code>backend-server-naming</code> configuration key to be working, minimum  the <code>v0.8.1</code> is required <a href="https://github.com/jcmoraisjr/haproxy-ingress/issues/469#issuecomment-583339894" rel="nofollow noreferrer">(it was backported)</a>.</p>
<p>Before you move on in troubleshooting, firstly please double check your ingress deployment for compatibility.</p>
<h2>My observations of &quot;backend-server-naming=pod&quot; behavior</h2>
<h3>Configuration dynamic updates:</h3>
<p>If I understand correctly the official documentation on this <a href="https://haproxy-ingress.github.io/docs/configuration/keys/#backend-server-naming" rel="nofollow noreferrer">configuration key</a>, setting a server naming of backends to pod names (<code>backend-server-naming=pod</code>) instead of <code>sequences</code>, does support a dynamic re-load of haproxy configuration, but does <strong>NOT</strong> support  as of now dynamic updates to haproxy run-time configuration to server names at backend section (it was explained by haproxy-ingress author <a href="https://github.com/jcmoraisjr/haproxy-ingress/issues/469#issuecomment-560022371" rel="nofollow noreferrer">here</a>, and <a href="https://github.com/jcmoraisjr/haproxy-ingress/issues/759#issuecomment-803169441" rel="nofollow noreferrer">here</a>)</p>
<p>It means you need to restart your haproxy-ingress controller instance first, to be able to see changes in backend's server names reflected at haproxy configuration, e.g. situations when new Pod replicas appear or POD_IP changed due the Pod crash (expect addition/updates of server entries based on sequence naming).</p>
<h3>Ingress Class:</h3>
<p>I have tested successfully (see test below) the <code>backend-server-naming=pod</code> setting on <code>v0.13.4</code>  with <a href="https://haproxy-ingress.github.io/docs/configuration/keys/#class-matter" rel="nofollow noreferrer">classified</a> Ingress type, based on <code>ingressClassName</code> field , rather than deprecated annotation <code>kubernetes.io/ingress.class</code>, as in your case:</p>
<p>I'm not claiming your configuration won't work (it should too), but it's important to know, that dynamic updates to configuration (this includes changes to backend configs) won't happen on unclassified Ingress resource or wrongly classified one, unless you're really running <code>v0.12</code> or newer version.</p>
<h2>Testing:</h2>
<pre><code># Ingress class 
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
  name: my-class
  annotations:
    ingressclass.kubernetes.io/is-default-class: &quot;true&quot;
spec:
  controller: haproxy-ingress.github.io/controller

# Demo Ingress resource
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    haproxy-ingress.github.io/backend-server-naming: &quot;pod&quot;
  name: echoserver
spec:
  ingressClassName: my-class
  rules:
  - http:
      paths:
      - backend:
          service:
            name: echoserver
            port:
              number: 8080
        path: /
        pathType: Prefix
</code></pre>
<p>HA proxy configuration with comment:</p>
<pre><code>backend default_echoserver_8080
    mode http
    balance roundrobin
    acl https-request ssl_fc
    http-request set-header X-Original-Forwarded-For %[hdr(x-forwarded-for)] if { hdr(x-forwarded-for) -m found }
    http-request del-header x-forwarded-for
    option forwardfor
    http-response set-header Strict-Transport-Security &quot;max-age=15768000&quot; if https-request
    # pod name start
    server echoserver-75d6f584bb-jlwb8 172.17.0.2:8080 weight 1 check inter 2s
    # pod name end
    server srv002 127.0.0.1:1023 disabled weight 1 check inter 2s
    server srv003 127.0.0.1:1023 disabled weight 1 check inter 2s
    server srv004 127.0.0.1:1023 disabled weight 1 check inter 2s
    ...
</code></pre>
