How to rewrite target to correct path in haproxy-ingress?

5/29/2020

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
haproxy-ingress
kubernetes
url-rewriting

0 Answers