Creating and Deploying a Component Based on a Container Using YAML Configurations
This section describes how to create and deploy a component based on a container using YAML configurations so that you can deploy components using the Kubernetes deployment template. This is applicable to users who are familiar with CCE.
Prerequisites
- An application has been created because components can only be added to applications. For details, see Creating an Application.
- A Kubernetes environment has been created and resources have been managed because components need to be deployed in an environment. For details, see Environment Management.
- An organization has been created because images generated during component build need to be managed by organization. For details, see Creating an Organization.
- A namespace has been created to isolate and build data and component instances. For details, see Creating a Namespace.
- If you create a component based on a source code repository, repository authorization has been created. For details, see Creating Repository Authorization.
- If you create a component based on a software package, the software package has been uploaded to the SWR software repository or OBS bucket.
- Upload the software package to the software repository. For details, see Uploading the Software Package.
- Upload the software package to the OBS bucket. For details, see Streaming Upload (PUT).
If the software package fails to be uploaded, see What If a Software Package Fails to Be Uploaded?
- If you create a component based on an image package, prepare the image by referring to Component Source.
Creating and Deploying a Component Based on a Container Using YAML Configurations
- Log in to ServiceStage.
- Use any of the following methods to go to the Create Component page:
- Choose Component Management > Create Component.
- On the Application Management page, select the application for which you want to create a component, and click Create Component in the Operation column.
- On the Application Management page, click the application for which you want to create a component. On the displayed Overview page, click Create Component.
- In the Basic Information area, configure the component by referring to the following table. Parameters marked with an asterisk (*) are mandatory.
Parameter
Description
*Component Name
Name of a component, which cannot be changed after the component is created and deployed.
Enter 2 to 64 characters. Start with a letter and end with a letter or digit. Only use letters, digits, underscores (_), and hyphens (-).
- Components with the same name in different applications can be deployed in the same environment.
- Components with the same name in the same application can be deployed in different environments.
*Component Version
Component version number, which can be automatically generated or customized.
- Automatically-generated: Click Generate. By default, the version number is 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.
- Customized: Enter a value in the format of A.B.C or A.B.C.D. A, B, C, and D are natural numbers. For example, 1.0.0 or 1.0.0.0.
*Environment
Select Kubernetes or VM + Kubernetes.
For details, see Environment Overview.
NOTE:If CCE clusters and VMs are managed in an earlier version, the environment type is VM + Kubernetes after the upgrade to the current version.
*Deployment Mode
Select Container.
This parameter is mandatory when Environment is set to VM + Kubernetes. For details, see Deploying a Component.
*Application
Application to which the component belongs.
*Workload Type
A workload is an application running on Kubernetes. No matter how many components are there in your workload, you can run it in a group of Kubernetes pods. A workload is an abstract model of a group of pods in Kubernetes. Select a workload type as required.
- Stateless: Workloads are completely independent and have the same functions. They support auto scaling and rolling upgrade. Typical scenario: Nginx.
- Stateful: Workloads have persistent storage and support orderly deployment, scaling, and deletion. Typical scenario: MySQL-HA and etcd.
*Workload
The workload name is automatically generated by default, and can also be customized.
The default workload name consists of the Component Name and Environment you set, and six random characters generated by the system. The total length cannot exceed 52 characters.
- If the Component Name contains 45 characters or fewer, the default workload name is:
All of the component name-All or part of the environment name-Six random characters generated by the system
Underscores (_) in the name will be replaced with hyphens (-), and uppercase letters will be converted to lowercase letters.
For example, if the component name is Com_calc and the environment is env-cce, the default workload name is:
com-calc-env-cce-1uw8g0
- If the Component Name contains more than 45 characters, the default workload name is:
First 45 characters of the component name-Six random characters generated by the system
Underscores (_) in the name will be replaced with hyphens (-), and uppercase letters will be converted to lowercase letters.
For example, if the component name is C_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, the default workload name is:
c-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-1uw8g0
You can also customize the workload name.
- If Workload Type is Stateful, enter 1 to 52 characters. Start with a lowercase letter and end with a lowercase letter or digit. Only use lowercase letters, digits, and hyphens (-).
- If Workload Type is Stateless, enter 1 to 63 characters. Start with a lowercase letter and end with a lowercase letter or digit. Only use lowercase letters, digits, and hyphens (-).
The workload name cannot be changed after the component is created and deployed.
Description
Component description.
- Click and enter up to 128 characters.
- Click to save the component description.
Figure 1 Setting the basic component information
- In the Component Package area, configure the component package by referring to the following table. Parameters marked with an asterisk (*) are mandatory.
Parameter
Description
*Stack
- Select a component technology stack type based on the component deployment mode. For details, see Table 1.
- Select a technology stack version from the Name drop-down list.
- Set JVM to configure the memory parameter size during Java code running. This parameter is available when a Java or Tomcat technology stack is selected.
Click Stack Settings and set JVM, for example, -Xms256m -Xmx1024m. Multiple parameters are separated by spaces.
- Set Tomcat to configure the parameters such as Tomcat request path and port number. This parameter is available when a Tomcat technology stack is selected.
- Click Stack Settings and select Tomcat. The Tomcat dialog box is displayed.
- Click Use Sample Code and edit the template file based on service requirements.
NOTE:
In Tomcat configuration, the default server.xml configuration is used. The context path is /, and no application path is specified.
If you need to customize an application path, customize the Tomcat context path by referring to How Do I Customize a Tomcat Context Path?
- Click OK.
*Source Code/Software Package
- If you select Source code repository, create authorization by referring to Creating Repository Authorization and set the code source.
- If you select a software package (JAR, WAR, or ZIP), the software package type supported by the component source is determined by the selected technology stack type. For details, see Table 1.
*Upload Method
If the component source is software package or image package, select an uploaded software package or image package. For details about the upload method, see Component Source.
NOTE:- When the component source is image package, select Multi-container to support multi-container deployment. It can be used to build complex application systems where different services or components are encapsulated in different containers.
- Click in the upper right corner of the selected image package to change the image package source or delete the image package.
*Container Name
- By default, the container name is the same as the workload name in 3. You can also customize the container name. The name contains 1 to 63 characters, including lowercase letters, digits, and hyphens (-), and must start with a lowercase letter and end with a lowercase letter or digit.
- If the source of the component selected for Upload Method is image package and multi-container deployment is enabled, you need to customize a container name for the new container. The name contains 1 to 63 characters, including lowercase letters, digits, and hyphens (-), and must start with a lowercase letter and end with a lowercase letter or digit.
- In the Build Job area, set build parameters by referring to the following table. Parameters marked with an asterisk (*) are mandatory.
This parameter is mandatory when the selected technology stack type is Java, Tomcat, Node.js, Python, or PHP in 4.
Parameter
Description
*Command
If the component source is Source code repository, set Command based on service requirements.
- Default command or script: preferentially executes build.sh in the root directory. If build.sh does not exist, the code will be compiled using the common method of the selected language. Example: mvn clean package for Java.
- Custom command: Commands are customized using the selected language. Alternatively, the default command or script is used after build.sh is modified.
NOTICE:
- If Custom command is selected, exercise caution when inputting sensitive information in the echo, cat, or debug command, or encrypt sensitive information to avoid information leakage.
- To run the compilation command in the project subdirectory, you need to go to the project subdirectory and then run other script commands. Example:
mvn clean package
*Dockerfile Address
If the component source is Source code repository, set Dockerfile Address based on service requirements.
Dockerfile Address is the directory where the Dockerfile is located relative to the root directory (./) of the project. The Dockerfile is used to build an image.
If Dockerfile Address is not specified, the system searches for the Dockerfile in the root directory of the project by default. If the Dockerfile does not exist in the root directory, the system automatically generates the Dockerfile based on the selected operating environment.
*Organization
An organization is used to manage images generated during component build.
*Build
Select the type of the environment used to build an image. The build environment must be a Kubernetes environment, and can access the Internet.
You are advised to select Use current environment. If the CCE cluster in the current environment cannot access the Internet and you have planned an independent build environment, you can select Use independent environment.
- Use independent environment: Use an independent build environment to build an image. The CCE clusters in the independent build environment and in the current component deployment environment must have the same CPU architecture. Otherwise, the component deployment fails.
- Use current environment: Use 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.
*Environment
- If Use independent environment is selected for Build, select an independent build environment different from that to which the component belongs.
- If Use current environment is selected for Build, select the deployment environment to which the component belongs.
*Namespace
Select the namespace of the CCE cluster in the environment where the build is executed, which is used to isolate build data. For details, see Managing Namespaces.
Node Label
You can use a node label to deliver the build job to a fixed node bound with an EIP.
In the following cases, set a node label to deliver the build job to the fixed node bound with an EIP to ensure that the component can be successfully built and deployed:
- If Use independent environment is selected for Build, set a node label to deliver the build job to the node in the independent environment, to ensure that the node CPU architecture is the same as that of the node in the current component deployment environment.
- If Use current environment is selected for Build and the CPU architecture of a node is different from that of the master node in the environment, set a node label to deliver the build job to the node that has the same CPU architecture as the master node.
For details about how to add a label, see Managing Node Labels.
YAML Mode
Enable it by clicking to use the YAML configurations to deploy component.
Figure 2 Configuring build parameters
- Click Next.
- In the Access Mode area, enable Public Network Access.
After public network access is enabled for a component, you can use a public network domain name to access the component through an ELB bound with an EIP to use services provided by the component.
- If a component is upgraded and maintained in ELB dark launch mode after being created and deployed, you need to enable public network access for the component. For details about ELB dark launch, see Upgrading a Component in Dark Launch Mode.
- After a component with public network access enabled is created and deployed, you can change the configured component access domain name by referring to Changing the Component Access Domain Name.
- By default, public network access is disabled for a component. After a component is created and deployed, you can also configure the component access mode. For details, see Configuring the Component Access Mode.
Click to enable public access and set the following parameters:- Set Public Network Load Balancer.
- Select a load balancer that has been bound to an EIP in the selected environment.
- If no load balancer exists, click Add One. On the Edit Environment page that is displayed, click Add Optional Resource to add created load balancers to the environment.
- To create ELB resources, refer to the following table.
Scenario
Reference
Use the domain name to access an application.
- An EIP has been bound to the load balancer and must be in the same VPC and subnet as the compute resources managed in the current component deployment environment.
- Components must be bound with different load balancers in different deployment environments to avoid route errors.
- Set Client Protocol.
- HTTP has security risks. You are advised to select HTTPS.
- If HTTPS is selected, click Use existing to select an existing certificate.
If no certificate exists, click Create new to create a server certificate. For details, see Adding a Certificate.
- Set Domain Name.
- If Automatically generated is selected, the automatically generated domain name is valid only for seven days.
- If Bound is selected, enter a domain name.
- Set Listening Port.
Enter the listening port number of the application process.
Figure 3 Configuring public access
- In the Headless Service Settings area, set the service name and port number of the component by referring to the following table. Parameters marked with an asterisk (*) are mandatory.
This operation is required when Workload Type is Stateful in 3. This operation enables pods in a StatefulSet to access each other and provides a fixed access domain name for each pod.
Parameter
Description
*Service Name
Enter the name of the service that can be accessed by external services.
A service is an abstract method that exposes a group of applications running on a pod as network services.
NOTE:Service names of components deployed on the same CCE must be unique. Otherwise, component deployment will fail.
*Port Settings
Set the following port parameters:
- Port Name: name of the port for communication between pods.
- Container Port: port used by an application for listening in a container.
- Access Port: port for accessing the service.
To add port settings, click Add Setting.
- Import or edit the YAML configuration file of the component.
- Click Import YAML File to import the edited YAML configuration file.
- Edit the configuration parameters as required.
The parameters in the YAML configuration file are described in Deployment.
You can change name in the YAML configuration by referring to the description of Workload Name in 3. The workload name cannot be changed after the component is created and deployed.
You can change name in the YAML configuration by referring to the description of Container Name in 4. After a component is created and deployed, you can also change the container name by upgrading the component.
- Click Create and Deploy.
On the Deployment Records page, view the deployment logs and wait until the component deployment is complete.
If the technology stack type of the component selected in 4 is Java, Tomcat, Node.js, Python, or PHP, the system creates a build job of the System created type after the component is deployed. For details, see Viewing Build Jobs.
Figure 4 Viewing component deployment logs
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot