1

I have following config in my nginx:

location / {
    if ($request_uri ~* ^/checkout/(dev-dist|dist|images|js|libs|resources|angular4-hybrid|bundle.js)) {

proxy_pass http://static-qa-uscentral1.company.com/hybrid/live$request_uri;
            break;
        }
}

I am trying to replicate this in istio's virtual service

I have written following virtual service to match this regex:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: routes-static
  namespace: mui-relqa
spec:
  gateways:
  - my-gateway
  hosts:
  - "*"
  http:
  - match:
    - uri:
        regex: '^./checkout/(dev-dist|dist|images|js|libs|resources|angular4-hybrid|bundle.js).*$'
    redirect:
      authority: static-qa-uscentral1.company.com
      uri: /hybrid/live

Few things I would lobe to have clarity on:

  1. how to use that $request_uri used in nginx config to replicate in virtual service

  2. using the above virtual service it will totally redirect the calls to "static-qa-uscentral1.company.com" which I have mentioned in "authority" parameter in "virtualservice" yaml. How can I achieve what nginx does during proxy_pass which doesnot change the URL but still gets the content of redirected URL.

Stunn3r
  • 53
  • 1
  • 12

1 Answers1

0

You could probably use Istio Envoy filter, you might want to check other rewrite options for Envoy HTTP routing.

You can have a look at Katacoda Migrating from NGINX to Envoy Proxy. In step 4 they show example of proxy_pass.

Regex will match ECMAscript style regex-based, you can even have a look into Istio Virtual Service source code.

You would need to either remove Istio and setup NGINX Ingress Controller instead, or setup the Ingress Controller behind Istio so it would redirect and/or proxy the traffic based on nginx.conf or using Nginx Annotations.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/server-snippet: |
 set $agentflag 0;

 if ($http_user_agent ~* "(Mobile)" ){
 set $agentflag 1;
 }

 if ( $agentflag = 1 ) {
 return 301 https://m.example.com;
 }

Update

This was mentioned by the OP, Envoy also supports Lua scripting that allows essentially injecting arbitrary code in the proxy to process requests.

Crou
  • 10,232
  • 2
  • 26
  • 31
  • I have been reading more on how to get this done using istio components only. I found "envoyFilters" in which we can write LUA code to handle something like this. Do you have any suggestions on using envoyFilters. I really cant go back to nginx ingress controller. All our exercise is to remove nginx ingress completely and use only istio-ingressgateway. Hence istio should do TLS termination, routing, header manipulation, conditional headers everything. – Stunn3r Jun 20 '19 at 12:04
  • @Stunn3r, You are correct I've updated my answer. Maybe this will be more helpful. – Crou Jul 01 '19 at 14:44