kubernetes-sigs / gateway-api

Repository for the next iteration of composite service (e.g. Ingress) and load balancing APIs.
https://gateway-api.sigs.k8s.io
Apache License 2.0
1.85k stars 480 forks source link

pathPrefix not working #2136

Closed Yeroha closed 1 year ago

Yeroha commented 1 year ago

I have some backend services (Java Spring boot). We using one endpoint for access to api For example -

https://test-api.example.com/service1
https://test-api.example.com/service2
https://test-api.example.com/service**

We have HTTPRoute:

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: api-prod-other-1
  namespace: master
spec:
  parentRefs:
  - name: k8s-gateway
    namespace: gateways-list
  hostnames: 
    - "test-api.example.com"
  rules:
    - matches:
      - path:
          value: /agent-polis
      backendRefs:
      - name: agent-polis-master
        port: 80
    - matches:
      - path:
          type: PathPrefix
          value: /telegram-bot
      backendRefs:
      - name: alert-bot-master
        port: 80

Each service has health check (for java Spring Boot - /actuator/health) When we trying running endpoint https://test-api.example.com/telegram-bot/actuator/health getting HTTP/2.0 404 Not Found Logs: [2023-06-22T09:15:54.775Z] "GET /telegram-bot/actuator/health/ HTTP/2" 404 - via_upstream - "-" 0 118 5 4 "10.44.91.192" "xh/0.17.0" "0b6076b5-cbea-9370-a3c5-398b69129648" "test-api.example.com" "10.44.247.15:8080" outbound|80||alert-bot-master.master.svc.cluster.local 10.44.247.4:58382 10.44.247.4:443 10.44.91.192:49643 test-api.example.com master.api-prod-other-1.1 Because java service provides only /actuator/health I try added:

filters:
        - type: RequestRedirect
          requestRedirect:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /

not working for me. Please help!

Yeroha commented 1 year ago

Fixed. We used URLRewrite filter

robscott commented 1 year ago

Glad you were able to figure this out, closing this one.