Manage L7 traffic with cluster peering

This usage topic describes how to configure and apply the service-resolver configuration entry to set up redirects and failovers between services that have an existing cluster peering connection.

For Kubernetes-specific guidance for managing L7 traffic with cluster peering, refer to Manage L7 traffic with cluster peering on Kubernetes.

Service resolvers for redirects and failover

When you use cluster peering to connect datacenters through their admin partitions, you can use dynamic traffic management to configure your service mesh so that services automatically forward traffic to services hosted on peer clusters.

However, the service-splitter and service-router configuration entry kinds do not natively support directly targeting a service instance hosted on a peer. Before you can split or route traffic to a service on a peer, you must define the service hosted on the peer as an upstream service by configuring a failover in the service-resolver configuration entry. Then, you can set up a redirect in a second service resolver to interact with the peer service by name.

For more information about formatting, updating, and managing configuration entries in Consul, refer to How to use configuration entries.

Configure dynamic traffic between peers

To configure L7 traffic management behavior in deployments with cluster peering connections, complete the following steps in order:

  1. Define the peer cluster as a failover target in the service resolver configuration.

    The following examples update the service-resolver configuration entry in cluster-01 so that Consul redirects traffic intended for the frontend service to a backup instance in peer cluster-02 when it detects multiple connection failures.

    1. Kind = "service-resolver"
    2. Name = "frontend"
    3. ConnectTimeout = "15s"
    4. Failover = {
    5. "*" = {
    6. Targets = [
    7. {Peer = "cluster-02"}
    8. ]
    9. }
    10. }
    1. {
    2. "ConnectTimeout": "15s",
    3. "Kind": "service-resolver",
    4. "Name": "frontend",
    5. "Failover": {
    6. "*": {
    7. "Targets": [
    8. {
    9. "Peer": "cluster-02"
    10. }
    11. ]
    12. }
    13. },
    14. "CreateIndex": 250,
    15. "ModifyIndex": 250
    16. }
    1. apiVersion: consul.hashicorp.com/v1alpha1
    2. kind: ServiceResolver
    3. metadata:
    4. name: frontend
    5. spec:
    6. connectTimeout: 15s
    7. failover:
    8. '*':
    9. targets:
    10. - peer: 'cluster-02'
    11. service: 'frontend'
    12. namespace: 'default'
  2. Define the desired behavior in service-splitter or service-router configuration entries.

    The following example splits traffic evenly between frontend services hosted on peers by defining the desired behavior locally:

    1. Kind = "service-splitter"
    2. Name = "frontend"
    3. Splits = [
    4. {
    5. Weight = 50
    6. ## defaults to service with same name as configuration entry ("frontend")
    7. },
    8. {
    9. Weight = 50
    10. Service = "frontend-peer"
    11. },
    12. ]
    1. {
    2. "Kind": "service-splitter",
    3. "Name": "frontend",
    4. "Splits": [
    5. {
    6. "Weight": 50
    7. },
    8. {
    9. "Weight": 50,
    10. "Service": "frontend-peer"
    11. }
    12. ]
    13. }
    1. apiVersion: consul.hashicorp.com/v1alpha1
    2. kind: ServiceSplitter
    3. metadata:
    4. name: frontend
    5. spec:
    6. splits:
    7. - weight: 50
    8. ## defaults to service with same name as configuration entry ("frontend")
    9. - weight: 50
    10. service: frontend-peer
  3. Create a local service-resolver configuration entry named frontend-peer and define a redirect targeting the peer and its service:

    1. Kind = "service-resolver"
    2. Name = "frontend-peer"
    3. Redirect {
    4. Service = frontend
    5. Peer = "cluster-02"
    6. }
    1. {
    2. "Kind": "service-resolver",
    3. "Name": "frontend-peer",
    4. "Redirect": {
    5. "Service": "frontend",
    6. "Peer": "cluster-02"
    7. }
    8. }
    1. apiVersion: consul.hashicorp.com/v1alpha1
    2. kind: ServiceResolver
    3. metadata:
    4. name: frontend-peer
    5. spec:
    6. redirect:
    7. peer: 'cluster-02'
    8. service: 'frontend'