7

I try to use haproxy as load balance and haproxy-ingress as ingress controller in k8s.

my load balance config:

frontend MyFrontend_80
    bind    *:80
    bind    *:443
    mode    tcp
    default_backend         TransparentBack_https

backend TransparentBack_https
        mode                            tcp
        balance roundrobin
        option ssl-hello-chk
        server                  MyWebServer1 10.5.5.53
        server                  MyWebServer2 10.5.5.54
        server                  MyWebServer3 10.5.5.55

Ingress file:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: li
  namespace: li
  annotations:
    # add an annotation indicating the issuer to use.
    cert-manager.io/cluster-issuer: "letsencrypt-staging"
    #haproxy.org/forwarded-for: true
    kubernetes.io/ingress.class: haproxy
    ingress.kubernetes.io/ssl-redirect: "true"
spec:
  rules:
  - host: a.b.c
    http:
      paths:
      - path: /storage
        backend:
          serviceName: li-frontend
          servicePort: 80
  tls:
  - hosts:
    - a.b.c
    secretName: longhorn-ui-tls

li-frontend is a dashboard ui service.

All is ok when I set the path field to blank in my ingress. and page is not normal when the path field seted to /storage or any non blank value.

I find some link not get correct position, e.g.

requst             correct value
/main.js           /storage/main.js

I found this in nginx-ingress:

#nginx.ingress.kubernetes.io/configuration-snippet: |
#rewrite ^/main(.*)$ /storage/main$1 redirect;

Does haproxy-ingress has same function? I try these, but no effect:

ingress.kubernetes.io/app-root: /storage
ingress.kubernetes.io/rewrite-target: /storage

In addition, I use rewrite in nginx-ingress, but it don't work on websocket.

Sorry for my pool english.

Yang Jie
  • 71
  • 1
  • 2
  • hi, haproxy-ingress has `app-root` config key, doc [here](https://haproxy-ingress.github.io/docs/configuration/keys/#configuration-keys) (no direct link to `app-root` atm). Perhaps you are using kubernetes ingress from haproxy tech? – Joao Morais May 29 '20 at 11:54

1 Answers1

5

for HAProxy:

you have to use haproxy annotation:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: web-ingress
  namespace: default
  annotations:
    # replace all paths with /
    haproxy.org/path-rewrite: "/"

    # remove the prefix /foo... "/bar?q=1" into "/foo/bar?q=1"
    haproxy.org/path-rewrite: (.*) /foo\1

    # add the suffix /foo ... "/bar?q=1" into "/bar/foo?q=1"
    haproxy.org/path-rewrite: ([^?]*)(\?(.*))? \1/foo\2

    # strip /foo ... "/foo/bar?q=1" into "/bar?q=1"
    haproxy.org/path-rewrite: /foo/(.*) /\1
spec:
  # ingress specification...

Ref: => https://www.haproxy.com/documentation/kubernetes/1.4.5/configuration/ingress/

Gans
  • 76
  • 1
  • 5
  • Thanks Bro ... this really saved my life .... using haproxy.org/path-rewrite: "/" helped me to direct request correctly _/\\_ – Nitin G Sep 25 '21 at 11:57
  • To me, it seems impossible to specify the same annotation key more than once. Can I create more than one rewrite target using this approach? – dosmanak Oct 11 '22 at 15:26