Service Mesh ASM supports integration with a Consul service registry to help you migrate microservices to ASM. This topic describes how to integrate a Consul service registry with ASM.
Prerequisites
-
Your ASM instance must run version v1.7.5.31-g28ec7490-aliyun or later.
-
Consul is deployed as a service registry. For more information, see Installing Consul on Kubernetes.
-
Pods in the Kubernetes cluster added to the Service Mesh must be able to access the Consul server endpoint. For example, the Consul server is installed in the same Kubernetes cluster and exposes a public endpoint, or provides an accessible internal endpoint.
-
Sample services, including Web, Web2, and the built-in Consul service, must be registered in Consul. For more information, see Services.
Background
ASM provides a feature to connect to a Consul service registry, which facilitates the migration of microservices to ASM by allowing services inside the Service Mesh to call services outside the Service Mesh. ASM does not automatically register services from within the Service Mesh with the Consul service registry. To allow services outside the Service Mesh to call services inside the service mesh, you must manually register the services from within the Service Mesh with the Consul service registry.
Step 1: Obtain ASM-se-syncer configuration
-
Obtain the ASM instance ID.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, find the ID of your target instance in the Name/ID column.
-
-
Obtain the cluster region ID.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click Cluster Information.
-
In the Basic Information section, view the region of the cluster. For example, if the region is China (Beijing), the region ID is cn-beijing. For more information about regions, see Supported regions.
-
Obtain an AccessKey ID and an AccessKey secret. For more information, see Create an AccessKey pair.
Step 2: Install ASM-se-syncer
-
Connect to your cluster by using kubectl. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
-
Install Helm on your local machine. For more information, see the Helm documentation.
NoteAfter you connect to the cluster with kubectl, the Helm client automatically uses the KubeConfig file to connect to the cluster.
-
Download and decompress the asm-se-syncer Helm chart to your local machine.
-
Enter the asm-se-syncer folder and find the values.yaml file. In the values.yaml file, add the ASM ID, cluster region ID, AccessKey ID, and AccessKey secret, modify the following Consul service information, and then save the values.yaml file.
[ { "name": "consul-test", "prefix": "consul-", "type": "consul", "endpoint": "http://consul-server.consul:8500", "toNamespace": "default" } ]Parameter
Description
nameA unique name for the service registry.
prefixThe prefix for the names of the generated service entry resources.
typeThe type of the service registry. The only supported value is
consul.endpointThe endpoint address of the service registry.
toNamespaceThe namespace where the generated service entry resources are created. If the namespace does not exist, it is automatically created.
To connect to multiple Consul service registries, add the configuration for each registry to the values.yaml file. Then, save the values.yaml file.
[ { "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" } ] -
Run the following command to install ASM-se-syncer.
helm install -f values.yaml se-syncer ./After ASM-se-syncer is installed, ASM automatically connects to the Consul service registry, installs the asm-serviceregistry-syncer component in the ACK cluster, and synchronizes services from Consul to the Service Mesh.
Step 3: Verify the Consul integration
-
Check the installation status of the ASM component.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Deployments page, find the component named asm-serviceregistry-syncer.
If the component is in the 1/1 ready state, it is running correctly.
-
Check the synchronization status of the service entry resources.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the External Service(ServiceEntry) page, verify that the services registered in Consul have been synchronized to the Service Mesh.
Note-
On the External Service(ServiceEntry) page, the names of the Consul services follow the format:
[prefix]-[service name in Consul]. The prefix is the value specified for theprefixparameter. -
On the External Service(ServiceEntry) page, the namespace of the Consul services is the value of the
toNamespaceparameter you specified.
-
-
FAQ
How do I call a synchronized service?
Once the calling service's cluster is part of the service mesh data plane, you can call the synchronized service in one of the following ways:
-
Method 1: Enable the DNS proxy and call the service by using the hostname and port from the
hostsfield of the service entry.-
Enable the DNS proxy. For more information, see Use the DNS proxy feature in an ASM instance.
-
Obtain the hostname and port to call the service.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the External Service(ServiceEntry) page, find the target service entry and click View YAML in the Operator column.
In the Edit dialog box, obtain the hostname and port, and use http://<hostname>:<port> to call the service. In the ServiceEntry YAML file, the key configuration item
hostsis set topro-qf-test, and the port number (number) is set to80.- apiVersion: istio.alibabacloud.com, controller: true kind: ASMServiceRegistry name: default uid: 5d301b4e-39bc-46b5-xxx resourceVersion: '432158678' selfLink: >- /apis/networking.istio.io/v1beta1/naxxx uid: e446b651-be82-4e13-99xxx spec: addresses: - 172.30.xxx endpoints: - address: 172.xxx ports: http: 80 hosts: - pro-qf-test ports: - name: http number: 80 protocol: HTTP resolution: STATIC
-
-
-
Method 2: Call the service by using the address from the
endpointsfield of the External Service(ServiceEntry).-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the External Service(ServiceEntry) page, find the target service entry and click View YAML in the Operator column.
In the Edit dialog box, find the address. Call the service using the http://<address> format. In the YAML, the key configuration item is the
addressfield underspec.endpoints.- apiVersion: istio.alibacloud.com controller: true kind: ASMServiceRegistry name: default uid: 5d301b4e-39bc-46b5-xxx resourceVersion: '432158678' selfLink: >- /apis/networking.istio.io/v1beta1/naxxx uid: e446b651-be82-4e13-99xxx spec: addresses: - 172.30.xxx endpoints: - address: 172.xxx ports: http: 80 hosts: - pro-qf-test ports: - name: http number: 80 protocol: HTTP resolution: STATIC
-
How does service synchronization work?
Services registered in Consul are automatically synchronized to Istio as service entry resources. When a service is deleted or updated in Consul, the change is automatically synchronized to the corresponding service entry in Istio.
How to disable Consul integration?
Run the following command to delete the Consul synchronization resources.
helm uninstall se-syncer