Configure application access with a K8s Service

更新时间:
复制 MD 格式

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

  1. Access the configuration page.

    On creation

    1. Log on to the SAE console. In the navigation pane on the left, choose Applications > Applications. Select a region and namespace, and then click Create Application.

    2. Select an application version, and then click Create Application.

    3. On the Basic Information wizard page, configure the settings and click Next: Advanced Settings.

    4. On the Advanced Settings wizard page, find and expand the Service Registration and Discovery section.

    On deployment

    Warning

    After 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.

    1. Log on to the SAE console. In the navigation pane on the left, choose Applications > Applications. Select a region and a namespace, and then click the name of your application.

    2. On the Basic Information page of the application, click Deploy Application.

    3. On the Deploy Application wizard page, find and expand the Service Registration and Discovery section.

  2. Configure Kubernetes Service-based service registration and discovery.

    1. Turn on the Kubernetes Service-based service registration and discovery switch.

    2. 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.

      Note

      By default, the application name is used as the service name.

      Port

      Enter a Port number from 1 to 65535.

      Note

      You 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.

Note

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.nsfoo

      In this example, nsfoo is a custom namespace. If the target application is in the default namespace, use default as 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.