Partition Exports

    v1.11.0+: This config entry is supported in Consul versions 1.11.0+.

    You can configure Consul to export services contained in an admin partition to one or more additional partitions by declaring the partition-exports configuration entry in the kind field. This enables you to route traffic between services in different clusters that share a single set of Consul servers.

    You can configure the settings defined in the partition-exports configuration entry to apply to all namespaces and federated datacenters.

    Requirements

    • A Consul Enterprise binary
    • A partition that corresponds to the configuration entry. As in, the partition exports config entry for partition “frontend” requires that the “frontend” partition exists
    1. Verify that your datacenter meets the conditions specified in the .
    2. Specify the partition-exports configuration in the agent configuration file (see config_entries) as described in .
    3. Apply the configuration using one of the following methods:
      • Kubernetes CRD: Refer to the Custom Resource Definitions documentation for details.
      • Issue the consul config write command: Refer to the documentation for details.

    Configuration

    Configure the following parameters to define a partition-exports configuration entry:

    Partition exports configuration syntax

    HCL

    • HCL
    • Kubernetes YAML
    • JSON
    1. apiVersion: consul.hashicorp.com/v1alpha1
    2. Kind: PartitionExports
    3. Partition: <partition containing services to export>
    4. Services:
    5. - Consumers:
    6. - Partition: <name of the partition that will dial the exported service>
    7. Name: <name of service to export>
    8. Namespace: <namespace in the partition containing the service to export>

    The following table describes the parameters associated with the partition-exports configuration entry.

    Services

    The Services parameter contains one or more lists of parameters that specify which services to export, which namespaces the services reside, and the destination partition for the exported services. Each list in the Services block must contain the following parameters:

    • Name: Specifies the name of the service to export. You can use a asterisk wildcard (*) to include all services in the namespace.
    • : Specifies one ore more objects that identify a destination partition for the exported services.

    The following example configures the agent to export the billing service from the default namespace of the finance admin partition to the and backend partitions. Additionally, all services in all namespaces within the finance partition will be exported to the monitoring partition.

    Partition Exports - 图2

    • HCL
    • Kubernetes YAML
    • JSON
    1. Kind = "partition-exports"
    2. Partition = "finance"
    3. Services = [
    4. {
    5. Name = "billing"
    6. Namespace = "default"
    7. Consumers = [
    8. {
    9. Partition = "frontend"
    10. },
    11. {
    12. Partition = "backend"
    13. }
    14. ]
    15. },
    16. {
    17. Name = "*"
    18. Namespace = "*"
    19. Consumers = [
    20. {
    21. Partition = "monitoring"
    22. }
    23. }
    24. ]
    1. "Kind": "partition-exports",
    2. "Partition": "finance",
    3. {
    4. "Consumers": [
    5. {
    6. "Partition": "frontend"
    7. },
    8. {
    9. "Partition": "backend"
    10. }
    11. ],
    12. "Name": "billing",
    13. "Namespace": "default"
    14. },
    15. {
    16. "Consumers": [
    17. {
    18. "Partition": "monitoring"
    19. }
    20. ],
    21. "Name": "*",
    22. "Namespace": "*"
    23. }
    24. ]

    Reading Services

    When an exported service has been imported to another partition, you can use the health REST API endpoint to query the service on the consumer partition. The following example queries the finance partition for the imported billing service:

    An ACL token with service:write permissions is required for the partition from which the query is made. If the call in the previous example is made from a service named web in a partition named frontend, then the request will require a token with write permissions to web in the frontend partition.

    Exports are available to all services in the consumer partition. In the previous example, any service with permissions for the frontend partition will be able to read exports.

    See for additional information.