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 |
Stable network identifiers | Assigns a hostname to each pod based on the StatefulSet name and an ordinal (for example, |
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
Log on to the ACS console.
In the left navigation pane, click Clusters.
On the Clusters page, click the name of your target cluster.
In the left navigation pane, choose Workloads > StatefulSets.
On the StatefulSets page, click Create from Image.
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.
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.
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.
(Optional) In the Ports section, click Add to specify container ports (1 to 65535) and protocols (TCP or UDP).
(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.
(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.
(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.
(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.
(Optional) In the Log section, specify Collection Configuration (Logstore and Log Path) and Custom Tags for log collection.
Click Next.
Step 3: Configure advanced settings
In the Access Control section, configure how to expose your application.
Services: Click Create to set up a Service (for example,
Cluster IPorServer Load Balancer). For StatefulSets, a Headless Service is often used.Ingresses: Click Create to define routing rules (domain name and path) for Internet access.
(Optional) In the Scaling section, enable HPA (Horizontal Pod Autoscaler) or CronHPA for automatic scaling based on metrics or schedules.
(Optional) In the Labels, Annotations section, add pod-level labels and annotations.
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.