• Cloud Container Engine

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

Creating a Stateful Application

Stateful application instances are dependent on each other and have stable persistent storage and network identifiers. They support ordered deployment, scaling in, and deletion. Examples of stateful applications include MySQL HA and etcd applications.


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


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


  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 Stateful Applications.
  3. Set basic application parameters as listed in Table 1. The parameters marked with an asterisk (*) are mandatory.

    Table 1 Basic application parameters



    * 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 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



      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.


      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. Set the headless service parameters listed in Table 3.

    Table 3 Headless service parameters



    * Service Name

    Name of the service corresponding to the application for mutual access between instances. This service is used for internal discovery of instances, and does not require an independent IP address or load balancing.

    * Port Name

    Name of the container port. You are advised to enter a name that indicates the function of the port.

    * Container Port

    Listening port of the container.

  6. (Optional) Click Add Access Mode, and 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. For details about the access modes, see Application Access Settings.

  7. Click Next.
  8. (Optional) Configure advanced settings for the application.

    • Upgrade Mode: Rolling Upgrade.
    • Scheduling policy: You can combine static global scheduling policies or dynamic runtime scheduling policies as required. For details, see Affinity and Anti-Affinity Scheduling.

  9. 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 automatically in real time. To update the application status, press F5.

Creating a Stateful Application Using kubectl

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


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


  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 etcd-statefulset.yaml file. etcd-statefulset.yaml is an example file name, and you can change it as required.

    vi etcd-statefulset.yaml

    The following provides an example of the file contents. For more information on StatefulSet, see the Kubernetes document.

    apiVersion: apps/v1beta1
    kind: StatefulSet
      name: etcd
      replicas: 2
          app: etcd
      serviceName: etcd-svc
            app: etcd
          - env:
            - name: PAAS_APP_NAME
              value: tesyhhj
            - name: PAAS_NAMESPACE
              value: default
            - name: PAAS_PROJECT_ID
              value: 9632fae707ce4416a0ab1e3e121fe555
            image: etcd
            imagePullPolicy: IfNotPresent
            name: container-0
        type: RollingUpdate

    vi etcd-headless.yaml

    apiVersion: v1
    kind: Service
        app: etcd
      name: etcd-svc
      clusterIP: None
      - name: etcd-svc
        port: 3120
        protocol: TCP
        targetPort: 3120
        app: etcd
      sessionAffinity: None
      type: ClusterIP

  3. Create an application and the corresponding headless service.

    kubectl create -f etcd-statefulset.yaml

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

    statefulset "etcd" created

    kubectl create -f etcd-headless.yaml

    If the following information is displayed, the headless service has been created.

    service "etcd-svc" created

  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.