0

I have a problem when creating an ingress to expose services running on the GKE cluster, my problem is that the path services that I configured are not pointing to the correct url like the following example :


/customer
# my expectation is to http://[customerapp-service]/
# instead of http://[customerapp-service]/customer

/supplier
# my expectation is to http://[supplierapp-service]/
# instead of http://[supplierapp-service]/supplier

this is the yaml file for ingress that I created :

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: saas-ingress
  annotations:
    kubernetes.io/ingress.class: "gce"
    kubernetes.io/ingress.allow-http: "true"
spec:
  rules:
  - http:
      paths:
      - path: /customer
        pathType: ImplementationSpecific
        backend:
          service:
            name: customerapp-service
            port:
              number: 9001
      - path: /supplier
        pathType: ImplementationSpecific
        backend:
          service:
            name: supplierapp-service
            port:
              number: 9000
              

i have tried to change pathType to Prefix instead of ImplementationSpecific but still not solve my problem

  • GCE ingress controller does not support path rewriting. See this answer: https://stackoverflow.com/questions/71019436/how-to-configure-gce-to-route-paths-rewrite-target-in-nginx – user2311578 Nov 25 '22 at 16:08

1 Answers1

0

As mentioned in the comments, the GCE Ingress controller does not support path rewrites. You might want to look at using host rules instead. You could create two DNS A records (e.g. customerapp.mydomain.com and supplierapp.mydomain.com) and point then to the IP address of the Ingress resource (you'd want to use a static IP as well)

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: saas-ingress
  annotations:
    kubernetes.io/ingress.class: "gce"
    kubernetes.io/ingress.allow-http: "true"
    kubernetes.io/ingress.global-static-ip-name: my-static-ip
spec:
  rules:
  - host: "customerapp.mydomain.com"
    http:
      paths:
      - path: "/bar"
        backend:
          service:
            name: customerapp-service
            port:
              number: 9001
  - host: "supplierapp.mydomain.com"
    http:
      paths:
      - path: "/"
        backend:
          service:
            name: supplierapp-service
            port:
              number: 9000
Gari Singh
  • 11,418
  • 2
  • 18
  • 41