Updated on 2024-11-15 GMT+08:00

Deploying a Microservice Using a Software Package

Scenarios

ServiceStage allows you to quickly deploy microservices in containers (such as CCE) or VMs (such as ECS), and supports source code deployment, JAR/WAR package deployment, and Docker image package deployment. In addition, ServiceStage allows you to deploy, upgrade, roll back, start, stop, and delete applications developed in different programming languages, such as Java, PHP, Node.js, and Python.

In this practice, backend components developed in Java and frontend components developed in Node.js are used.

User Story

In this practice, you can deploy an application in containers and register microservice instances with the ServiceComb engine. The following components need to be created and deployed for the weathermap application:
  1. Frontend component: weathermapweb, which is developed in Node.js.
  2. Backend components: weather, fusionweather, forecast, and edge-service, which are developed based on Java.

The procedures for deploying a microservice are as follows:

  1. Creating and Deploying a Backend Application Component
  2. Setting the Access Mode of the edge-service Component
  3. Creating and Deploying a Frontend Component
  4. Confirming the Deployment Result
  5. Setting the Access Mode
  6. Accessing an Application

Creating and Deploying a Backend Application Component

You need to create and deploy four application components (weather, forecast, fusionweather, and edge-service), which correspond to the four software packages generated by the backend build jobs.

  1. Log in to ServiceStage.
  2. Choose Application Management. The application list is displayed.
  3. Click Create Component in the Operation column of the application created in Creating an Application (for example, weathermap).
  4. In the Basic Information area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Component Name

    Enter the name of the corresponding backend component (for example, weather).

    Component Version

    Click Generate. By default, the version number is generated based on the time when you click Generate. The format is yyyy.mmdd.hhmms, where s is the ones place of the second in the timestamp. For example, if the timestamp is 2022.0803.104321, the version number is 2022.0803.10431.

    Environment

    Select the environment created in Creating an Environment, for example, env-test.

    Application

    Select the application created in Creating an Application, for example, weathermap.

  5. In the Component Package area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Stack

    Select Java.

    Source Code/Software Package

    Select JAR package.

    Upload Method

    1. Select OBS.
    2. Click Select Software Package and select the uploaded software package of the corresponding component by referring to Table 1.

  6. In the Build Job area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Organization

    An organization is used to manage images generated during component building.

    Select the organization created in Creating an Organization.

    Environment

    Select Use current environment to use the CCE cluster in the deployment environment to which the component belongs to build an image.

    In the current environment, masters and nodes in the CCE cluster must have the same CPU architecture. Otherwise, the component build fails.

  7. Click Next.
  8. In the Resources area, set Instances for each component and retain the default values for other parameters.

    Component Name

    Instances

    weather

    2

    forecast

    1

    fusionweather

    1

    edge-service

    1

  9. Bind the ServiceComb engine.

    • After a component is deployed, the microservice will be registered with the ServiceComb engine.
    • All components must be registered with the same ServiceComb engine.
    1. Choose Cloud Service Settings > Microservice Engine.
    2. Click Bind Microservice Engine.
    3. Select the managed ServiceComb engine in the current environment.
    4. Click OK.

  10. (Optional) Choose Container Settings > Environment Variable > Add Environment Variable. Then add environment variables for the weather, forecast, and fusionweather components by referring to the following table.

    Type

    Name

    Variable/Variable Reference

    Add manually

    MOCK_ENABLED

    Set the parameter value to false.

    • true: If no EIP is bound to the ECS node in the CCE cluster created in Preparing Resources or the node cannot access the public network, set this parameter to true. The weather data used by the application is simulated data.
    • false: If an EIP has been bound to the ECS node in the CCE cluster created in Preparing Resources and the node can access the public network, set this parameter to false or do not set this parameter. The weather data used by the application is real-time data.

  11. Click Create and Deploy.

Setting the Access Mode of the edge-service Component

  1. Click in the upper left corner to return to the Application Management page.
  2. Click the application created in Creating an Application (for example, weathermap). The Overview page is displayed.
  3. In the Component List area, locate the row that contains edge-service and click View Access Mode in the External Access Address column.
  4. Click Add Service in the TCP/UDP Route Configuration area and set parameters by referring to the following table.

    Parameter

    Description

    Service Name

    Retain the default value.

    Access Mode

    Select Public network access.

    Access Type

    Select Elastic IP address.

    Service Affinity

    Retain the default value.

    Protocol

    Select TCP.

    Container Port

    Enter 3010.

    Access Port

    Select Automatically generated.

    Figure 1 Setting the access mode of the edge-service component

  5. Click OK.

Creating and Deploying a Frontend Component

  1. Click in the upper left corner to return to the Application Management page.
  2. Click Create Component in the Operation column of the application created in Creating an Application (for example, weathermap).
  3. In the Basic Information area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Component Name

    Enter the frontend component name weathermapweb.

    Component Version

    Click Generate. By default, the version number is generated based on the time when you click Generate. The format is yyyy.mmdd.hhmms, where s is the ones place of the second in the timestamp. For example, if the timestamp is 2022.0803.104321, the version number is 2022.0803.10431.

    Environment

    Select the environment created in Creating an Environment, for example, env-test.

    Application

    Select the application created in Creating an Application, for example, weathermap.

  4. In the Component Package area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Stack

    Select Node.js.

    Source Code/Software Package

    Select ZIP package.

    Upload Method

    1. Select OBS.
    2. Click Select Software Package and select the uploaded software package of component weathermapweb by referring to Table 1.
    Figure 2 Setting frontend software package parameters

  5. In the Build Job area, set the following mandatory parameters. Retain the default values for other parameters.

    Parameter

    Description

    Organization

    An organization is used to manage images generated during component building.

    Select the organization created in Creating an Organization.

    Environment

    Select Use current environment to use the CCE cluster in the deployment environment to which the component belongs to build an image.

    In the current environment, masters and nodes in the CCE cluster must have the same CPU architecture. Otherwise, the component build fails.

  6. Click Next to add an environment variable.

    1. Choose Container Settings > Environment Variable.
    2. Click Add Environment Variable to configure environment variables.

      Type

      Name

      Variable/Variable Reference

      Add manually

      SERVICE_ADDR

      Access address generated in Setting the Access Mode of the edge-service Component.

  7. Click Create and Deploy.

Confirming the Deployment Result

  1. Click in the upper left corner to return to the Application Management page.
  2. Choose Cloud Service Engine > Microservice Catalog.
  3. Select the ServiceComb engine where the microservice application is deployed from the Microservice Engine drop-down list.
  4. Select the application (for example, weathermap) created in Creating an Application from Microservice List.

    If the number of instances of each microservice is the same as listed in the following table, the deployment is successful.

    Component Name

    Instances

    weather

    2

    forecast

    1

    fusionweather

    1

    edge-service

    1

Setting the Access Mode

  1. Choose Application Management.
  2. Click the application created in Creating an Application (for example, weathermap). The Overview page is displayed.
  3. In the Component List area, locate the row that contains weathermapweb and click View Access Mode in the External Access Address column.
  4. Click Add Service in the TCP/UDP Route Configuration area and set parameters by referring to the following table.

    Parameter

    Description

    Service Name

    Retain the default value.

    Access Mode

    Select Public network access.

    Access Type

    Select Elastic IP address.

    Service Affinity

    Retain the default value.

    Protocol

    Select TCP.

    Container Port

    Enter 3000.

    Access Port

    Select Automatically generated.

    Figure 3 Setting the access mode

  5. Click OK.

    Figure 4 Access address

Accessing an Application

  1. Click in the upper left corner to return to the Application Management page.
  2. Click the application created in Creating an Application (for example, weathermap). The Overview page is displayed.
  3. In the Component List area, locate the row that contains weathermapweb and click View Access Mode in the External Access Address column.

    If the following page is displayed, the weather forecast microservice application is successfully deployed.

    Figure 5 Application deployed successfully
    • The data is real-time data.
    • When you access the application for the first time, it takes some time for the weather system to be ready. If the preceding page is not displayed, refresh the page.