Defining a split traffic route in Kuma/Envoy

274 views Asked by At

I'm trying to create a demo of a service mesh using Kuma, and I'm confused about how to configure a traffic traffic split when viewing the example in the docs. I have two versions of a microservice which return different results depending on an environment variable which is defined in the Kubernetes config. And the service associated with the pods is configured by its config which pod to use (not sure if this the right way to do this):

apiVersion: v1
kind: Pod
metadata:
  name: dntapi-mil
  namespace: meshdemo
  labels:
    uservice: dntapi
    format: military
spec:
  containers:
  - name: dntapi
    image: meshdemo:dntapi
    ports:
    - name: http
      containerPort: 4000
    env:
      - name: MILITARY
        value: "true"

---

apiVersion: v1
kind: Pod
metadata:
  name: dntapi-std
  namespace: meshdemo
  labels:
    uservice: dntapi
    format: standard
spec:
  containers:
  - name: dntapi
    image: meshdemo:dntapi
    ports:
    - name: http
      containerPort: 4000
    env:
      - name: MILITARY
        value: "false"

---

apiVersion: v1
kind: Service
metadata:
  name: dntapi
  namespace: meshdemo
spec:
  selector:
    uservice: dntapi
    format: military
  ports:
  - protocol: TCP
    port: 4000
    targetPort: 4000

This works from a purely K8s perspective if I change the selector on the service, but looking at the Kuma example of split traffic:

  conf:
    split:
      - weight: 90
        destination:
          kuma.io/service: redis_default_svc_6379
          version: '1.0'
      - weight: 10
        destination:
          kuma.io/service: redis_default_svc_6379
          version: '2.0'

To what is "version" referring when associated with the service (and I have to admit that I don't understand how there could be two services with the same identifier). Are these K8s selectors?

I should add that when I inspect services with kumactl, I see two for this microservice, one without a port name:

dntapi-std_meshdemo_svc          Online   1/1
dntapi_meshdemo_svc_4000         Online   1/1

Thanks in advance.

1

There are 1 answers

0
Scott Lowe On BEST ANSWER

Change your Service definition to use only a label common to both variations of the workload (looks like this would be uservice: dntapi). Then use the format label as "tags" in the Kuma TrafficRoute destination, just as the example uses the version tag (which is/can be derived directly from the Kubernetes labels). This would allow you to control what percentage of traffic is sent to Pods labeled format: standard and what percentage is sent to Pods labeled format: military.

See https://github.com/kumahq/kuma-demo/tree/master/kubernetes for another example. Scroll down to the "Traffic Routing" section; that example does exactly what I describe above.