Exported Services

Enterprise

This feature requires Consul Enterprise.

This topic describes the exported-services configuration entry type. The exported-services configuration entry enables Consul to export service instances to other admin partitions from a single file. This enables your services to be networked across admin partitions. See Admin Partitions for additional information.

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

Introduction

You can configure Consul to export services contained in an admin partition to one or more additional partitions by declaring the exported-services 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 exported-services configuration entry to apply to all namespaces and federated datacenters.

Requirements

  • A Consul Enterprise binary
  • A corresponding partition that the configuration entry can export to. For example, the exported-services configuration entry for a partition named frontend requires an existing frontend partition.

Usage

  1. Verify that your datacenter meets the conditions specified in the Requirements.
  2. Specify the exported-services configuration in the agent configuration file (see config_entries) as described in Configuration.
  3. Apply the configuration using one of the following methods:

Configuration

Configure the following parameters to define a exported-services configuration entry:

Exported services configuration syntax

Exported services configuration syntax

HCL

Exported Services - 图1

  • HCL
  • Kubernetes YAML
  • JSON
  1. Kind = "exported-services"
  2. Partition = "<partition containing services to export>"
  3. Name = "<partition containing services to export>"
  4. Services = [
  5. {
  6. Name = "<name of service to export>"
  7. Namespace = "<namespace in the partition containing the service to export>"
  8. Consumers = [
  9. {
  10. Partition = "<name of the partition that will dial the exported service>"
  11. },
  12. ]
  13. }
  14. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ExportedServices
  3. metadata:
  4. name: <partition containing services to export>
  5. spec:
  6. services:
  7. - name: <name of service to export>
  8. namespace: <namespace in the partition containing the service to export>
  9. consumers:
  10. - partition: <name of the partition that will dial the exported service>
  1. "Kind": "exported-services",
  2. "Partition": "<partition containing services to export>",
  3. "Name": "<partition containing services to export>",
  4. "Services": [
  5. {
  6. "Consumers": [
  7. {
  8. "Partition": "<name of partition that will dial the exported service>"
  9. }
  10. ],
  11. "Name": "<name of service to export>",
  12. "Namespace": "<namespace in the partition containing the service to export>"
  13. }
  14. ]

Configuration Parameters

The following table describes the parameters associated with the exported-services configuration entry.

ParameterDescriptionRequiredDefault
KindString value that enables the configuration entry. The value should always be exported-services (HCL and JSON) or ExportedServices (YAML)RequiredNone
PartitionString value that specifies the name of the partition that contains the services you want to export.RequiredNone
NameString value that specifies the name of the partition that contains the services you want to export.RequiredNone
ServicesList of objects that specify which services to export. See Services for details.RequiredNone
MetaObject that defines a map of the max 64 key/value pairs.OptionalNone

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.
  • Namespace: Specifies the namespace containing the services to export. You can use a asterisk wildcard (*) to include all namespaces in the partition.
  • Consumers: Specifies one ore more objects that identify a destination partition for the exported services.

Example

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

HCL

Exported Services - 图2

  • HCL
  • Kubernetes YAML
  • JSON
  1. Kind = "exported-services"
  2. Partition = "finance"
  3. Name = "finance"
  4. Services = [
  5. {
  6. Name = "billing"
  7. Namespace = "default"
  8. Consumers = [
  9. {
  10. Partition = "frontend"
  11. },
  12. {
  13. Partition = "backend"
  14. }
  15. ]
  16. },
  17. {
  18. Name = "*"
  19. Namespace = "*"
  20. Consumers = [
  21. {
  22. Partition = "monitoring"
  23. }
  24. ]
  25. }
  26. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. Kind: ExportedServices
  3. metadata:
  4. name: finance
  5. spec:
  6. services:
  7. - name: mesh-gateway
  8. namespace: default
  9. consumers:
  10. - partition: default
  11. - name: billing
  12. namespace: default
  13. consumers:
  14. - partition: frontend
  15. - partition: backend
  1. "Kind": "exported-services",
  2. "Partition": "finance",
  3. "Name": "finance",
  4. "Services": [
  5. {
  6. "Consumers": [
  7. {
  8. "Partition": "frontend"
  9. },
  10. {
  11. "Partition": "backend"
  12. }
  13. ],
  14. "Name": "billing",
  15. "Namespace": "default"
  16. },
  17. {
  18. "Consumers": [
  19. {
  20. "Partition": "monitoring"
  21. }
  22. ],
  23. "Name": "*",
  24. "Namespace": "*"
  25. }
  26. ]

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:

  1. $ curl 'localhost:8500/v1/health/connect/billing?partition=finance'

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 write permissions for the frontend partition will be able to read exports.

See Health HTTP Endpoint for additional information.