All Products
Search
Document Center

Container Compute Service:Use a StatefulSet to create a stateful application

Last Updated:Jan 29, 2026

You can use a StatefulSet to quickly create a stateful application in the Alibaba Cloud Container Compute Service (ACS) console. This topic describes how to create a stateful NGINX application and the features of StatefulSets.

Background information

StatefulSets provide the following features:

Feature

Description

Pod consistency

Ensures that pods are started and terminated in the specified order and maintain network consistency, regardless of the node to which a pod is scheduled.

Stable and persistent storage

Uses VolumeClaimTemplate to mount a persistent volume (PV) to each pod. PVs are retained even after the associated pods are deleted or the workload is scaled in.

Stable network identifiers

Assigns a hostname to each pod based on the StatefulSet name and an ordinal (for example, StatefulSet name-pod ordinal).

Stable orders

Assigns a unique integer ordinal from 0 to N-1 to each of the N replicated pods in a StatefulSet.

Prerequisites

Before you begin, ensure that a kubectl client is connected to your cluster. For more information, see Obtain a cluster kubeconfig file and use kubectl to connect to the cluster.

Procedure

Step 1: Configure basic settings

  1. Log on to the ACS console.

  2. In the left navigation pane, click Clusters.

  3. On the Clusters page, click the name of your target cluster.

  4. In the left navigation pane, choose Workloads > StatefulSets.

  5. On the StatefulSets page, click Create from Image.

  6. On the Basic Information wizard page, configure the following parameters:

    Parameter

    Description

    Name

    Enter a name for the application.

    Namespace

    Choose a namespace.

    Replicas

    Specify the number of pods to provision. Default value: 2.

    Type

    Select StatefulSet.

    Label

    Add labels to identify the application.

    Annotations

    Add annotations for configuration or metadata.

    Instance Type

    Select the instance type for the pods. For more information, see Overview of ACS pod instances.

    QoS Type

    Select a QoS class. For more information, see Overview of ACS pod instances.

    • General-purpose pods support Default and BestEffort.

    • Performance-enhanced pods support only Default.

  7. Click Next.

Step 2: Configure containers

On the Container wizard page, configure settings such as images, resources, and health checks. To add multiple containers, click Add Container to the right of the Container1 tab.

  1. In the General section, configure the following basic settings:

    Parameter

    Description

    Image Name

    Click Select images to choose a container image. Options include:

    • Container Registry Enterprise Edition: Select an image from an Enterprise Edition instance.

    • Container Registry Personal Edition: Select an image from a Personal Edition instance.

    • Artifact Center: Select base images for OS, languages, or AI/big data. In this example, select an NGINX image. For more information, see Artifact Center.

    Image Pull Policy

    Select a policy:

    • ifNotPresent (Default): Uses the local image if available; otherwise, pulls it from the registry.

    • Always: Always pulls the image from the registry.

    • Never: Only uses the local image.

    Image Pull Secret

    Click Set Image Pull Secret to configure credentials for private images. Not required for ACR Enterprise Edition if configured for secret-free pulling. For more information, see Manage secrets.

    Required Resources

    Specify CPU and memory requests/limits. Requests and limits are equal by default and billed on a pay-as-you-go basis.

    Container Start Parameter

    (Optional) Specify stdin (pass console input) and tty (define virtual terminal parameters) for interactive programs.

    Init Containers

    (Optional) Select to create containers that initialize the environment or check service availability before application containers start. For more information, see Init Containers.

  2. (Optional) In the Ports section, click Add to specify container ports (1 to 65535) and protocols (TCP or UDP).

  3. (Optional) In the Environments section, click Add to specify environment variables in key-value pairs. You can use types such as Custom, Parameter, Secrets, or Value/ValueFrom.

  4. (Optional) In the Health Check section, enable probes based on your requirements:

    • Liveness Probe: Determines if the container is running. Restarts the container if checks fail.

    • Readiness Probe: Determines if the container is ready to accept traffic.

    • Startup Probe: Checks if the container has successfully started. Liveness and readiness probes only run after this succeeds.

    You can configure probes using HTTP GET requests, TCP Socket connections, or custom Command execution. For more information, see Configure Liveness, Readiness and Startup Probes.

  5. (Optional) In the Lifecycle section, configure Start, Post Start, and Pre Stop commands to manage container lifecycle events. For more information, see Attach Handlers to Container Lifecycle Events.

  6. (Optional) In the Volume section, configure local storage (ConfigMap, Secret, or EmptyDir) or cloud storage (Disks or NAS) to mount to the container. For more information, see Volumes.

  7. (Optional) In the Log section, specify Collection Configuration (Logstore and Log Path) and Custom Tags for log collection.

  8. Click Next.

Step 3: Configure advanced settings

  1. In the Access Control section, configure how to expose your application.

    • Services: Click Create to set up a Service (for example, Cluster IP or Server Load Balancer). For StatefulSets, a Headless Service is often used.

    • Ingresses: Click Create to define routing rules (domain name and path) for Internet access.

  2. (Optional) In the Scaling section, enable HPA (Horizontal Pod Autoscaler) or CronHPA for automatic scaling based on metrics or schedules.

  3. (Optional) In the Labels, Annotations section, add pod-level labels and annotations.

  4. Click Create.

Step 4: View application information

After creating the application, click View Details to go to the StatefulSet details page. You can also access this page by clicking the StatefulSet name or Details in the Actions column on the Workloads > StatefulSets page.