All Products
Search
Document Center

Container Service for Kubernetes:Deploy a Stable Diffusion application in an ACK Serverless cluster

Last Updated:Feb 28, 2026

Stable Diffusion generates images from text prompts using AI. This tutorial shows you how to deploy the Stable Diffusion WebUI in a Container Service for Kubernetes (ACK) Serverless cluster and access it through an external endpoint.

You can deploy the application using either of these methods:

  • ACK console -- Deploy through the graphical interface

  • kubectl -- Deploy using a YAML manifest from the command line

How Stable Diffusion works

Stable Diffusion WebUI is an open-source project on GitHub that generates images from text prompts. It has two core components:

  • Text comprehension -- Encodes prompts using the Contrastive Language-Image Pre-training (CLIP) model

  • Image generation -- Creates images using a diffusion model

Important
  • Alibaba Cloud does not guarantee the legitimacy, security, or accuracy of the third-party model Stable Diffusion. Alibaba Cloud is not liable for any damages caused by the use of Stable Diffusion.

  • Abide by the user agreements, usage specifications, and relevant laws and regulations of Stable Diffusion. You are responsible for all consequences that result from your use of Stable Diffusion.

Prerequisites

Before you begin, make sure you have:

Step 1: Deploy the Stable Diffusion application

Choose one of the following deployment methods.

Option A: Deploy from the ACK console

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, find your cluster and click its name. In the left navigation pane, choose Workloads > Deployments.

  3. On the Deployments page, click Create from Image.

  4. On the Basic Information step, set Name to stable-diffusion and Replicas to 1. Click Next.

  5. On the Container step, configure the following parameters. Keep the default values for all other parameters. Click Next.

    For the internal network image, replace <Region ID> with your cluster's region ID. Supported values: cn-beijing, cn-shanghai, cn-hangzhou, cn-shenzhen. The internal network endpoint pulls the image faster and avoids internet bandwidth charges.
    SectionParameterValue
    GeneralImage Nameyunqi-registry.cn-shanghai.cr.aliyuncs.com/lab/stable-diffusion:v1.2.0 (internet) or registry-vpc.<Region ID>.aliyuncs.com/yunqi-lab/stable-diffusion:v1.2.0 (internal network)
    Required ResourcesCPU8 vCPU
    Required ResourcesMemory16 GB
    Health CheckReadinessSelect Readiness, select TCP, and set the port to 7860
    LifecycleStartCommand: ["python3", "launch.py"] Arguments: ["--listen", "--skip-torch-cuda-test", "--no-half"]
  6. On the Advanced page, click Create next to Services to expose the application. Configure the Service with the following settings:

    ParameterValue
    Namestable-diffusion-svc
    Service TypeSLB -- Classic Load Balancer (CLB), select Create Resource
    Port MappingName: example-port, Service Port: 7860, Container Port: 7860, Protocol: TCP
  7. Return to the Advanced page and click Create.

  8. Go back to the Deployments page and click the application name. On the Pods tab, wait until the pod status changes to Running. Then click the Access Method tab and copy the IP address from the External Endpoint field.

    The application typically takes several minutes to start. The Stable Diffusion model must load into memory before the readiness probe on port 7860 passes and the pod status changes to Running.

Option B: Deploy with kubectl

  1. Connect to the ACK Serverless cluster using kubectl.

  2. Create a file named stable-diffusion.yaml with the following content: The YAML uses a public image endpoint by default. To pull the image over an internal network, replace the image value with the endpoint for your cluster region:

    The Deployment requests 8 vCPU, 16 GB memory, and 50 GiB ephemeral storage. These resources are needed to load and run the Stable Diffusion model for inference. Insufficient resources may cause out-of-memory errors or startup failures.
    RegionInternal image endpoint
    China (Beijing)registry-vpc.cn-beijing.aliyuncs.com/yunqi-lab/stable-diffusion:v1.2.0
    China (Shanghai)registry-vpc.cn-shanghai.aliyuncs.com/yunqi-lab/stable-diffusion:v1.2.0
    China (Hangzhou)registry-vpc.cn-hangzhou.aliyuncs.com/yunqi-lab/stable-diffusion:v1.2.0
    China (Shenzhen)registry-vpc.cn-shenzhen.aliyuncs.com/yunqi-lab/stable-diffusion:v1.2.0
       apiVersion: apps/v1
       kind: Deployment
       metadata:
         labels:
           app: stable-diffusion
         name: stable-diffusion
         namespace: default
       spec:
         replicas: 1
         selector:
           matchLabels:
             app: stable-diffusion
         template:
           metadata:
             labels:
               app: stable-diffusion
           spec:
             containers:
             - args:
               - --listen
               - --skip-torch-cuda-test
               - --no-half
               command:
               - python3
               - launch.py
               image: yunqi-registry.cn-shanghai.cr.aliyuncs.com/lab/stable-diffusion:v1.2.0
               imagePullPolicy: IfNotPresent
               name: stable-diffusion
               ports:
               - containerPort: 7860
                 protocol: TCP
               readinessProbe:
                 tcpSocket:
                   port: 7860
               resources:
                 limits:
                   cpu: "8"
                   memory: 16Gi
                   ephemeral-storage: 50Gi
       ---
       apiVersion: v1
       kind: Service
       metadata:
         annotations:
           service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: internet
           service.beta.kubernetes.io/alibaba-cloud-loadbalancer-instance-charge-type: PayByCLCU
         name: stable-diffusion-svc
         namespace: default
       spec:
         externalTrafficPolicy: Local
         ports:
         - port: 7860
           protocol: TCP
           targetPort: 7860
         selector:
           app: stable-diffusion
         type: LoadBalancer
  3. Deploy the application: Expected output:

       kubectl apply -f stable-diffusion.yaml
       deployment.apps/stable-diffusion created
       service/stable-diffusion-svc created
  4. Verify that the Deployment is ready: Expected output:

    The pod may take several minutes to reach the 1/1 READY state. The application needs time to load the model into memory.
       kubectl get deployment stable-diffusion
       NAME               READY   UP-TO-DATE   AVAILABLE   AGE
       stable-diffusion   1/1     1            1           103m
  5. Retrieve the external IP address of the Service: Expected output: Copy the EXTERNAL-IP value. Use this IP address to access the application in the next step.

       kubectl get service stable-diffusion-svc
       NAME                   TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)          AGE
       stable-diffusion-svc   LoadBalancer   172.x.x.x      47.x.x.x        7860:xxxxx/TCP   103m

Step 2: Access the application

  1. Open a browser and go to http://<EXTERNAL-IP>:7860, replacing <EXTERNAL-IP> with the IP address from Step 1.

  2. Enter a prompt in the text field. For example, enter "Black and white photo of a beautiful city" and click Generate to create an image.

Step 3: Clean up resources

After you complete the tutorial, delete the resources to avoid unnecessary charges.

Delete the application and Service

From the ACK console

  1. On the Clusters page of the ACK console, click the name of your cluster.

  2. In the left navigation pane, choose Workloads > Deployments. Select the Stable Diffusion application, click Batch Delete, and confirm the deletion.

Using kubectl

Run the following command to delete the Deployment and Service:

kubectl delete -f stable-diffusion.yaml

Expected output:

deployment.apps "stable-diffusion" deleted
service "stable-diffusion-svc" deleted

Delete the cluster

ACK Serverless clusters are in public preview and offer a free trial. However, other Alibaba Cloud services used by the cluster are billed separately based on their respective billing rules.

  • To delete the cluster: Log on to the ACK console. On the Clusters page, choose More > Delete in the Actions column. In the Delete Cluster dialog box, select Delete ALB Instances Created by the Cluster, Delete Alibaba Cloud DNS PrivateZone instances Created by the Cluster, and I understand the above information and want to delete the specified cluster. Click OK. For details, see Delete an ACK Serverless cluster.

  • To keep the cluster: Recharge your Alibaba Cloud account at least 1 hour before the trial period ends. Maintain an account balance of at least CNY 100. For billing details, see Cloud service fee.

Troubleshooting

Pod stuck in Pending state

The pod may remain in Pending if the cluster cannot allocate the requested resources (8 vCPU, 16 GB memory).

Solution: Verify that your ACK Serverless cluster is in a supported region (China Beijing, Hangzhou, Shanghai, or Shenzhen) and that your account has sufficient quota.

Image pull errors

If the pod fails with an ImagePullBackOff or ErrImagePull status, the container image cannot be downloaded.

Solution: If you use the internal network endpoint, confirm the region ID in the image URL matches your cluster region. If you use the public endpoint, verify that the cluster has internet access.

Pod is Running but the application is not accessible

The pod status shows Running but you cannot reach the WebUI in the browser.

Solution:

  1. Run kubectl get service stable-diffusion-svc and confirm the EXTERNAL-IP field has an IP address (not <pending>).

  2. Verify the browser URL uses port 7860: http://<EXTERNAL-IP>:7860.

  3. Verify that no network access control lists (ACLs) or security group rules block inbound TCP traffic on port 7860.

Out-of-memory errors during startup

The pod restarts with OOMKilled status.

Solution: Verify the resource limits in the YAML manifest match the required values: cpu: "8", memory: 16Gi, ephemeral-storage: 50Gi. Reducing the values below these limits may cause the application to fail.

Contact us

For questions about Artificial Intelligence Generated Content (AIGC) services on ACK, join DingTalk group 31850017754.