• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. User Guide 2.0
  4. Application Management
  5. Creating a Stateless Application

Creating a Stateless Application

Stateless application instances are independent from each other and provide the same functions. They support auto scaling and rolling upgrades. Examples of stateless applications include Nginx and WordPress.

Prerequisites

  • A cluster is available. For details on how to create a cluster, see Creating a VM Cluster.
    NOTE:

    When creating multiple containerized applications, ensure that each application has a unique port. Otherwise, application deployment will fail.

  • To enable access to an application from Internet, ensure that an elastic IP address has been bound to or ELB instances have been configured for at least one node in the cluster.

Creating a Stateless Application on the CCE Console

  1. (Optional) If you are creating an application based on your own image, upload the image to the image management service. For details about how to upload an image, see Image Repository.
  2. In the navigation pane, choose Application Management. Click Create Application, and set Select Application Type to Stateless Applications.
  3. Set basic application parameters as described in Table 1. The parameters marked with an asterisk (*) are mandatory.

    Table 1 Basic application parameters

    Parameter

    Description

    * Application Name

    Name of the containerized application to be created. The name must be unique.

    * Cluster Name

    Cluster in which the application resides.

    * Namespace

    Namespace in which the application resides. By default, this parameter is set to default.

    Application Group

    You can manage (start, stop, and delete) applications in batches by adding these applications to the same application group.

    When you enter an application group name, a user group is automatically created.

    * Instances

    Number of instances in the application. Each application has at least one instance. You can specify the number of instances as required.

    Each application instance consists of the same containers. Configuring multiple instances for an application ensures that the application can still run properly even if an instance is faulty.

    Description

    Description of the application.

  4. Click Next to add a container.

    1. Click Add Container and select the image to be deployed. Click OK.
      • The My Images tab page displays all images you created.
      • Third-party Images: CCE allows you to create an application using an image pulled from a third-party image repository, rather than a public cloud image repository or a Docker Hub image repository. When you create an application using a third-party image, ensure that the node where the application is running can access public networks. For details about how to create an application using a third-party image, see Using a Third-party Image to Create an Application.
        • If your image repository does not require authentication, set Authenticate Secret to No, specify Image Address, for example, nginx:latest, and click OK.
        • If your image repository is accessible only after being authenticated by account and password, set Authenticate Secret to Yes. You need to create a secret first and then user a third-party image to create an application.
    2. Set image parameters.
      Table 2 Image parameters

      Parameter

      Description

      Image Name

      Imported image. You can click Change Image to update it.

      * Image Version

      Version of the image to be deployed.

      * Container Name

      Name of the container. You can modify it.

      Privileged Pod

      If this option is selected, the container obtains the privileged permission, for example, modifying kernel parameters.

      Container Resources

      For more information about Request and Limit, see Setting Container Specifications.

      • Request: the amount of resources that CCE will guarantee to a container.
      • Limit: the maximum amount of resources that CCE will allow a container to use. You can set Limit to prevent system faults caused by container overload.
    3. Configure the lifecycle to set the commands that need to be executed in each phase during container management.
    4. Set the health check function that checks whether containers and services are running properly. Two types of probes are set: application liveness probe and application service probe. For more information, see Checking the Health of Containers.
      • Application Liveness Probe: Restarts the application when detecting that the application instance is unhealthy.
      • Application Service Probe: Sets the application to the unready state when detecting that the application instance is unhealthy. In this way, the service traffic will not be directed to the application instance.
    5. Set environment variables.
      Environment variables are set in the container running environment and can be modified after application deployment to ensure the flexibility of applications.
      1. Click Add.
      2. Set Type to Added manually.
      3. Set Variable Name and Variable/Variable Reference.
    6. Set data storage.

      You can mount a host directory, EVS disk, SFS, and configuration items and secrets to the corresponding directories of a container instance. For details, see Storage Management.

      NOTE:

      If you set Allocation Mode to Automatic when adding data storage, the created storage will not be tagged.

    7. In the Security Context area, set container permissions to prevent the container from affecting the system and other containers.

      Enter a user ID. The container will run with this user ID.

    8. Set log policy.

      Set a policy and log directory for collecting application logs and preventing logs from exceeding size limits. For details, see Log Management.

    9. (Optional) One application instance contains one or more related containers. If your application contains multiple containers, click Add Container and then add containers.

  5. Click Next. Then, click Add Access Mode, and set the application access mode.

    To enable access to the application from other applications or the Internet, set the application access mode.

    The application access mode determines the network attributes of an application. Applications with different access modes can provide different network capabilities.

    At present, the following access modes are provided:

    • Intra-Cluster Access: An application is accessible to other applications in the same cluster by using an internal domain name.
    • Intra-VPC Access: An application is accessible to other applications in the same VPC by using the IP address of the cluster node or the ELB service address of the private network.
    • External Access - Elastic IP Address: An application is accessible to public networks by using an EIP. This access mode is applicable to services that need to be exposed to public networks. To enable access to an application from the Internet, an elastic IP address must be bound to a node in the cluster, and a mapping port number must be set. The port number ranges from 30000 to 32767, for example, the access address can be 10.117.117.117:30000.
    • External Access - Elastic Load Balancer: An application is accessible to public networks by using an ELB address. This access mode provides higher reliability than EIP-based access and is applicable to services that need to be exposed to public networks. The access address consists of the ELB service address of the public network and the configured access port, for example, 10.117.117.117:80.
    • Layer 7 Load Balancing (Ingress): Enhanced ELB is used. Compared with layer-4 ELB, layer-7 ELB newly supports Uniform Resource Identifier (URI) configurations and distributes access traffic to the corresponding service based on the corresponding URIs. In addition, different functions are implemented based on various URIs. The access address consists of the IP address of the public network load balancer, access port, and defined URI, for example, 10.154.55.77:80/helloworld.

    For details about the access modes, see Application Access Settings.

  6. Click OK, and then click Next.
  7. (Optional) Configure advanced settings for the application.

    1. Configure the upgrade policy, as listed in Table 3.
      Table 3 Upgrade policy

      Upgrade Mode

      Description

      In-place upgrade

      In this upgrade mode, the old instance needs to be deleted before a new instance is created. Services are interrupted during the upgrade.

      Rolling upgrade

      The instance of the old version is gradually replaced with the instance of the new version. During the upgrade, service traffic is evenly distributed between new and old instances, so services are not interrupted.

    2. Migration Policy: Provides a time window for the application instances to be rescheduled to other available nodes when the node where the application instance is located is unavailable. The default value is 300s.
    3. Scheduling policy: You can combine static global scheduling policies or dynamic runtime scheduling policies as required. For details, see Affinity and Anti-Affinity Scheduling.

  8. Click Create Now. Click Back to Application List.

    In the application list, if the application status is Running, the application has been created successfully. Application status is not updated in real time. To view the application status, press F5.

  9. To access the application in a browser, go to the application list on the Application Management page. Copy the corresponding External Access Address and paste it into the address box in the browser.

    NOTE:

    External access addresses can be obtained only when the application access mode is set to Elastic IP Address or Elastic Load Balancer.

Creating a Stateless Application Using kubectl

The following procedure uses an Nginx application as an example to describe how to create an application using kubectl.

Prerequisites

You have configured the kubectl commands and connected an ECS to the cluster. For details, see Connecting to a Kubernetes Cluster Using kubectl.

Procedure

  1. Log in to the ECS on which the kubectl commands have been configured. For details, see Logging In to a Linux ECS.
  2. Create and edit the nginx-deployment.yaml file. nginx-deployment.yaml is an example file name, and you can change it as required.

    vi nginx-deployment.yaml

    The following provides an example of the description file contents. For more information on deployment, see the Kubernetes documentation.

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      strategy:
        type: RollingUpdate
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - image: nginx 
            imagePullPolicy: Always
            name: nginx
          imagePullSecrets:
          - name: default-secret

  3. Create a containerized application.

    kubectl create -f nginx-deployment.yaml

    If the following information is displayed, the application is being created.

    deployment "nginx" created

    kubectl get po

    If the following information is displayed, the application is running.

    NAME                     READY     STATUS    RESTARTS   AGE
    icagent-m9dkt            0/0       Running   0          3d
    nginx-1212400781-qv313   1/1       Running   0          3d

  4. If the application needs to be accessed by other nodes in the same cluster, in the same VPC, or in a public network, set the application access mode. For details, see Application Access Settings.