how to Route 70% traffic to ExternalName service and append url?

12/27/2018

I want to route 70% percentage of my traffic coming to service A to an external end point and append the URL.

To achieve this I created an externalName type service which points to external endpoint and then use treafik ingress controller to divide the weight in percentage.

My service definition looks something like this:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: wensleydale
    spec:
      ports:
      - name: http
        targetPort: 80
        port: 80
      selector:
        app: cheese
        task: wensleydale

    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: test-service
    spec:
      type: ExternalName
      externalName: www.google.com
      ports:
      - name: http
        targetPort: 80
        port: 80
      selector:
        app: cheese
        task: test-service

Ingress.yaml:

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      annotations:
        traefik.ingress.kubernetes.io/service-weights: |
          test-service: 70%
          wensleydale: 30%
      name: cheese
    spec:
      rules:
      - http:
          paths:
          - backend:
              serviceName: test-service
              servicePort: 80
            path: /
          - backend:
              serviceName: wensleydale
              servicePort: 80
            path: /

What I want in addition is when traffic goes to test-service, I want to append path.
In my test-service I want the URL to be something like www.google.com/something

I'm open to use other tools to achieve this.

-- Aakash Singhal
istio
kubernetes
kubernetes-ingress
traefik

2 Answers

12/27/2018

You can do the following:

  1. Use Istio Ingress Gateway instead of a traefik gateway. Istio Ingress Gateway is the recommended way for Ingress control in Istio. See https://istio.io/docs/tasks/traffic-management/ingress/

  2. In the corresponding Virtual Service, use HTTPRewrite directive https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPRewrite :

rewrite: uri: /something

-- Vadim Eisenberg
Source: StackOverflow

12/27/2018

Unfortunately you are hitting a limitation. The traefik ingress docs state this condition on weighting - "The associated service backends must share the same path and host". (https://docs.traefik.io/user-guide/kubernetes/#traffic-splitting) So you can't rewrite the path just for one of the weighted targets. The limitation comes from https://github.com/kubernetes/kubernetes/issues/25485 so you can see the suggestions there, many of which mention istio. (See also https://github.com/zalando/skipper/issues/324)

A simple solution might be to deploy another proxy into the cluster and use that to rewrite the target to the internal service that you can't change. Then your Ingress would be able to use the same path for both.

Another way would be to look at configuring a proxy using a conf file rather than ingress annotations. Configuration snippets may be enough to achieve this but I am not sure. I suspect you'd be best to deploy an additional proxy and expose it externally and configure it directly (avoiding the Ingress abstraction).

-- Ryan Dawson
Source: StackOverflow