Service Topology is a mechanism in Kubernetes to route traffic based upon the Node topology of the cluster. For example, you can configure a Service to route the traffic to endpoints on specific nodes, or even based on the region or availability zone of the node’s location.

To enable this new feature in your Kubernetes cluster, use the feature gates --feature-gates="ServiceTopology=true,EndpointSlice=true" flag. After enabling, you can control Service traffic routing by defining the topologyKeys field in the Service API object.

In the following example, a Service defines topologyKeys to be routed to endpoints only in the same zone:

apiVersion: v1
kind: Service
metadata:
  name: my-konvoy-service
  namespace: default
spec:
  selector:
    app: MyKonvoyApp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9191
  topologyKeys:
  - "topology.kubernetes.io/zone"
CODE

If the value of the topologyKeys field does not match any pattern, the traffic is rejected.