Deploy Spring Cloud and Dubbo applications in a Kubernetes cluster

更新时间:
复制 MD 格式

Enterprise Distributed Application Service (EDAS) provides demo applications for Spring Cloud, Dubbo, and High-speed Service Framework (HSF). You can deploy these demos to a Kubernetes (K8s) cluster to quickly learn how to deploy microservice applications. This topic describes how to deploy a microservice application in a Kubernetes environment.

Prerequisites

  • Activate EDAS.

  • Create a cluster in Container Service for Kubernetes (ACK) and import it into EDAS. You cannot create Kubernetes clusters directly in EDAS. For more information, see Use the console to manage Kubernetes clusters.

    Note

    To quickly get started, you can import your Kubernetes cluster into the default microservices namespace for the region. For production use, you can import the cluster into a custom microservices namespace to isolate resources and services.

  • Create an application image.

  • If you are a Resource Access Management (RAM) user, your Alibaba Cloud account must grant permissions to your RAM user before you can use an image from a Container Registry Enterprise Edition repository to create an application. For more information, see RAM authorization information.

Background information

Deploy a microservice application demo image

The microservice application demo image contains a server-side application (Provider) and a client-side application (Consumer). This topic describes how to deploy the Provider. After you deploy the Provider, follow the same steps to deploy the Consumer.

  1. Log on to the EDAS consoleEDAS console.

  2. In the left-side navigation pane, choose Application Management > Applications.

  3. In the top navigation bar of the Applications page, select a region. On the page that appears, select the target microservices namespace, and then click Create Application.

  4. On the Basic Information tab of the Create Application wizard, set the basic information for the application, and then click Next.

    Parameter

    Description

    Cluster Type

    Select Kubernetes Cluster.

    Application Runtime Environment

    • Hosted Applications: Select Java.

    • Select Application: Select Custom.

  5. On the Application Configuration tab, configure the application environment, select the demo image, and then click Next.

    Note

    If you are a RAM user, your Alibaba Cloud account must grant permissions to your RAM user before you can use an image from a Container Registry Enterprise Edition repository to create an application. For more information, see RAM authorization information.

    应用配置-K8s

    Parameter

    Description

    Microservices Namespace

    Select Default.

    Note

    This topic is intended to help you learn how to deploy a microservice application demo in a K8s cluster. For this reason, we recommend that you do not create a new microservices namespace. You can use the default microservices namespace. To isolate resources and services when you use EDAS, you can create a microservices namespace. For more information, see Manage microservices namespaces.

    Cluster

    Select the target K8s cluster from the drop-down list.

    K8s Namespace

    Select default from the drop-down list.

    If you want to create a custom Kubernetes namespace, click Create Kubernetes Namespace. In the dialog box that appears, enter a name for the Kubernetes namespace in the K8s Namespace field. The name can contain digits, lowercase letters, and hyphens (-), and can be 1 to 63 characters in length. It must start and end with a letter or a digit.

    Application Name

    Enter a name for the application.

    Application Description

    Enter a description for the application.

    Image Type

    Select Demo Image.

    Image Repository Namespace

    Select edas-demo-project from the list. Then, from the list to the far right of edas-demo-project/provider, select version 1.0.

    Note

    The edas-demo-project/provider image in the edas-demo-project image repository namespace and its version 1.0 are provided by EDAS as a demo. You cannot change these settings.

    Total Pods

    Enter 1.

    Resource Quota per Pod

    Set CPU Reservation (Core) to 1 and Mem Reservation (MB) to 2048.

  6. On the Advanced Settings tab, click Create Application.

    The Advanced Settings tab contains advanced settings that you can configure as needed. For more information, see Advanced Configuration.

  7. On the Creation Completed tab, review the settings on the Basic Information, Configurations, and Advanced Settings tabs, and then click Create.

    After the application starts deploying, a message appears at the top of the Basic Information page, indicating that the application is being changed. The deployment process takes about two minutes.

    You can also click View Details next to the message to open the Change History page of the application. On this page, you can view the deployment progress and related logs.

  8. Repeat the preceding steps to deploy the client-side application.

Verify the result

The service consumer includes a web service. After you deploy both the server-side and client-side applications, you can access the web page of the client application to verify the service call.

  1. On the Application List page, click the name of the Consumer application to open the Application Overview page.

  2. In the Access Method Configuration section of the Application Overview page, click the icon to the right of Internet-facing SLB.

  3. In the Internet-facing SLB dialog box, set the SLB and listener parameters, and then click Confirm.

    添加SLB

    1. From the Select SLB drop-down list, select Create SLB.

      If you have an existing SLB instance, you can select it from the list.

    2. Next to TCP | HTTP, click Add New Listener. Set the SLB Port to 80 and the Container Port to 18082.

      Important

      Configure the TCP or HTTP protocol for the application as follows. You need to configure only one of them for access.

      • Service consumer (Consumer): Set Container Port (Target port) in the TCP or HTTP protocol section to 18082.

      • Service provider (Provider): Set Container Port (Target port) in the TCP or HTTP protocol section to 18081.

      If you set the port for the service consumer (Consumer) to 18081, the web page is not accessible.

    3. Click Confirm.

    It takes about 30 seconds to add the Internet-facing SLB instance. After the instance is added, its IP address and port are displayed next to Internet-facing SLB in the Access Method Configuration section. The address is in the SLB instance IP:Port format.

  4. Copy the Internet-facing SLB address, paste it into the address bar of your browser, and press Enter.

    The web page of the client application appears.访问客户端应用

  5. In the Echo this string text box, enter an arbitrary string, such as Hello EDAS. Then, click Click here and check whether data is returned from the call in the area below the page.

    If the Data returned from the call area shows the process in which the client-side application (Consumer) calls the server-side application (Provider) and includes the string you entered, the call is successful and the microservice Demo application is deployed.

    2020-08-25T10:00:01.866Z :  Consumer received.    
        2020-08-25T10:00:01.878Z :  Provider received.
            Provider processed after sleep 1 second! Echo String: "Hello EDAS"
        2020-08-25T10:00:02.878Z :  Provider Return
    2020-08-25T10:00:02.882Z :  Consumer Return