Alibaba Cloud Service Mesh (ASM) supports the connection to one or more Consul service registries to help you migrate microservices to ASM. This topic describes how to connect an ASM instance to one or more Consul service registries.

Prerequisites

  • The version of your ASM instance is v1.7.5.31-g28ec7490-aliyun or later.
  • One or more Consul service registries are deployed. For more information, see Installing Consul on Kubernetes.
  • A Kubernetes cluster is added to your ASM instance, and the pods of the Kubernetes cluster can access a Consul server. For example, the Consul server is installed in the same Kubernetes cluster as the pods, or the Consul server provides a public endpoint or an accessible internal endpoint. In these cases, the pods can access the Consul server.
  • Sample services including Web and Web2 and a built-in service Consul are registered in the Consul service registries. For more information, see Services.

Background information

After you connect an ASM instance to the Consul service registries, services inside the ASM instance can call services outside the ASM instance when you migrate microservices to the ASM instance. However, services inside the ASM instance are not automatically registered in the Consul service registries after the ASM instance is connected to the Consul service registries. To ensure that services outside the ASM instance can call services inside the ASM instance, you must manually register services inside the ASM instance in the Consul service registries.

Use Alibaba Cloud CLI to connect to a Consul server

  1. Enter the URL of Cloud Shell in the address bar of a browser or open a CLI in OpenAPI Developer Portal. For more information about OpenAPI Explorer, visit OpenAPI Developer Portal.
    Note You can open up to five Cloud Shell windows at the same time.
  2. Create a config.json file that contains the following content:
    [
      {
        "name": "consul-test",
        "prefix": "consul-",
        "type": "consul",
        "endpoint": "http://consul-server.consul:8500",
        "toNamespace": "default"
      }
    ]
    Parameter Description
    name The name of the service registry. The name must be unique.
    prefix The prefix for the names of service entries that are generated after service registration.
    type The type of the service registry. Set the value to consul.
    endpoint The endpoint of the service registry.
    toNamespace The namespace in which the generated service entries reside. If the specified namespace does not exist, the namespace is automatically created.
  3. Run the following command to connect to the Consul service registry:
    aliyun servicemesh SetServiceRegistrySource --ServiceMeshId cf9e58cf8743748b3bd13867d6d87**** --Config "$(cat config.json)"
    After you connect an ASM instance to the Consul service registry, the asm-serviceregistry component is automatically installed in the Container Service for Kubernetes (ACK) clusters that are added to the ASM instance. In addition, all services that are registered in the Consul service registry are synchronized to the ASM instance.

Use Alibaba Cloud CLI to connect to multiple Consul servers

You can connect an ASM instance to multiple Consul service registries.

  1. Enter the URL of Cloud Shell in the address bar of a browser or open a CLI in OpenAPI Developer Portal. For more information about OpenAPI Explorer, visit OpenAPI Developer Portal.
    Note You can open up to five Cloud Shell windows at the same time.
  2. Create a config.json file that contains the following content:
    [
      {
        "name": "consul-test01",
        "prefix": "consul01-",
        "type": "consul",
        "endpoint": "http://consul-server01.consul:8500",
        "toNamespace": "default"
      },
      {
        "name": "consul-test02",
        "prefix": "consul02-",
        "type": "consul",
        "endpoint": "http://consul-server02.consul:8500",
        "toNamespace": "default"
      }
    ]
    Parameter Description
    name The name of the service registry. The name must be unique.
    prefix The prefix for the names of service entries that are generated after service registration.
    Note To prevent services in different service registries from generating duplicate service entries, you must set different prefixes for the service registries in the config.json file. The service entries generated by services in the Consul service registries are in the format of {prefix}{serviceName}.
    type The type of the service registry. Set the value to consul.
    endpoint The endpoint of the service registry.
    toNamespace The namespace in which the generated service entries reside. If the specified namespace does not exist, the namespace is automatically created.
  3. Run the following command to connect to the Consul service registries:
    aliyun servicemesh SetServiceRegistrySource --ServiceMeshId cf9e58cf8743748b3bd13867d6d87**** --Config "$(cat config.json)"
    After you connect an ASM instance to the Consul service registries, the asm-serviceregistry component is automatically installed in the ACK clusters that are added to the ASM instance. In addition, all services that are registered in the Consul service registries are synchronized to the ASM instance.

Check the connection to Consul

  1. Check whether the asm-serviceregistry component is installed.
    1. Log on to the ACK console.
    2. In the left-side navigation pane of the ACK console, click Clusters.
    3. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
    4. In the left-side navigation pane of the details page, choose Workloads > Deployments.
    5. On the Deployments page, check whether the asm-serviceregistry component exists.
      Deployments page
  2. Check the synchronization of service entries.
    1. Log on to the ASM console.
    2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
    3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column of the ASM instance.
    4. On the details page of the ASM instance, choose Traffic Management > ServiceEntry in the left-side navigation pane.
    5. On the Service entry page, check whether the three services that are registered in Consul are synchronized to the ASM instance.
      Note
      • On the Service entry page, Consul services are named in the following format: [the prefix specified in Step 2]-[the registered service name in Consul].
      • On the Service entry page, the name of the namespace in which Consul services reside is the value of the toNamespace parameter specified in Step 2.

FAQ

How do I call a Consul service?

After you add the cluster in which a Consul service resides to the data plane, you can call the Consul service by using the following two methods:
  • Enable the DNS proxy feature and use the hosts and port number in the service entry that corresponds to the Consul service to call the Consul service.
    1. Log on to the ASM console.
    2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
    3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column of the ASM instance.
    4. On the details page of the ASM instance, click Settings in the upper-right corner.
    5. In the Settings Update panel, select Enable DNS Proxy and click OK.
    6. On the details page of the ASM instance, choose Traffic Management > ServiceEntry in the left-side navigation pane.
    7. On the Service entry page, find the service entry that you want to view and click YAML in the Actions column.
      In the Edit panel, view the hosts and port number. Then, use http://<hosts>:<port number> to call the Consul service. Service entry
  • Use the endpoint in the service entry that corresponds to the Consul service to call the Consul service.
    1. Log on to the ASM console.
    2. In the left-side navigation pane, choose Service Mesh > Mesh Management.
    3. On the Mesh Management page, find the ASM instance that you want to configure. Click the name of the ASM instance or click Manage in the Actions column of the ASM instance.
    4. On the details page of the ASM instance, choose Traffic Management > ServiceEntry in the left-side navigation pane.
    5. On the Service entry page, find the service entry that you want to view and click YAML in the Actions column.
      In the Edit pane, view the endpoint of the Consul service. Then, use http://<endpoint> to call the Consul service. Service entry

How do I synchronize services between Consul and Istio?

After you register a service in Consul, the service is automatically synchronized to Istio as a service entry. If you update or delete the service, the service entry in Istio is updated or deleted.