Istio ingress with httpRewrite failed to load additional resources

3/7/2018

On minikube VM I have two k8s services: service-v1 and service-v2. I have istio-ingress rule:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: forecast-ingress
  annotations:
    kubernetes.io/ingress.class: "istio"
spec:
  rules:

  - http:
      paths:
      - path: /v2/.*
        backend:
          serviceName: service-v2
          servicePort: 8080

  - http:
      paths:
      - path: /v1/.*
        backend:
          serviceName: service-v1
          servicePort: 8080

So when I access the /v1/endpoint it forwards the call to service-v1. In my application, I have a mapping for /endpoint and not for /v1/endpoint, so I have also an httpRewrite rule:

apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
  name: ingress-service-v2-rewrite
  namespace: default
spec:
  destination:
    name: service-v2
  match:
    request:
      headers:
        uri:
          prefix: /v2
  rewrite:
    uri: /
  route:
  - labels:
      version: "2.0"
---
apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
  name: ingress-service-v1-rewrite
  namespace: default
spec:
  destination:
    name: service-v1
  match:
    request:
      headers:
        uri:
          prefix: /v1
  rewrite:
    uri: /
  route:
  - labels:
      version: "1.0"

But now I have another issue: when I'm accessing /v1/endpoint from the browser, it makes another call to my service to another /endpoint2 and it gives me 404 as this endpoint can be accessed as /v1/endpoint2. And I can access /v1/endpoint2 from the browser. The only way that I can see to fix it is by changing the code to make a call to relative URL like this: ../endpoint1. Is this the only option? Are there any other options how to get around this issue?

-- Sergii Bishyr
istio
kubernetes-ingress
minikube
url-rewriting

0 Answers