Ingress Rewrite not working in GKE, HAProxy Controller

11/25/2019

I have an app which has multiple APIs defined as: - /CreateUser - /DeleteUser - /UpdateUser The API accepts JSON data as an input body in the request.

I have deployed the app, HAProxy Ingress Controller in GKE. I would like to do the following using ingress rewrite. But not sure what to implement.

User will request using url: http:///user-reg/create-user/CreateUser/ http:///user-reg/delete-user/DeleteUser/

The above requests will be rewritten and will hit the app APIs (/CreateUser or /DeleteUser etc.)

I have tried below but it's not working.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: fanout-ingress-haproxy
  namespace: xyz-product
  labels:                     # Labels that will be applied to this resource
    app: prod-user-reg-app
  annotations:
    haproxy.org/forwarded-for: "enabled"
    haproxy.org/load-balance: "roundrobin"
    haproxy.org/ingress.class: "haproxy"
    kubernetes.io/ingress.global-static-ip-name: prod-reg-static-ip  #Defined in GCP platform. A Static IP needs to be created in the GCP.
    haproxy.ingress.kubernetes.io/rewrite-target: /$3
spec:
  rules:
#   - host: demo.apps.myproduct.com
   - http:
      paths:
      - path: /user-reg/create-user(/|$)(.*)
        backend:
          serviceName: prod-user-reg-create-app
          servicePort: 8081

When I trying to apply the Ingress the below error is happening:

Ingress Error

Why this error is getting generated? How to resolve? And what would be the rewrite rule if I want to achieve the above?

On another note, I am using static IP to access the app via loadbalancer. Static IP is attached to the loadbalancer. If you see in the Ingress yaml file I have disabled the hostname. If I enable the hostname then from my desktop PostMan app I am not to request the app and getting 504 error. I have even tried to add the Hostname in the GCP Cloud DNS but still no luck.

Cloud DNS

How the Hostname is being used in the Ingress YAML? How can I send a request to the app over the internet using my desktop PostMan application?

Thanks in advance. - Suvendu

-- Suvendu Mandal
google-kubernetes-engine
haproxy
kubernetes-ingress

0 Answers