Container Compute Service (ACS) supports creating stateless applications using container images, orchestration YAML templates, or kubectl command-line tools. This topic uses an Nginx application as an example to show how to create a stateless application in an ACS cluster.
Console
Create from image
Step 1: Configure basic application information
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Workloads > Deployments.
-
On the Deployments page, click Create with Image.
-
In the Basic Information wizard, configure the basic settings for your application.
configuration item
Description
Name:
Enter a name for the application.
Replicas:
The number of pods in the application. The default value is 2.
Workloads
Select Deployment.
Label
Add a label to identify this application.
Annotations
Add an annotation to the application.
Instance Type
Select a compute type. For details about compute types, see Overview of ACS pod instances.
QoS Type
Select a Quality of Service (QoS) class.
-
Click Next to go to the Container wizard.
Step 2: Configure containers
On the Container wizard page, configure the container image, resources, ports, environment variables, health checks, lifecycle, volumes, and logging.
To add multiple containers to the pod, click Add Container next to the Container 1 tab.
-
In the General section, complete the basic container configuration.
configuration item
Description
Image Name
-
Select an image
Click Select Image to choose the required image.
-
Container Registry Enterprise Edition: Select an Enterprise Edition image hosted in Alibaba Cloud Container Registry (ACR). You must select the region and ACR instance where the image resides. For more information about ACR, see What is Container Registry?.
-
Container Registry Personal Edition (must be activated first): Select a Personal Edition image hosted in ACR. You must select the region and ACR instance where the image resides.
-
Artifact center: Includes base OS images for containerized applications, language runtime images, and AI/big data-related images. This example uses an Nginx image from Artifact Center. For more information, see Artifact Center.
-
-
(Optional) Set the image pull policy
From the Image Pull Policy drop-down list, select a pull policy. By default, no policy is set, and Kubernetes uses IfNotPresent.
-
IfNotPresent: If the image already exists locally (previously pulled to the host), it will not be pulled again. Otherwise, the image will be pulled.
-
Always: Always pull the image during deployment or scale-out, ignoring any local copy.
-
Never: Use only the local image.
-
-
(Optional) Set an image pull secret
Click Set Image Pull Secret to securely access private images.
-
For ACR Personal Edition instances, you can pull container images by setting an image pull secret. For more information, see Manage secrets.
-
For ACR Enterprise Edition instances, you can pull images without passwords using the passwordless component. For details, see Pull ACR images without passwords.
-
Required Resources
Set resource quotas for the container.
-
CPU: Specify CPU request and limit values. By default, the request equals the limit, and billing uses the pay-as-you-go method. If you set a different limit via YAML, the request will be overwritten to match the limit. For details, see Resource specifications.
-
Memory: Specify memory request and limit values. By default, the request equals the limit, and billing uses the pay-as-you-go method. If you set a different limit via YAML, the request will be overwritten to match the limit. For details, see Resource specifications.
Interactive Session
(Optional) Configure container startup options.
-
stdin: Send console input to the container.
-
tty: Attach the standard input console as the container's console input.
NoteTypically, both stdin and tty are selected together to bind the terminal (tty) to the container's standard input (stdin). For example, an interactive program reads user input from stdin and displays output on the terminal.
Init Containers
(Optional) Select this option to create an init container.
Init containers provide a mechanism to block or delay the startup of application containers until they succeed. After successful execution, application containers in the pod start in parallel. For example, you can use init containers to check the availability of dependent services. Init containers can include utilities or installation scripts not present in the application image to initialize the runtime environment—for example, setting kernel parameters or generating configuration files. For more information, see Init Containers.
-
-
(Optional) In the Ports section, click Add to configure container ports.
configuration item
Description
Name
Specify a name for the container port.
Container Port
Specify the exposed container access port. The port number must be between 1 and 65535.
Protocol
Supported protocols are TCP and UDP.
-
(Optional) In the Environments section, click Add to configure environment variables.
You can configure environment variables for the pod using key-value pairs to add environment flags or pass configuration. For more information, see Pod Environment Variables.
Parameter
Description
Type
Set the environment variable type:
-
Custom
-
ConfigMaps
-
Secrets
-
Value/ValueFrom
-
ResourceFieldRef
ConfigMap and Secret support referencing entire files.
This example uses a Secret. When you select the Secrets type and choose a target Secret, all files in that Secret are referenced by default. After selecting Secret, enter a Variable Name and select the corresponding Secret name and key from the two drop-down lists on the right.
The corresponding YAML references the entire Secret:
envFrom: - secretRef: name: testVariable Key
Set the environment variable name.
Value/ValueFrom
Set the referenced variable value.
-
-
(Optional) In the Health Check section, enable Liveness, Readiness, and Startup as needed.
-
Liveness probe: A liveness probe checks if a container is running. If the probe fails multiple times, the kubelet restarts the container. This can help resolve issues like deadlocks where the container is running but unable to make progress.
-
Readiness probe: A readiness probe checks if a container is ready to accept traffic. A Pod is added as a backend to a Service only after its readiness probe succeeds.
-
Startup Probes: These probes are executed only when a container starts to check if it has started successfully. The Liveness Probes and Readiness Probes are executed only after the startup probe succeeds.
For more information, see Configure liveness, readiness, and startup probes.
Parameter
Description
HTTP
Sends an HTTP GET request to the container. Supported parameters include the following:
-
Protocol: HTTP or HTTPS.
-
Path: The path to access the HTTP server.
-
Port: The exposed container port or port name. The port number must be between 1 and 65535.
-
HTTP Header: Custom request headers in the HTTP request. HTTP allows duplicate headers. Configure them as key-value pairs.
-
Initial Delay (s): The initialDelaySeconds parameter specifies how many seconds to wait after the container starts before performing the first probe. Default is 3 seconds.
-
Period (s): The periodSeconds parameter specifies the time interval between probes. Default is 10 seconds. Minimum is 1 second.
-
Timeout (s): The timeoutSeconds parameter specifies the probe timeout duration. Default is 1 second. Minimum is 1 second.
-
Healthy Threshold: The minimum number of consecutive successful probes required after a failure to mark the container as healthy. Default is 1. Minimum is 1. For liveness probes, this must be 1.
-
Unhealthy Threshold: The minimum number of consecutive failed probes required after success to mark the container as unhealthy. Default is 3. Minimum is 1.
TCP
Opens a TCP socket to the container. Kubelet attempts to open a socket on the specified port. If successful, the container is considered healthy; otherwise, it is marked as failed. Supported parameters include the following:
-
Port: The exposed container port or port name. The port number must be between 1 and 65535.
-
Initial Delay (s): The initialDelaySeconds parameter specifies how many seconds to wait after the container starts before performing the first probe. Default is 15 seconds.
-
Period (s): The periodSeconds parameter specifies the time interval between probes. Default is 10 seconds. Minimum is 1 second.
-
Timeout (s): The timeoutSeconds parameter specifies the probe timeout duration. Default is 1 second. Minimum is 1 second.
-
Healthy Threshold: The minimum number of consecutive successful probes required after a failure to mark the container as healthy. Default is 1. Minimum is 1. For liveness probes, this must be 1.
-
Unhealthy Threshold: The minimum number of consecutive failed probes required after success to mark the container as unhealthy. Default is 3. Minimum is 1.
Command
Runs a command inside the container to check its health. Supported parameters include the following:
-
Command: The command used to check container health.
-
Initial Delay (s): The initialDelaySeconds parameter specifies how many seconds to wait after the container starts before performing the first probe. Default is 5 seconds.
-
Period (s): The periodSeconds parameter specifies the time interval between probes. Default is 10 seconds. Minimum is 1 second.
-
Timeout (s): The timeoutSeconds parameter specifies the probe timeout duration. Default is 1 second. Minimum is 1 second.
-
Healthy Threshold: The minimum number of consecutive successful probes required after a failure to mark the container as healthy. Default is 1. Minimum is 1. For liveness probes, this must be 1.
-
Unhealthy Threshold: The minimum number of consecutive failed probes required after success to mark the container as unhealthy. Default is 3. Minimum is 1.
-
-
(Optional) In the Lifecycle section, configure the container lifecycle.
You can configure pre-start commands, post-start handlers, and pre-stop handlers for the container lifecycle. For details, see Configure lifecycle.
Parameter
Description
Start
Specify a command and its arguments to run before the container starts.
Post-start Hook
Specify a command to run after the container starts.
Pre-stop Hook
Specify a command to run before the container terminates.
-
(Optional) In the Volume section, mount volumes to the container.
-
Local storage: Mount ConfigMaps, Secrets, or temporary directories to container paths. For more information, see volumes.
-
Cloud storage: Supports cloud disks, NAS, and more. For details, see Storage overview.
-
-
(Optional) In the Log section, configure Collection Configuration and Custom Tag.
Parameter
Description
Collection Settings
-
Logstore: Creates a corresponding Logstore in Simple Log Service to store collected logs.
-
Log Path in Container (Can be set to stdout): Supports stdout and text logs.
-
Stdout: Collects standard output logs from the container.
-
Text logs: Collects logs from a specified path inside the container. This example collects all text logs under
/var/log/nginxand supports wildcard characters.
-
Custom Tags
You can also set custom tags. When configured, these tags are included with the container logs. Custom tags help you categorize logs for easier statistics and filtering during analysis.
-
-
Click Next to go to the Advanced wizard.
Step 3: Complete advanced configuration
On the Advanced wizard page, configure access, scaling, scheduling, and labels/annotations.
-
In the Access Control section, configure how to expose backend pods.
This example uses ClusterIP and Ingress to create a publicly accessible Nginx application.
-
Configure a Service: Click Create next to Services to set up service parameters.
-
Configure Ingress: Click Create next to Ingresses to set routing rules for backend pods.
-
-
(Optional) In the Scaling section, enable HPA to meet varying load demands.
-
Container Compute Service supports autoscaling based on pod CPU and memory usage.
NoteTo enable autoscaling, you must specify requested resources for the container. Otherwise, autoscaling will not work.
configuration item
Description
Metric
Supports CPU and memory. Must match the requested resource type.
Trigger Condition
The threshold for resource usage percentage. When exceeded, the system scales out.
Max. Replicas
The maximum number of containers that can be scaled out for this payload type.
Min. Replicas
The lower limit for scaling in this workload.
-
Container Compute Service also supports scheduled scaling (CronHPA) to automatically scale Kubernetes clusters at specific times. Before enabling scheduled scaling, install the ack-kubernetes-cronhpa-controller component. For details, see Scheduled scaling (CronHPA).
-
-
(Optional) In the Labels,Annotations section, click Add to set pod labels and annotations.
-
Click Create.
Step 4: View application information
After successful creation, you are redirected to the completion page. Click View Details to go to the Deployment details page.
You can also view the Deployment information on the Deployments page. Click the name of the target Deployment or the Actions column’s Details to go to the application details page.
Create using YAML
In ACS template orchestration, you define the required resource objects for your application and combine them into a complete application using mechanisms such as label selectors.
This example shows how to create an Nginx application using an orchestration template containing a Deployment and a Service. The Deployment creates pod resources, and the Service binds to those pods, forming a complete Nginx application.
-
Log on to the ACS console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of the target cluster. In the left navigation pane, choose Workloads > Deployments.
-
On the Deployments page, click Create from YAML in the upper-right corner.
-
On the Create page, configure the template and click Create.
-
Sample Template: ACS provides Kubernetes YAML examples for various resource types to help you deploy quickly. You can also write your own YAML following Kubernetes standards.
-
Create Workload: Quickly define a YAML template using this feature.
-
Use Existing Template: Import an existing orchestration template.
-
Save Template: Save your configured orchestration template.
Below is a sample YAML for an Nginx application. This example quickly creates an Nginx Deployment and a CLB-type LoadBalancer service.
Note-
ACS supports Kubernetes YAML orchestration. Use the
---separator to define multiple resource objects in one template. -
(Optional) When mounting volumes via Volume, files in the mount directory are overwritten by default. To preserve existing files, configure the
subPathparameter.
-
-
After clicking Create, deployment status messages appear.
kubectl
You can use kubectl commands to create and view applications.
-
Connect to your cluster. For details, see Obtain cluster kubeconfig and connect using kubectl or Manage Kubernetes clusters using kubectl in CloudShell.
-
You can run the following command to start a container (such as an Nginx web server).
kubectl create deployment nginx --image=registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest -
You can run the following command to create a service endpoint for the container. Specifying
--type=LoadBalancercreates an Alibaba Cloud SLB that routes traffic to the Nginx container.kubectl expose deployment nginx --port=80 --target-port=80 --type=LoadBalancer -
You can run the following command to list running nginx containers.
kubectl get pod |grep nginxExpected output:
NAME READY STATUS RESTARTS AGE nginx-2721357637-d**** 1/1 Running 1 9h