Kong / kubernetes-ingress-controller

:gorilla: Kong for Kubernetes: The official Ingress Controller for Kubernetes.
https://docs.konghq.com/kubernetes-ingress-controller/
Apache License 2.0
2.2k stars 590 forks source link

Routing an IBM AppConnect using Custom path #6321

Open Rockyjr-git opened 1 month ago

Rockyjr-git commented 1 month ago

Is there an existing issue for this?

Current Behavior

I have deployed IBM AppConnect in the Anthos Bare Metal Cluster and Kong Ingress Controller is deployed using Helm chart. I want to route the AppConnect using custom path (/foo) instead of root path (/). Curl -i http:///Echo is working, but blank is displayed with prefix /Echo. whereas it is working for root path. Please suggest the steps or any documents for the custom path routing. Tried using rewrite transformer, but it did not work. Screenshot 2024-07-16 180708

Expected Behavior

Expected to work on the Custom path (/Echo)

Steps To Reproduce

Anthos Bare metal Cluster on the Air Gapped Environment.

Kong Ingress Controller version

v3.1

Kubernetes version

v1.27

Anything else?

No response

randmonkey commented 1 month ago

Do you want the requests to /Echo/* to be forwarded to /foo/*? You can use the konghq.com/rewrite annotation: https://docs.konghq.com/kubernetes-ingress-controller/latest/guides/requests/rewrite-annotation/. The feature needs you to set RewriteURIs feature gate to true. KIC 3.1 supports the feature.

Rockyjr-git commented 1 month ago

@randmonkey Thanks for the suggestion.

IBM AppConnect web page is displaying blank screen after adding the annotation. Can you Please help me here.

Screenshot 2024-07-17 190243 Screenshot 2024-07-17 190159

randmonkey commented 1 month ago

@Rockyjr-git Looks like the URI in the request was not rewritten correctly. Did you enable the RewirteURIs feature gate? If the feature gate is not enabled, the rewrite does not take effect. Please look at this doc to configure feature gates in KIC: https://docs.konghq.com/kubernetes-ingress-controller/3.1.x/reference/feature-gates/.

Rockyjr-git commented 1 month ago

@randmonkey Rewriteuri is already enabled, IBM AppConnect is working on root path. I am trying to route to other than root path. rewrite-uri

randmonkey commented 1 month ago

@Rockyjr-git Similar to the example in the doc https://docs.konghq.com/kubernetes-ingress-controller/3.1.x/guides/requests/rewrite-annotation/ , you can define your Ingress like this to keep your path after the matched prefix:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ace-ingress-rewrite
  namespace: appconnect
  annotations:
    konghq.com/rewrite: "/$1"
    konghq.com/strip-path: "true"
spec:
  ingressClassName: kong
  rules:
  - http:
      paths:
      - path: /~/echo/(\w+)
        pathType: ImplementationSpecific
        backend:
          service:
            name: ace-service-7600
            port:
              number: 7600
Rockyjr-git commented 1 month ago

As suggested used the same Ingress yaml, but still the same blank web page. Screenshot 2024-07-18 134518 Screenshot 2024-07-18 134645

randmonkey commented 1 month ago

@Rockyjr-git You need to change pathType to ImplementationSpecific to make it work. The pathType should be ImplementationSpecific to tell that the path should be interpreted as a regular expression when it has the /~ prefix. Kong will match path of your requests with the regex (the parts of path after the /~ prefix, in this case /echo/(\w+)) and fill the part matched to the capture group (in this case the (\w+) which means matching any number of letters, digits and underscores _) into the $1 place.

Rockyjr-git commented 1 month ago

Thanks for quick response again, Am i missing anything here again. Screenshot 2024-07-22 191336 Screenshot 2024-07-22 191315

randmonkey commented 1 month ago

@Rockyjr-git Your configuration is right. Kong gateway itself is a REVERSE PROXY so configuration of rewrite URI does not affect your request from the browser to Kong gateway. So the URL displayed in your browser is not re-written. You can check the logs of your backend service to check the URI is successfully re-written if the logs are available.