best practices - huawei cloud€¦ · 3. select cloud container engine for deployment system. 4....

65
ServiceStage Best Practices Issue 01 Date 2020-06-11 HUAWEI TECHNOLOGIES CO., LTD.

Upload: others

Post on 17-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

ServiceStage

Best Practices

Issue 01

Date 2020-06-11

HUAWEI TECHNOLOGIES CO., LTD.

Page 2: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Copyright © Huawei Technologies Co., Ltd. 2020. All rights reserved.

No part of this document may be reproduced or transmitted in any form or by any means without priorwritten consent of Huawei Technologies Co., Ltd. Trademarks and Permissions

and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.All other trademarks and trade names mentioned in this document are the property of their respectiveholders. NoticeThe purchased products, services and features are stipulated by the contract made between Huawei andthe customer. All or part of the products, services and features described in this document may not bewithin the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements,information, and recommendations in this document are provided "AS IS" without warranties, guaranteesor representations of any kind, either express or implied.

The information in this document is subject to change without notice. Every effort has been made in thepreparation of this document to ensure accuracy of the contents, but all statements, information, andrecommendations in this document do not constitute a warranty of any kind, express or implied.

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. i

Page 3: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Contents

1 ServiceComb on ServiceStage (Based on the New Application Model).................... 11.1 Overview.................................................................................................................................................................................... 11.2 ServiceComb Microservice Building.................................................................................................................................. 51.3 ServiceComb Microservice Deployment.......................................................................................................................... 81.4 ServiceComb Microservice O&M......................................................................................................................................151.5 ServiceComb Microservice Catalog................................................................................................................................. 161.6 ServiceComb Microservice Governance.........................................................................................................................161.7 ServiceComb Microservice Dark Launch....................................................................................................................... 21

2 Service Mesh on ServiceStage (Based on the New Application Model)..................232.1 Overview.................................................................................................................................................................................. 232.2 Accessing Applications........................................................................................................................................................ 252.3 Deploying an Application................................................................................................................................................... 252.4 Verifying Configuration.......................................................................................................................................................32

3 Python on ServiceStage (Based on the New Application Model)............................. 343.1 Overview.................................................................................................................................................................................. 343.2 Deploying a Flask Python Application Component.................................................................................................. 363.3 Deploying a Bottle Python Application......................................................................................................................... 403.4 Deploying a Pyramid Python Application.....................................................................................................................443.5 Deploying a CherryPy Application.................................................................................................................................. 48

4 Edge Service on ServiceStage............................................................................................. 534.1 Overview.................................................................................................................................................................................. 534.2 Edge Service Development................................................................................................................................................ 544.3 Edge Service Configuration............................................................................................................................................... 554.4 Edge Service Deployment.................................................................................................................................................. 564.5 Edge Service FAQ.................................................................................................................................................................. 59

5 Using Java SDK to Implement Hitless Upgrades........................................................... 60

ServiceStageBest Practices Contents

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. ii

Page 4: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

1 ServiceComb on ServiceStage (Based onthe New Application Model)

1.1 Overview

Introduction to ServiceCombApache ServiceComb is a simple and easy-to-use microservice developmentframework. It provides a large number of out-of-the-box features, such as serviceregistry and discovery, configuration management, load balancing, fault tolerance,circuit breaker, rate limiting, and service degradation, enabling you to quickly buildmicroservice applications.

HUAWEI CLOUD ServiceStage provides a series of tools and platforms to help youbetter manage ServiceComb microservice applications. ServiceStage supportsfunctions for ServiceComb microservice applications: development, building,deployment, maintenance, registry, load balancing, rate limiting, servicedegradation, circuit breaker, fault tolerance, fault injection, blacklist/whitelist,configuration management, and dashboard.

DemoThis section uses an actual microservice system to demonstrate the microservicegovernance capabilities supported by ServiceComb.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 1

Page 5: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

The weather forecast in the preceding figure is a microservice applicationdeveloped based on ServiceComb. You can enter a city name to query the weather.

1. weathermapweb is an interface microservice developed by Node.js.2. The fusionweather microservice provides data for the interface and is

developed by Java.3. The forecast microservice is developed by Java and provides the weather

forecast service for the next few days in a specified city.4. The weather microservice provides the current weather of a specified city.5. The weather-beta microservice is a new version of the weather microservice. It

allows users to query the ultraviolet (UV) of a specified city.

The weather forecast page is as follows:

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 2

Page 6: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Preparing Resources

To facilitate subsequent operations, you need to prepare the followingenvironment in advance:

1. Register a HUAWEI CLOUD account and log in to the HUAWEI CLOUD.2. Create a Virtual Private Cloud (VPC). For details, see Creating a VPC.3. Create a Cloud Container Engine (CCE) cluster. In a trial scenario, set Size to

50 nodes and High Availability to no. The cluster must contain at least oneECS node (you are advised to set Specifications to 4 vCPUs | 8 GB tofacilitate subsequent operations.) and the ECS node is bound with an EIP. Fordetails, see Creating a Hybrid Cluster.

Creating an Environment

Step 1 Log in to ServiceStage, choose Environment Management, and click CreateEnvironment.

Step 2 Configure the environment information.

1. Enter test-env in Environment.2. Select an existing VPC.3. Select basic resources in the VPC. In this example, Cloud Container Engine

(CCE) is selected.4. Select optional resources in the VPC. In this example, Cloud Service Engine

(CSE) is selected.

After a VPC is selected, basic resources and optional resources in the VPC are loaded.Resources that are not in the VPC cannot be selected.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 3

Page 7: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Figure 1-1 Creating an environment

Step 3 Click Create Now.

----End

Creating an Application

Step 1 Log in to ServiceStage, choose Application Management > Application List, andclick Create Application.

Step 2 Set basic application information.

1. You are advised to set weathermap in Name.

2. Select default for Enterprise Project. This parameter is displayed only whenthe enterprise project function is enabled.

Figure 1-2 Creating an application

Step 3 Click OK.

----End

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 4

Page 8: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

1.2 ServiceComb Microservice Building

Forking the Source CodeLog in to GitHub and fork the weather forecast source code.

Source code address: https://github.com/servicestage-demo/weathermap.git

Creating a Build Job of Backend Applications

Step 1 Log in to ServiceStage, choose Continuous Delivery > Build, and click CreateSource Code Job.

Step 2 Specify the following parameters on the displayed page:

1. Enter weathermap in Name.2. Select default for Enterprise Project.3. Select GitHub for Code Source, and select the authorization bound to the

GitHub account.4. Select your GitHub account from Username, weathermap from Repository

Name, and master from Branch.5. Select Build with shared cluster from Cluster.

Step 3 Click Next. On the page that is displayed, select a custom build template.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 5

Page 9: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 4 Click Advanced Configuration and set the following parameters on EnvironmentSettings:

1. In the Compile area, click Add Plug-in, select Command Line Build, and setBuild Language to Java.

2. In the Compile area, click Add Plug-in, select Make Docker Image, and addfour build jobs with parameters setting as follows:

Dockerfile Directory Container Image

./weather/ weather

./weather-beta/ weather-beta

./forecast/ forecast

./fusionweather/ fusionweather

3. In the Archive area, click Add Plug-in and select Archive to SWR Image

Repository to archive the preceding images.Retain the default values for other parameters. After jobs are added, theimage package is automatically archived to the image repository forsubsequent operations.

Step 5 Click Build.

----End

Creating a Build Job of Frontend Applications

Step 1 Log in to ServiceStage, choose Continuous Delivery > Build, and click CreateSource Code Job.

Step 2 Specify the following parameters on the displayed page:

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 6

Page 10: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

1. Enter weathermap in Name.2. Select default for Enterprise Project.3. Select GitHub for Code Source, and select the authorization bound to the

GitHub account.4. Select the GitHub account in Namespace, weathermap in Project, and

master in Branch.5. Select Build with shared cluster from Cluster.

Step 3 Click Next. On the page that is displayed, select a Docker build template.

1. Compile Docker to add a build job, and specify the task parameters asfollows.

Dockerfile Directory Container Image

./weathermapweb/ weathermapweb

2. Set image archiving.

Retain the default values for other parameters. After jobs are added, theimage package is automatically archived to the image repository forsubsequent operations.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 7

Page 11: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 4 Click Build.

----End

Build Result

The following figure shows a successful build.

1.3 ServiceComb Microservice DeploymentUsing ServiceStage, ServiceComb microservices can be easily deployed incontainers (such as CCE), VMs (such as ECS), or serverless (such as CCI). Inaddition, source code deployment, JAR/WAR package deployment, and Dockerimage package deployment are supported.

Creating and Deploying Backend Application Components

You need to create four application components, which correspond to the fourimages generated by the backend build jobs. This section uses the weather imagepackage as an example to describe the procedure.

Step 1 Log in to ServiceStage, choose Application Management > Application List, andclick Create Component in the Operation column of the weathermap application.

Step 2 On the page that is displayed, select Microservice and click Create Component.

Step 3 Set basic application component information.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 8

Page 12: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

1. Enter weather in Name.2. Select the Java Chassis framework.3. Select Docker for Runtime System.

Step 4 Click Create and Deploy to deploy the component.

1. Select test-env from Environment.2. Set Version to 1.0.0.3. Select Cloud Container Engine for Deployment System.4. Set Instances to 1.5. Retain the default values for other parameters.

Step 5 Click Next to configure the component.

1. Click Select Image.2. Search for the weather image on the My Images tab.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 9

Page 13: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

3. Select the displayed weather image package and click OK.4. Set Cloud Service Engine.

– After an application component is deployed, the microservice is registered with themicroservice engine.

– All application components must be registered with the same microservice engine.

5. Retain the default values for other parameters.

Step 6 Click Next, confirm the specifications, and click Deploy.

----End

Repeat the preceding steps to create and deploy the other three applicationcomponents. The following table describes the parameters to be set.

ApplicationName

Image EnvironmentVariable

TCP/UDP Route Configuration

weather-beta

weather-beta

No No

forecast forecast No No

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 10

Page 14: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

ApplicationName

Image EnvironmentVariable

TCP/UDP Route Configuration

fusionweather

fusionweather

No After the application component isdeployed, click fusionweather on theComponent List tab page to go to theEnvironment View. Then, click Set.1. On the page that is displayed, click

Add Service in the TCP/UDP RouteConfiguration area.

2. You are advised to set ServiceName to fusion.

3. Select Intra-cluster access forAccess Mode.

4. Select TCP from Protocol.5. Enter 13092 in Container Port.6. Specify Access Port as required.

Ensure that the specified port is notoccupied. It is recommended thatAccess Port is specified with thevalue of Container Port.

Creating and Deploying Frontend Application Components

Step 1 Log in to ServiceStage, choose Application Management > Application List, andclick Create Component in the Operation column of the weathermap application.

Step 2 On the page that is displayed, select Microservice and click Create Component.

Step 3 Set basic application component information.

1. Enter weathermapweb in Name.2. Select Mesher for Framework.3. Select Docker for Runtime System.

Step 4 Click Create and Deploy to deploy the component.

1. Select test-env from Environment.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 11

Page 15: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

2. Set Version to 1.0.0.3. Select Cloud Container Engine for Deployment System.4. Set Instances to 1.5. Retain the default values for other parameters.

Step 5 Click Next to configure the component.

1. Click Select Image.2. Search for the weathermapweb image on the My Images tab.3. Select the displayed weathermapweb image package and click OK.4. Set Cloud Service Engine.

– After an application component is deployed, the microservice is registered with themicroservice engine.

– All application components must be registered with the same microservice engine.

5. Choose Advanced Settings > Component Configuration. Then, click AddEnvironment Variable to add the following environment variables:

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 12

Page 16: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Type

Variable Value

Addmanually

SERVICE_ADDR fusionweather

Addmanually

HTTP_PROXY_PORT 30101 (access port)

6. Retain the default values for other parameters.

Step 6 Click Next, confirm the specifications, and click Deploy.

----End

Accessing an Application

Step 1 Log in to ServiceStage, choose Application Management > Application List, andclick the weathermap application.

Step 2 On the application details page, click Environment View to view the deployedapplication components.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 13

Page 17: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 3 Find and click the weathermapweb application component to go to its detailspage.

Step 4 Choose Access Mode.

1. On the page that is displayed, click Add Service in the TCP/UDP RouteConfiguration area.

2. You are advised to set Service Name to weathermapweb.3. Select External access for Access Mode.4. Select Elastic IP address for Access Type.5. Select TCP from Protocol.6. Enter 3000 in Container Port.7. Select Automatically generated from Access Port.8. Click OK.

Step 5 Choose Access Mode. If the following page is displayed, the application issuccessfully deployed.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 14

Page 18: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

----End

1.4 ServiceComb Microservice O&MYou can perform one-stop O&M for ServiceComb microservices on ServiceStage,including start, stop, upgrade, rollback, scale-in and scale-out, monitoring, logs,and alarm.

Step 1 Log in to ServiceStage, choose Application Management > Application List, andclick the weathermap application.

Step 2 On the application details page, click Environment View to view the deployedapplication components.

Step 3 Select and click an application component (for example, weathermapweb) to goto its details page.

----End

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 15

Page 19: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

1.5 ServiceComb Microservice CatalogThe ServiceComb microservice is deployed based on ServiceStage andautomatically registers with the service center. After being deployed, you can viewthe microsevice in the Cloud Service Engine (CSE) instance.

Step 1 Log in to ServiceStage and choose Infrastructure > Cloud Service Engines.

Step 2 Select a microservice engine and click Console. The microservice engine console isdisplayed.

Step 3 On the CSE console, choose Service Catalog to view the registered services.

----End

1.6 ServiceComb Microservice GovernanceStep 1 Log in to ServiceStage and choose Infrastructure > Cloud Service Engines.

Step 2 Select a microservice engine and click Console. The microservice engine console isdisplayed.

Step 3 On the CSE console, choose Service Governance.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 16

Page 20: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

----End

ServiceComb Microservice Load BalancingLoad balancing settings on the ServiceStage include:

● Response Time Weight: The microservice instance with low loads and quickresponse is preferentially selected for routing.

● Random: The microservice instance is selected randomly.● Session Stickiness: The microservice instance that has been responded

previously is preferentially selected.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 17

Page 21: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

● RoundRobin: Multiple microservice instances respond to requests in turn(default policy).

The following describes how to use the weather forecast application to experiencesession stickiness.

Step 1 By default, the system polls load balancing. Therefore, when the weather forecastpage is refreshed, the UV forecasts of the current city are displayed alternately, asshown in the following figure.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 18

Page 22: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 2 Set Load Balancing Policy.

1. Select the fusionweather microservice.2. Select Load Balancing and click Add.3. Select the weather microservice and set Load Balancing Policy to Session

Stickiness.4. Click OK.

Step 3 Refresh the weather forecast page multiple times, the current city's UV forecast isnot displayed alternately.

Step 4 Delete the created policy to avoid affecting subsequent user experience.

----End

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 19

Page 23: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

ServiceComb Microservice DegradationServiceStage supports service degradation by microservice or API.

The following uses the forecast microservice as an example.

Step 1 Set Fallback Policy.

1. Select the fusionweather microservice.2. Select Service Degradation and click Add.3. Select forecast from Service Degradation Object and set Policy to Open.4. Click OK.

Step 2 The weather forecast on the right fails to be displayed.

Step 3 Delete the created policy to avoid affecting subsequent user experience.

----End

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 20

Page 24: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

1.7 ServiceComb Microservice Dark LaunchIn dark launch, users are selected to test the beta version, ensuring smooth rolloutof new features. Once new features become mature and stable, a formal version isreleased for all users to use.

In the application demo project, the 0.0.2 version of the weather service does notcontain the UV forecast, and the 0.0.3 version contains the UV forecast.

Step 1 Log in to ServiceStage and choose Infrastructure > Cloud Service Engines.

Step 2 Select a microservice engine and click Console. The microservice engine console isdisplayed.

Step 3 Choose Service Catalog, and click the weather microservice to go to its detailspage.

Step 4 Choose Dark Launch and click Add Launch Rule.

Step 5 Perform the following operations on the displayed page:

1. Select Customization for Launch Rule.2. Select 0.0.3 for Version.3. Set Parameter Name to city and Rules to =chengdu.

city is the request parameter defined in the fusionweather service.

4. Click OK to save the configuration.

Step 6 Access the weather forecast application.

1. Search for Shenzhen weather, as shown in the following figure. No UVforecast is displayed.

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 21

Page 25: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

2. Search for Chengdu weather, as shown in the following figure. The UVforecast is displayed.

Based on the current dark launch rule, the weather forecast requests of Chengdu aredelivered to the 0.0.3 version of the weather service. The 0.0.2 version does not contain theUV forecast, and the 0.0.3 version contains the UV forecast. Therefore, when the weatherservice receives a request in which city is set to chengdu, the UV forecast is displayed.

----End

ServiceStageBest Practices

1 ServiceComb on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 22

Page 26: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

2 Service Mesh on ServiceStage (Based onthe New Application Model)

2.1 Overview

ScenariosServiceStage Mesher is reconstructed and deployed based on a Java service and aGo service. The Java service uses Spring Boot and Vert.x. The Go service uses Goand httproute for routing. ServiceStage then is used to deploy applications andenable mutual calling between the Java and Go services.

Preparing ResourcesTo facilitate subsequent operations, you need to prepare the followingenvironment in advance:

1. Register a HUAWEI CLOUD account and log in to the HUAWEI CLOUD.2. Create a VPC. For details, see Creating a VPC.3. Create a Cloud Container Engine (CCE) cluster. In a trial scenario, set Size to

50 nodes and High Availability to no. The cluster must contain at least oneECS node (you are advised to set Specifications to 4 vCPUs | 8 GB tofacilitate subsequent operations.) and the ECS node is bound with an EIP. Fordetails, see Creating a Hybrid Cluster.

Creating an Environment

Step 1 Log in to ServiceStage, choose Environment Management, and click CreateEnvironment.

Step 2 Configure the environment information.

1. Enter test-env in Environment.2. Select an existing VPC.3. Select basic resources in the VPC. In this example, Cloud Container Engine

(CCE) is selected.

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 23

Page 27: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

4. Select optional resources in the VPC. In this example, Cloud Service Engine(CSE) and Elastic Load Balance (ELB) are selected.

After a VPC is selected, basic resources and optional resources in the VPC are loaded.Resources that are not in the VPC cannot be selected.

Figure 2-1 Creating an Environment

Step 3 Click Create Now.

----End

Creating an Application

Step 1 Log in to ServiceStage, choose Application Management > Application List, andclick Create Application.

Step 2 Set basic application information.

1. You are advised to set Name to app-mesher.2. Select default for Enterprise Project. This parameter is displayed only when

the enterprise project function is enabled.

Figure 2-2 Creating an Application

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 24

Page 28: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 3 Click OK.

----End

2.2 Accessing Applications

Code Source● Java service code source:

https://github.com/servicestage-demo/mesher-demo-server

● Java service code source:

https://github.com/servicestage-demo/mesher-demo

In this example, the GitHub source code repository is bound to ServiceStage toimplement source code building, archiving, and application creation. Register anaccount on the GitHub official website. Then, you need to fork the source codeof the two services to your GitHub repository.

2.3 Deploying an Application

Deploy a Java Application Component

Step 1 Log in to ServiceStage, choose Application Management > Application List, andclick Create Component in the Operation column of the app-mesher application.

Step 2 On the page that is displayed, select Microservice and click Create Component.

Step 3 Set basic application component information.

1. Enter demo-mesher-server in Name.2. Select Mesher for Framework.3. Select Java8 for Runtime System.4. Select Source code repository for Source Code/Software Package.5. Select GitHub

and set Authorization, and Username/Organization. Select mesher-demo-server for Repository and master for Branch.

6. Retain the default values for other parameters.

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 25

Page 29: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 4 Click Create and Deploy to deploy the component.

1. Select test-env from Environment.2. Set Version to 1.0.0.3. Select Cloud Container Engine for Deployment System.4. Set Instances to 1.5. Retain the default values for other parameters.

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 26

Page 30: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 5 Click Next to configure the component.

1. Enable Internet Access.2. Enter 8080 in Port.3. Select ELB for Access Type.4. Set Cloud Service Engine.

– After an application component is deployed, the microservice is registered with themicroservice engine.

– All application components must be registered with the same microservice engine.

5. Retain the default values for other parameters.

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 27

Page 31: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 6 Click Next, confirm the specifications, and click Deploy to deploy the component.

----End

Deploying a Go Application Component

Step 1 Log in to ServiceStage, choose Continuous Delivery > Build, and click CreateSource Code Job.

Specify the following parameters on the displayed page:

1. Enter mesher-demo in Name.2. Select default for Enterprise Project.3. Select GitHub for Code Source, and select the authorization bound to the

GitHub account.4. Select your GitHub account from Username, mesher-demo from Repository

Name, and master from Branch.5. Select Build with shared cluster from Cluster.

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 28

Page 32: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 2 Click Next. On the page that is displayed, select a custom build template, andclick Advanced Configuration.

1. In the Compile area, click Add Plug-in, select Command Line Build, and setBuild Language to Go. Delete the command and use build.sh of theapplication.

2. In the Compile area, click Add Plug-in, select Make Docker Image, andenter ./ in Dockerfile Address and mesher-demo in Image Name.

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 29

Page 33: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

3. In the Archive area, click Add Plug-in and select Archive to SWR ImageRepository to archive the mesher-demo image.

Step 3 Click Build.

Step 4 Choose Application Management > Application List, and click CreateComponent in the Operation column of the app-mesher application.

Step 5 On the page that is displayed, select Microservice and click Create Component.

Step 6 Set basic application component information.

1. Enter demo-mesher in Name.2. Select Mesher for Framework.3. Select Docker for Runtime System.

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 30

Page 34: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 7 Click Create and Deploy to deploy the component.

1. Select test-env from Environment.2. Set Version to 1.0.0.3. Select Cloud Container Engine for Deployment System.4. Set Instances to 1.5. Retain the default values for other parameters.

Step 8 Click Next to configure the component.

1. Click Select Image.2. Search for the mesher-demo image on the My Images tab.3. Select the displayed mesher-demo image package and click OK.4. Set Cloud Service Engine.

– After an application component is deployed, the microservice is registered with themicroservice engine.

– All application components must be registered with the same microservice engine.

5. Retain the default values for other parameters.

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 31

Page 35: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 9 Click Next, confirm the specifications, and click Deploy to deploy the component.

----End

2.4 Verifying Configuration

demo-mesher Accesses demo-mesher-server

Step 1 Log in to the node where the application is deployed and run the following Dockercommand:containerID=$(docker ps |grep "op_svc_cse" | grep "demo-mesher" | grep -v "server" | awk '{print $1}');docker exec -it $containerID sh

Step 2 Run the curl commands.

1. Call API /demo/hello of demo-mesher. This API does not remotely call otherservices.curl http://127.0.0.1:8080/demo/hello

2. Call API /demo/greeting of demo-mesher. This API remotely calls API /demo/hello of demo-mesher-server.curl http://127.0.0.1:8080/demo/greeting

----End

demo-mesher-server Accesses demo-mesher

Step 1 Log in to the node where the application is deployed and run the following Dockercommand:containerID=$(docker ps |grep "op_svc_cse" | grep "demo-mesher-server" | awk '{print $1}');docker exec -it $containerID sh

Step 2 Run the curl commands.

1. Call API /demo/hello of demo-mesher-server. This API does not remotely callother services.curl http://127.0.0.1:8090/demo/hello

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 32

Page 36: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

2. Call API /demo/greeting of demo-mesher-server. This API remotely calls API /demo/hello of demo-mesher.curl http://127.0.0.1:8090/demo/greeting

----End

ServiceStageBest Practices

2 Service Mesh on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 33

Page 37: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

3 Python on ServiceStage (Based on theNew Application Model)

3.1 Overview

IntroductionPython requires the Python web application framework to support webapplications. Currently, the top Python web application frameworks are Django,Pyramid, TurboGears, Flask, CherryPy, Bottle, Web2Py, and Tornado. ServiceStageprovides the following demos based on the preceding popular Python webapplication frameworks:

● Flask python app● Bottle python app● Pyramid python app● Cherry python app

ServiceStage supports direct hosting of Python web applications to implementapplication lifecycle management.

Preparing ResourcesTo facilitate subsequent deployment operations, you need to prepare the followingenvironment in advance:

1. Register a HUAWEI CLOUD account and log in to the HUAWEI CLOUD.2. Create a VPC. For details, see Creating a VPC.3. Create a Cloud Container Engine (CCE) cluster. In a trial scenario, set Size to

50 nodes and High Availability to no. The cluster must contain at least oneECS node (you are advised to set Specifications to 4 vCPUs | 8 GB tofacilitate subsequent operations.) and the ECS node is bound with an EIP. Fordetails, see Creating a Hybrid Cluster.

4. In this example, the GitHub source code repository is bound to ServiceStageto implement source code building, archiving, and application creation.Register an account on the official GitHub website.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 34

Page 38: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Creating an Environment

Step 1 Log in to ServiceStage, choose Environment Management, and click CreateEnvironment.

Step 2 Configure the environment information.

1. Enter test-env in Environment.2. Select an existing VPC.3. Select basic resources in the VPC. In this example, Cloud Container Engine

(CCE) is selected.

After a VPC is selected, basic resources and optional resources in the VPC are loaded.Resources that are not in the VPC cannot be selected.

Figure 3-1 Creating an environment

Step 3 Click Create Now.

----End

Creating an Application

Step 1 Log in to ServiceStage, choose Application Management > Application List, andclick Create Application.

Step 2 Set basic application information.

1. You are advised to set Name to app-python.2. Select default for Enterprise Project. This parameter is displayed only when

the enterprise project function is enabled.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 35

Page 39: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Figure 3-2 Creating an application

Step 3 Click OK.

----End

3.2 Deploying a Flask Python Application Component

Flask Python ArchitectureFlask is a lightweight web application framework written based on Python. It isbased on the WerkzeugWSGI toolkit and Jinja2 template engine, and uses BSDauthorization.

Flask uses a simple core and uses extension to add other functions. It does nothave the default database and form verification tools, but retains the scalability.You can use Flask-extension to add functions: ORM, form verification tools, fileupload, and various open authentication technologies.

Creating and Deploying a ComponentDemo source code address of a Flask Python app: https://github.com/servicestage-demo/flask-pythonapp, which can be directly used.

Step 1 Visit the demo source code address of a Flask Python app and click Fork tocopy the source code to your GitHub repository.

Step 2 Log in to ServiceStage, choose Application Management > Application List, andclick Create Component in the Operation column of the app-python application.

Step 3 On the page that is displayed, select Common and click Create Component.

Step 4 Set basic application component information.

1. Enter app-flask in Name.2. Select Python3 for Runtime System.3. Select Source code repository for Source Code/Software Package.4. Select Python3-Flask for Framework.5. Select GitHub

and set Authorization, and Username/Organization. Select flask-pythonapp for Repository and master for Branch.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 36

Page 40: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

6. Enter server in Module Name.7. Enter app in Variable Name.

Enter the name of a Python entry point file in Module Name and objects thatcan be invoked by WSGI in the Python module in Variable Name.

8. Retain the default values for other parameters.

Step 5 Click Create and Deploy to deploy the component.

1. Select test-env from Environment.2. Set Version to 1.0.0.3. Select Cloud Container Engine for Deployment System.4. Set Instances to 1.5. Retain the default values for other parameters.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 37

Page 41: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 6 Click Next to configure the component.

Retain the default settings.

Step 7 Click Next, confirm the specifications, and click Deploy to deploy the component.

----End

Accessing an Application Component

Step 1 Log in to ServiceStage, choose Application Management > Application List,select the created app-python application to go to the application details page.

Step 2 On the Component List tab page, select and click the created component app-python. The component overview page is displayed. You can view the componentversion on the Environment View tab page.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 38

Page 42: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 3 Click Set in a component in the Running state. On the displayed page, click AddService.

1. Use the default Service Name.

2. Select External access for Access Mode.

3. Select Elastic IP address for Access Type.

4. Select TCP from Protocol.

5. Enter 8000 in Container Port.

6. Select Automatically generated from Access Port.

7. Click OK.

Step 4 Click the access address. The message "Not Found" is displayed.

Step 5 Add access parameters and access {access address}/hello again. The result isdisplayed.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 39

Page 43: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Hello, World!

----End

3.3 Deploying a Bottle Python Application

Bottle Python ArchitectureBottle is a fast, simple, lightweight Python WSGI web framework. It relies only onthe Python standard library. You can develop a web application as long as youunderstand basic Python syntax and a little web knowledge.

Deploying an ApplicationDemo source code address of a Bottle Python app: https://github.com/servicestage-demo/bottle-pythonapp, which can be directly used.

Step 1 Visit the Demo source code address of a Bottle Python app and click Fork tocopy the source code to your GitHub repository.

Step 2 Log in to ServiceStage, choose Application Management > Application List, andclick Create Component in the Operation column of the app-python application.

Step 3 On the page that is displayed, select Common and click Create Component.

Step 4 Set basic application component information.

1. Enter app-bottle in Name.2. Select Python3 for Runtime System.3. Select Source code repository for Source Code/Software Package.4. Select Python3-Bottle for Framework.5. Select GitHub

and set Authorization, and Username/Organization. Select bottle-pythonapp for Repository and master for Branch.

6. Enter myapp in Module Name.7. Enter app in Variable Name.

Enter the name of a Python entry point file in Module Name and objects thatcan be invoked by WSGI in the Python module in Variable Name.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 40

Page 44: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

8. Retain the default values for other parameters.

Step 5 Click Create and Deploy to deploy the component.

1. Select test-env from Environment.2. Set Version to 1.0.0.3. Select Cloud Container Engine for Deployment System.4. Set Instances to 1.5. Retain the default values for other parameters.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 41

Page 45: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 6 Click Next to configure the component.

Retain the default settings.

Step 7 Click Next, confirm the specifications, and click Deploy to deploy the component.

----End

Accessing an Application Component

Step 1 Log in to ServiceStage, choose Application Management > Application List,select the created app-python application to go to the application details page.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 42

Page 46: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 2 On the Component List tab page, select and click the created component app-bottle. The component overview page is displayed. You can view the componentversion on the Environment View tab page.

Step 3 Click Set in a component in the Running state. On the displayed page, click AddService.

1. Use the default Service Name.2. Select External access for Access Mode.3. Select Elastic IP address for Access Type.4. Select TCP from Protocol.5. Enter 8000 in Container Port.6. Select Automatically generated from Access Port.7. Click OK.

Step 4 Click the access address.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 43

Page 47: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 5 The following information is displayed.

Hello my Bottle!

----End

3.4 Deploying a Pyramid Python Application

Pyramid Python ArchitecturePyramid is an open-source Python web application framework that makes webapplication development easier.

Creating and Deploying a ComponentDemo source code address of a Pyramid Python app: https://github.com/servicestage-demo/pyramid-pythonapp, which can be directly used.

Step 1 Visit the Demo source code address of a Pyramid Python app and click Fork tocopy the source code to your GitHub repository.

Step 2 Log in to ServiceStage, choose Application Management > Application List, andclick Create Component in the Operation column of the app-python application.

Step 3 On the page that is displayed, select Common and click Create Component.

Step 4 Set basic application component information.

1. Enter app-pyramid in Name.2. Select Python3 for Runtime System.3. Select Source code repository for Source Code/Software Package.4. Select Others for Framework.5. Select GitHub

and set Authorization, and Username/Organization. Select pyramid-pythonapp for Repository and master for Branch.

6. Enter server in Module Name.7. Enter app in Variable Name.

Enter the name of a Python entry point file in Module Name and objects thatcan be invoked by WSGI in the Python module in Variable Name.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 44

Page 48: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

8. Retain the default values for other parameters.

Step 5 Click Create and Deploy to deploy the component.

1. Select test-env from Environment.2. Set Version to 1.0.0.3. Select Cloud Container Engine for Deployment System.4. Set Instances to 1.5. Retain the default values for other parameters.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 45

Page 49: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 6 Click Next to configure the component.

Retain the default settings.

Step 7 Click Next, confirm the specifications, and click Deploy to deploy the component.

----End

Accessing an Application Component

Step 1 Log in to ServiceStage, choose Application Management > Application List,select the created app-python application to go to the application details page.

Step 2 On the Component List tab page, select and click the created component app-pyramid. The component overview page is displayed. You can view the componentversion on the Environment View tab page.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 46

Page 50: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 3 Click Set in a component in the Running state. On the displayed page, click AddService.

1. Use the default Service Name.

2. Select External access for Access Mode.

3. Select Elastic IP address for Access Type.

4. Select TCP from Protocol.

5. Enter 8000 in Container Port.

6. Select Automatically generated from Access Port.

7. Click OK.

Step 4 Click the access address.

Step 5 The following information is displayed.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 47

Page 51: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Hello Pyramid!

----End

3.5 Deploying a CherryPy Application

CherryPy ArchitectureCherryPy is a simple and useful web framework written based on Python. Itminimizes the connections between a web server and Python code. You can selectyour desired template system, database mapping program, or tools.

Deploying an ApplicationDemo source code address of a CherryPy app: https://github.com/servicestage-demo/cherry-pyapp, which can be directly used.

Step 1 Visit the Demo source code address of a CherryPy app and click Fork to copythe source code to your GitHub repository.

Step 2 Log in to ServiceStage, choose Application Management > Application List, andclick Create Component in the Operation column of the app-python application.

Step 3 On the page that is displayed, select Common and click Create Component.

Step 4 Set basic application component information.

1. Enter app-cherry in Name.2. Select Python3 for Runtime System.3. Select Source code repository for Source Code/Software Package.4. Select Others for Framework.5. Select GitHub

and set Authorization, and Username/Organization. Select cherry-pyappfor Repository and master for Branch.

6. Enter wsgi in Module Name.7. Enter app in Variable Name.

Enter the name of a Python entry point file in Module Name and objects thatcan be invoked by WSGI in the Python module in Variable Name.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 48

Page 52: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

8. Retain the default values for other parameters.

Step 5 Click Create and Deploy to deploy the component.

1. Select test-env from Environment.2. Set Version to 1.0.0.3. Select Cloud Container Engine for Deployment System.4. Set Instances to 1.5. Retain the default values for other parameters.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 49

Page 53: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 6 Click Next to configure the component.

Retain the default settings.

Step 7 Click Next, confirm the specifications, and click Deploy to deploy the component.

----End

Accessing an Application Component

Step 1 Log in to ServiceStage, choose Application Management > Application List,select the created app-python application to go to the application details page.

Step 2 On the Component List tab page, select and click the created component app-cherry. The component overview page is displayed. You can view the componentversion on the Environment View tab page.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 50

Page 54: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 3 Click Set in a component in the Running state. On the displayed page, click AddService.

1. Use the default Service Name.

2. Select External access for Access Mode.

3. Select Elastic IP address for Access Type.

4. Select TCP from Protocol.

5. Enter 8000 in Container Port.

6. Select Automatically generated from Access Port.

7. Click OK.

Step 4 Click the access address.

Step 5 The following information is displayed.

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 51

Page 55: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Hello Cherrypy!

----End

ServiceStageBest Practices

3 Python on ServiceStage (Based on the NewApplication Model)

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 52

Page 56: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

4 Edge Service on ServiceStage

4.1 OverviewThe Edge Service is a Java gateway service development framework provided byServiceComb. As an external interface of the entire microservice system, the EdgeService provides services for end users, receives RESTful requests, and forwards therequests to internal microservices. The Edge Service is provided in the form of adevelopment framework. Using which, you can simply set up the Edge Service anddefine routing and forwarding rules by simple configuration. In addition, the EdgeService supports extension. Logic such as service mapping, request parsing,encryption and decryption, and authentication can be implemented throughextension.

Edge Service is a microservice and must comply with the ServiceCombmicroservice development rules. It can be deployed as multiple instances, and thefrontend uses a load balancing apparatus to distribute loads. Alternatively, it canalso be deployed in active/standby mode to directly receive user requests. You candetermine the specific mode based on the logic carried by the Edge Service,service access traffic, and networking.

This section describes how to use the Edge Service as a gateway service to forwardrequests of backend microservices. Specifically, register an account on the webpage and use this account to log in.

Category External API Internal API

Accountregistration

POST: /rest/crm/user POST: /user/v1/

Account login POST: /rest/crm/auth/login POST: /auth/v1/login

ServiceStageBest Practices 4 Edge Service on ServiceStage

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 53

Page 57: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

4.2 Edge Service Development

Maven Settings1. Add the following configuration items to profiles:

<profile> <id>MyProfile</id> //Customized ID. <repositories> <repository> <id>HuaweiCloudSDK</id> <url>https://mirrors.huaweicloud.com/repository/maven/huaweicloudsdk/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories></profile>

2. Add the following configuration items to mirrors:<mirror> <id>huaweicloud</id> <mirrorOf>*,!HuaweiCloudSDK</mirrorOf> <url>https://mirrors.huaweicloud.com/repository/maven/</url></mirror>

3. Add activeProfiles to the configuration file.<activeProfiles> <activeProfile>MyProfile</activeProfile> //The value must be the same as that set in step 1. </activeProfiles>

Service Development

Step 1 Create a microservice project based on the ServiceComb framework. You candirectly copy the project. Only one startup class is required.import org.apache.servicecomb.foundation.common.utils.BeanUtils;import org.apache.servicecomb.foundation.common.utils.Log4jUtils; public class ScmedgeserviceApplication { public static void main(String[] args) throws Exception{ Log4jUtils.init();

ServiceStageBest Practices 4 Edge Service on ServiceStage

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 54

Page 58: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

BeanUtils.init(); }}

Step 2 Modify the .pom file.

1. Add the dependency management configuration of the HUAWEI CLOUDmicroservice. <dependencyManagement> <dependencies> <dependency> <groupId>com.huawei.paas.cse</groupId> <artifactId>cse-dependency</artifactId> <version>2.3.62</version> <type>pom</type> <scope>import</scope> </dependency></dependencies></dependencyManagement>

2. Add the core library of Edge Service and the core dependency library ofHUAWEI CLOUD microservice.<dependencies> <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>edge-core</artifactId> </dependency> <dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>metrics-core</artifactId> </dependency> <dependency> <groupId>com.huawei.paas.cse</groupId> <artifactId>cse-solution-service-engine</artifactId> </dependency> </dependencies>

----End

4.3 Edge Service ConfigurationThe Edge Service is configured in the microservice.yaml file. This section focuseson the edge configuration.

1. Configure the route forwarding rules.cse: http: dispatcher: edge: url: enabled: true mappings: crm-user: prefixSegmentCount: 2 path: "/rest/crm/user/v1/.*" microserviceName: user versionRule: 0.0.1-2.0.0 crm-auth: prefixSegmentCount: 2 path: "/rest/crm/auth/login/v1/.*" microserviceName: auth versionRule: 0.0.1-2.0.0

ServiceStageBest Practices 4 Edge Service on ServiceStage

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 55

Page 59: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

● The crm-user configuration item indicates that requests whose request path is /rest/crm/user/.* are forwarded to the microservice crm-user and to only theinstance whose version number is 0.0.1-2.0.0 (excluding 2.0.0). The URL forforwarding is /user/v1/.*.

● path uses the JDK regular expression, which can be queried in the description ofthe Pattern class.

● prefixSegmentCount indicates the number of URL segments in the prefix. Theprefix is excluded from the URL.

● There are three types of versionRules that can be specified:2.0.0-3.0.0 indicates the version range, including 2.0.0 but excluding 3.0.0.2.0.0+ indicates a version later than 2.0.0, including 2.0.0.2.0.0 indicates that requests are forwarded to only 2.0.0. 2.0 is equivalent to 2.0.0.

2. Configure CORS.Cross-origin resource sharing (CORS) allows the web server to perform cross-origin access control so that the browser can transmit cross-origin data moresecurely. The CORS mechanism may be used when users need to send RESTrequests from browsers across origins. The CORS mechanism must be enabledfor microservices that receive cross-origin requests.cors: enabled: true origin: "http://*.*.yourcompany.com" allowCredentials: true allowedHeader: "appid,content-type" allowedMethod: GET,POST,PUT,DELETEmaxAge: 3600

For details about the attributes, see the CORS Mechanism.

4.4 Edge Service DeploymentUsing ServiceStage, the Edge Service can be easily deployed in containers (such asCCE), VMs (such as ECS), or serverless (such as CCI). In addition, source codedeployment, JAR/WAR package deployment, and Docker image packagedeployment are supported.

For details about how to build Edge Service, see the Microservice Building.

Step 1 Enter Create Application.

Step 2 Select application type ServiceComb and click Create Application.

ServiceStageBest Practices 4 Edge Service on ServiceStage

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 56

Page 60: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 3 Enter basic information. The following uses Docker image deployment as anexample.

Step 4 Configure the application, that is, select the image to be deployed (select thehello-docker image that has been built and packaged).

ServiceStageBest Practices 4 Edge Service on ServiceStage

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 57

Page 61: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

Step 5 Confirm specifications and create the application.

ServiceStageBest Practices 4 Edge Service on ServiceStage

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 58

Page 62: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

----End

4.5 Edge Service FAQ

What Should I Do If Services Are Unavailable After Deployment?

Check the microservice.yaml file:

1. Check whether APPLICATION_ID of the Edge Service is consistent with that ofthe forwarded microservice.

2. Check whether service_description.environment of the Edge Service isconsistent with that of the forwarded microservice.

3. Check whether path, microserviceName, and versionRule in the forwardingrule are correctly configured.

Check the following configurations on ServiceStage:

1. Check whether the Edge Service and the forwarded microservice areregistered with the same microservice engine.

2. Check whether the Edge Service and the forwarded microservice are deployedand registered successfully.

3. Check whether the listening port of the Edge Service conflicts with that ofother microservices.

What Should I Do If CORS Is Invalid?1. Check whether the expression configured for the origin is correct.2. The origin expression does not support multiple addresses separated by

commas (,).3. Check whether the header contains customized fields, which should be

configured in allowedHeader, for example, appid in the preceding example.4. Check whether the API-related operations are correctly configured on

allowedMethod.

ServiceStageBest Practices 4 Edge Service on ServiceStage

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 59

Page 63: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

5 Using Java SDK to Implement HitlessUpgrades

CSE Java SDK used for application development achieves hitless applicationupgrades.

Issues to Be Resolved1. When services are stopped, services may be interrupted. In the process of

stopping a service, if the service is processing the request, the new requestmay continue to be sent to the service.

2. In the microservice architecture, service discovery is usually performedthrough the service center. The client caches the instance address. When theservice is stopped, users may fail to detect the instance offline and continueto access the service. As a result, the access fails.

3. After the new service starts, the dark state exists and multiple versionscoexist. If an API is added to the new service, you need to send the request tothe service that contains this new API.

4. To achieve hitless upgrades, you can prepare a large number of backupmachines to start the new services. Then, the system diverts requests. Afterthe old service has no traffic, the old service is stopped. This requires O&Mpersonnel to prepare additional cluster resources and develop a powerfulO&M monitoring system.

CSE Java SDK framework achieves hitless upgrades without using O&M tools at alow cost.

Practice and EvaluationA test evaluation model is required for implementing hitless upgrades. Thefollowing test scenarios are used for evaluation.

The following describes an application instance upgrade, in which, the calleraccesses application instance 1 and application instance 2 through the gateway.During the upgrade, the caller starts N threads and requests for Mtps traffic. Theperformance of a hitless upgrade is evaluated based on the number of failures inthe entire upgrade process.

To save resources, stop instance 1 of version 1.0 and then deploy instance 1 ofversion 2.0. After that, stop instance 2 of version 1.0 and deploy instance 2 of

ServiceStageBest Practices 5 Using Java SDK to Implement Hitless Upgrades

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 60

Page 64: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

version 2.0. In addition, construct the server processing delay T to simulate thescenario where the request is being processed.

In this process, the test data is as follows:

Caller Threads(N)

Traffic M of theCaller

Processing DelayT

Failures

10 20 TPS None 0

10 80 TPS None 0

10 600 TPS None 0

10 80 TPS 100 ms 0

Implementation Principles

Core mechanisms for implementing hitless upgrades:

1. Graceful shutdown: When the service is stopped, the system waits for therequest to be completed and rejects the new request.

2. Retry: If the client fails to connect to the network or rejects the request, anew server needs to be selected for retry.

3. Isolation: Service instances that fail to be processed for a specified number oftimes are isolated.

In the preceding test data, set the retry policy in the microservice.yamlconfiguration file as follows:

servicecomb: loadbalance: retryEnabled: true retryOnNext: 1 retryOnSame: 0

Configure the isolation policy in the microservice.yaml configuration file.

ServiceStageBest Practices 5 Using Java SDK to Implement Hitless Upgrades

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 61

Page 65: Best Practices - HUAWEI CLOUD€¦ · 3. Select Cloud Container Engine for Deployment System. 4. Set Instances to 1. 5. Retain the default values for other parameters. Step 5 Click

servicecomb: loadbalance: myservice: isolation: enabled: true enableRequestThreshold: 5 singleTestTime: 10000 continuousFailureThreshold: 2

During the test, when instance 2 of version 1.0 is stopped, ensure that instance 1of version 2.0 has correctly processed the request. Otherwise, no instance isavailable and the upgrade will be interrupted.

RecommendationOnly CSE Java SDK is used in the above-mentioned hitless upgrade. Using togetherwith dark launch and deployment tools of CSE, reliable hitless upgrades can beachieved and you can get better experience.

ServiceStageBest Practices 5 Using Java SDK to Implement Hitless Upgrades

Issue 01 (2020-06-11) Copyright © Huawei Technologies Co., Ltd. 62