Creating a Container Workload

This section describes how to deploy a workload on CCE. When using CCE for the first time, create an initial cluster and add a node into the cluster.

Containerized workloads are deployed in a similar way. The difference lies in:

  • Whether environment variables need to be set.
  • Whether cloud storage is used.

Required Cloud Services

  • Cloud Container Engine (CCE): a highly reliable and high-performance service that allows enterprises to manage containerized applications. With support for Kubernetes-native applications and tools, CCE makes it simple to set up an environment for running containers in the cloud.
  • Elastic Cloud Server (ECS): a scalable and on-demand cloud server. It helps you to efficiently set up reliable, secure, and flexible application environments, ensuring stable service running and improving O&M efficiency.
  • Virtual Private Cloud (VPC): an isolated and private virtual network environment that users apply for on HUAWEI CLOUD. You can configure the IP address ranges, subnets, and security groups, as well as assign elastic IP addresses and allocate bandwidth in a VPC.

Basic Concepts

  • A cluster is a collection of computing resources, including a group of node resources. A container runs on a node. Before creating a containerized application, you must have an available cluster.
  • A node is a virtual or physical machine that provides computing resources. You must have sufficient node resources to ensure successful operations such as creating applications.
  • A workload indicates a group of container pods running on CCE. CCE supports third-party application hosting and provides the full lifecycle (from deployment to O&M) management for applications. This section describes how to use a container image to create a workload.

Procedure

  1. Prepare the environment as described in Table 1.

    Table 1 Preparing the environment

    No.

    Item

    Procedure

    1

    Creating a VPC

    Create a VPC before you create a cluster. A VPC provides an isolated, configurable, and manageable virtual network environment for CCE clusters.

    If you have a VPC already, skip to the next task.

    1. Log in to the management console.
    2. In the service list, choose Network > Virtual Private Cloud.
    3. On the Dashboard page, click Create VPC.
    4. Follow the instructions to create a VPC. Retain default settings for parameters unless otherwise specified.

    2

    Creating a key pair

    Create a key pair before you create a containerized application. Key pairs are used for identity authentication during remote login to a node. If you have a key pair already, skip this task.

    1. Log in to the management console.
    2. In the service list, choose Security and Compliance > Data Encryption Workshop.
    3. In the navigation pane, choose Key Pair Service. On the Private Key Pairstab page, click Create Key Pair.
    4. Enter a key pair name and click OK.
    5. In the displayed dialog box, click OK.

      View and save the key pair. For security purposes, a key pair can be downloaded only once. Keep it secure to ensure successful login.

  2. Create a cluster.

    1. Log in to the CCE console, choose Dashboard in the navigation pane, and click Buy ClusterCreate Cluster.
    2. Set Billing Mode to Pay-per-use. Select an enterprise project, enter the cluster name cluster-01, retain the default values for other parameters, and click Next: Create Node.
    3. Configure parameters for nodes in the cluster. Configure EIP and Login Mode as follows, and retain the default values for the other parameters.
      • EIP: Select Automatically assign to make the node accessible from public networks. Retain the default values for other parameters.
      • Login Mode: Select Key pair, and select the created key pair for logging in to the node.
    4. Click Next: Install Add-on and install the desired add-ons in the cluster. The system resource add-ons are mandatory whereas the advanced functional add-ons are optional.
    5. Click Next: Confirm. Read the product instructions and select I am aware of the above limitations. Confirm the configured parameters, specifications, and fees.
    6. Click Submit. It takes about 6 to 10 minutes to create a cluster. View the cluster creation process as prompted.
    7. Choose Resource Management > Nodes in the navigation pane. You can view the node whose status is Available and has bound with an elastic IP address.

  3. Deploy a workload on CCE.

    1. In the navigation pane, choose Workloads > Deployments. On the page displayed, click Create Deployment.
    2. Set the following parameters, and retain the default settings for other parameters:
      • Workload Name: Set it to apptest.
      • Cluster Name: Enter the name of the cluster created in 2.
      • Instances: Set it to 1.
    3. Click Next: Add Container. Click Add Container. On the My Images tab page, select the image uploaded in Building and Uploading an Image and click OK.
    4. Retain the default settings for image parameters. Expand the Environment Variables section, set the environment variables used for interconnecting with the MySQL database. These environment variables are set in Compiling a Startup Script.

      In this example, interconnection with the MySQL database is implemented through configuring the environment variables. Determine whether to use environment variables based on your service requirements.

      Table 2 Configuring environment variables

      Variable Name

      Variable Value/Variable Reference

      MYSQL_DB

      Database name.

      MYSQL_URL

      IP address and port number of the database.

      MYSQL_USER

      Database username.

      MYSQL_PASSWORD

      Database user password.

    5. Expand the Data Storage section to configure cloud storage. To implement persistent data storage, you need to configure cloud storage.

      In this example, the MongoDB database is used and persistent data storage is also needed, so you need to configure cloud storage. Determine whether to use cloud storage based on your service requirements.

      In this example, set Container Path as the path to the MongoDB storage directory that you configured in the Docker startup script.

      Figure 1 Configuring cloud storage
    6. Retain the default values of other parameters and click Next: Set Application Access to configure workload access.
    7. Click Add Service, set workload access parameters, and click OK.

      In this example, the application will be accessible from public networks by using an elastic IP address.

      • Access Type: In this example, select NodePort.
      • Service Name: name of the application that can be accessed externally. In this example, this parameter is set to apptest.
      • Service Affinity
        • Cluster level: The IP addresses and access ports of all nodes in a cluster can be used to access the workload associated with the Service. Service access will cause performance loss due to route redirection, and the source IP address of the client cannot be obtained.
        • Node level: Only the IP address and access port of the node where the workload is located can be used to access the workload associated with the Service. Service access will not cause performance loss due to route redirection, and the source IP address of the client can be obtained.
      • Port Settings
        • Protocol: Set it to TCP.
        • Container Port: port that the application will listen on the container. In this example, this parameter is set to 8080.
        • Access Port: If this parameter is set to Automatically generated, the system automatically opens a real port on all nodes in the current cluster and then maps the port number to the container port.
    8. Click Next: Configure Advanced Settings. Skip the advanced settings, and click Create.

      After the workload is created, you can view the running workload in the workload list.