SAE supports multi-language service registration and discovery through K8s Services. You can configure a fixed domain name for an application within an SAE cluster so that instance IP addresses no longer change after each deployment.
Background
In a distributed microservices framework, service registration and discovery ensure reliable communication between server and client components as services start and stop.
-
Service registration: A service instance registers its information with a registry, which clients then read and subscribe to.
-
Service discovery: A client queries the registry for the addresses of dependent services before making a request. The registry exposes instance addresses and metadata through a predefined interface.
Limitations
-
This domain name can only be used to access instances within the same SAE application. To allow access from other services such as FC, ACK, or ECS, bind a private or public Classic Load Balancer (CLB). For more information, see Configure application service access by using a CLB.
-
You cannot use the ping command to access a K8s Service. Instead, use TCP or UDP from your code. To check network connectivity, use the ping command to test the application's pod IP address.
-
An application pod cannot access itself by using its K8s Service.
-
A job cannot access an application by using a K8s Service.
-
If a server application and a client application need to call each other, both must have a K8s Service.
Procedure
-
Access the configuration page.
On creation
-
Log on to the SAE console. In the navigation pane on the left, choose . Select a region and namespace, and then click Create Application.
-
Select an application version, and then click Create Application.
-
On the Basic Information wizard page, configure the settings and click Next: Advanced Settings.
-
On the Advanced Settings wizard page, find and expand the Service Registration and Discovery section.
On deployment
WarningAfter you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.
-
Log on to the SAE console. In the navigation pane on the left, choose . Select a region and a namespace, and then click the name of your application.
-
On the Basic Information page of the application, click Deploy Application.
-
On the Deploy Application wizard page, find and expand the Service Registration and Discovery section.
-
-
Configure Kubernetes Service-based service registration and discovery.
-
Turn on the Kubernetes Service-based service registration and discovery switch.
-
Configure the Service name, Port, and Protocol.
Parameter
Description
Service name
Enter a custom service name. The name must be unique per account within a region and cannot be changed after creation.
NoteBy default, the application name is used as the service name.
Port
Enter a Port number from 1 to 65535.
NoteYou can add up to five port and protocol configurations.
Container port
Enter the container port.
Protocol
Select a protocol. The following protocols are supported:
-
TCP
-
UDP
-
-
Access domain names
On the Basic Information page of the target application, go to the Application Access Settings section and view the information on the Kubernetes Service-based Access tab.
The following four types of domain names are supported:
-
To access applications in the same namespace, use the service name. Example:
demo. -
To access applications across namespaces, use one of the following domain name formats.
-
demo.nsfooIn this example,
nsfoois a custom namespace. If the target application is in the default namespace, usedefaultas the namespace name. Example:demo.default. -
demo.nsfoo.svc.cluster.local -
demo.nsfoo.svc.cluster.local.cn-hangzhou
-
Example port mapping: The port is 2000, the container port is 5000, and the protocol is TCP.