Home > Net >  Request Header based routing (User Agent) using Ingress in Kubernetes
Request Header based routing (User Agent) using Ingress in Kubernetes

Time:08-17

I hope you all are doing well. I am using DB less kong as gateway in kubernetes and the use case i have is to redirect traffic from browser to URL where they can download Electron app and if the traffic is from Electron app it redirects to the front end . I am using ingress for routing. Can anyone share an example of how to do it. Regards

CodePudding user response:

You can try to redirect if "user agent" contains the desired "agent" name.

ingress:
  enabled: true
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    cert-manager.io/cluster-issuer: letsencrypt-issuer
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header l5d-dst-override $service_name.$namespace.svc.cluster.local:$service_port;
      grpc_set_header l5d-dst-override $service_name.$namespace.svc.cluster.local:$service_port;
    nginx.ingress.kubernetes.io/server-snippet:  |
      if ($http_user_agent ~* "(Electron)" ) { 
        rewrite / https://frontendapp.example.com permanent;
      }
  hosts:
    - host: test.exmaple.com
      paths:
        - path: /
          pathType: Prefix
  tls:
    - secretName: test-tls
      hosts:
        - test.example.com

This will redirect the call if the user agent contain Electron, otherwise serve the default response, and redirect to https://frontendapp.example.com

CodePudding user response:

Should the following configuration work if i return 404 in case of firefox browser. I am using on premise offline Kubernetes cluster (security purpose).

  • Related