Quickly deploy a scalable and highly available DeepSeek-R1-Distill-Qwen-7B inference service

Updated at:
Copy as MD

Combine Elastic Container Instance (ECI) scaling groups with Application Load Balancer (ALB) to deploy a cross-zone, highly available large language model (LLM) inference service.

Solution overview

This solution deploys ECI-based inference instances across multiple zones in a single region for zone-level disaster recovery. ALB handles traffic distribution, and Object Storage Service (OSS) stores model files. The following figure shows the architecture.

image

Benefits

  • High availability: Distributes the workload across multiple servers to eliminate single points of failure and prevent service interruptions.

  • Elastic scaling: A scaling group manages the inference cluster. Quickly scale out by adjusting the ECI instance count, or configure auto scaling to provision resources on demand based on workload.

Procedure

  1. Plan the cluster network. Create a VPC and vSwitches in multiple zones.

  2. Create an OSS bucket. Store model weight files.

  3. Configure an instance RAM role. Grant the ECI instance access to the OSS bucket from Step 2.

  4. Prepare an image cache. Create an image cache to accelerate startup and download model weights to OSS.

  5. Create an ALB instance. The ALB instance serves as the service endpoint.

  6. Create a scaling group. Associate it with the ALB instance to auto-add new ECI instances to the backend server group.

  7. Start the service. Set the expected instance count in the scaling group to launch the service.

1. Plan the cluster network

Create a Virtual Private Cloud (VPC) and vSwitches across multiple zones. This example uses one VPC and two vSwitches in different zones for high availability.

You can reuse an existing VPC and skip this step.
  1. In the console, create one VPC and two vSwitches as instructed below.

    ①②: Click Create VPC.

    image

    ③: Region. China (Hangzhou).

    ④: Name. vpc-ess-hangzhou.

    ⑤: IPv4 CIDR. Select 192.168.0.0/16.

    image

    vSwitch 1:

    ⑥: Name. vSwitch-j.

    ⑦: Zone. Zone J.

    ⑧: IPv4 CIDR. 192.168.0.0/24.

    ⑨: Click Add to create vSwitch 2.

    image

    vSwitch 2:

    ⑩: Name. vSwitch-k.

    ⑪: Zone. Zone K.

    ⑫: IPv4 CIDR. 192.168.1.0/24.

    image

  2. Click OK and wait for the VPC to be created.

2. Create an OSS bucket

Create an Object Storage Service (OSS) bucket to store model weight files. ECI instances read files from this bucket.

You can reuse an existing OSS bucket and skip this step.
  1. In the Object Storage Service console, create a bucket.

    Configure the following key parameters. Keep the defaults for others.

    ①: Click Create Bucket.

    ②: Bucket. This name is required when you mount the storage space later.

    ③: Region. Select Specific Region and make sure the region is the same as the region of your ECI instances. This tutorial uses China (Hangzhou).

    Same-region access from ECI to OSS uses the internal network and incurs no data transfer fees. Access OSS resources from an ECS instance over an internal network.

    image

  2. Click OK.

3. Create an instance RAM role

Create an instance RAM role that allows ECI instances to read model weight files from your OSS bucket.

  1. In the console, create an instance RAM role with the following settings.

    ①: Click Create Role.

    image

    ②: Principal Type. Select Cloud Service.

    ③: Principal Name. Select ECS.

    4. Click OK and set a name for the instance RAM role as prompted.

    image

  2. In the console, create the following policy.

    ①: Click Create Policy.

    ②: Click JSON Editor.

    image

    image

    ③: This policy grants full permissions for a specific bucket. Use the following policy script.

    Important

    When you configure this policy, replace <bucket_name> with the Bucket of the bucket that you created.

    {
        "Version": "1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "oss:*",
                "Resource": [
                    "acs:oss:*:*:<bucket_name>",
                    "acs:oss:*:*:<bucket_name>/*"
                ]
            }
        ]
    }

    Click OK and set a name for the policy as prompted.

  3. In the console, grant permissions to the instance RAM role.

    ①②: Click Grant Permission.

    ③: Principal. Select the instance RAM role that you created.

    ④: Policies. Select the policy that you created.

    image

    Click OK.

4. Prepare image cache and model files

Create an image cache to accelerate ECI instance startup, and download model weight files to OSS.

  1. In the console, create an ECI image cache.

    ①②: Click Create Image Cache.

    image

    ③④: Region and Zone. Must match the VPC region from Step 1. The zone must match one of the vSwitches from Step 1.

    ⑤⑥: Network. Select the VPC and one of the vSwitches that you created in Step 1.

    ⑦: Elastic IP Addresses. Select an existing EIP. If none exists, click EIP console to create one, then return, click the refresh icon image, and select it.

    ⑧: Security Group. Select a security group. If none exists, click Create Security Group to create one, then return and select it.

    ⑨: Image Cache Name. vllm.

    ⑩: Cache Size. 100 GB.

    ⑪: Image. egs-registry.cn-hangzhou.cr.aliyuncs.com/egs/vllm.

    ⑫: Version. 0.6.4.post1-pytorch2.5.1-cuda12.4-ubuntu22.04.

    image

    image

    Wait for the image cache to be created (~15 minutes). Check progress on the image cache page of the console.

    image

  2. In the console, launch a temporary ECI instance to download the model weight files to the OSS bucket.

    ①②: Click Create Container Group.

    image

    ③: Billing Method. pay-as-you-go.

    ④: Region. Must match the VPC region from Step 1. This tutorial uses China (Hangzhou).

    ⑤: VPC. Select the VPC that you created in Step 1.

    ⑥: vSwitch. Select the vSwitch that you created in Step 1.

    ⑦: Security Group. Set the parameter as prompted on the page.

    image

    Container group configuration:

    ⑧: CPU. 2 vCPU.

    ⑨: Memory. 4 GiB.

    ⑩: After containers run and exit. Select Upon Failure.

    image

    Advanced settings:

    ⑪: Expand Advanced Configuration.

    ⑫: Turn on Automatically Match Image Cache.

    ⑬: Select and add OSS Persistence.

    ⑭: Name. oss-data.

    ⑮: Bucket. Select the bucket that you created in Step 2.

    ⑯: RAM Role. Select the instance RAM role that you created in Step 3.

    ⑰: Ephemeral Storage Size. Set the value to 100 GiB.

    image

    Container configuration:

    ⑱: Image. egs-registry.cn-hangzhou.cr.aliyuncs.com/egs/vllm.

    Ⲅ: Image Tag. 0.6.4.post1-pytorch2.5.1-cuda12.4-ubuntu22.04.

    ⑳: Startup Command. Copy the following commands to the corresponding fields as shown in the figure.

    /bin/bash
    -c
    git-lfs clone https://www.modelscope.cn/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B.git /oss-data/DeepSeek-R1-Distill-Qwen-7B
    This command uses git-lfs to clone the model from the ModelScope community repository to the /oss-data/DeepSeek-R1-Distill-Qwen-7B directory.

    image

    Advanced container settings:

    ㉑: Expand container-1 advanced settings.

    ㉒: CPU. 2 vCPU.

    ㉓: Memory. 4 GiB.

    ㉔: Turn on Storage and Add a volume mount.

    ㉕: Select oss-data.

    ㉖: Mount Path. /oss-data.

    ㉗: Click Next: Other Settings.

    image

    ㉘: Elastic IP Addresses. Select Auto Create.

    ㉙: Maximum Bandwidth. Set the value to 200 Mbit/s.

    ㉚: Click Confirm Configuration and complete the creation of the ECI instance as prompted.

    image

    Model weight file download starts automatically after the ECI instance is created. Proceed with Step 5 and Step 6 while the download runs.

    How to check if the download is complete

    After the download is complete, the status of the ECI instance changes to Run successfully in the ECI console.

    image

    In the Object Storage Service console, a folder named DeepSeek-R1-Distill-Qwen-7B is generated in the bucket.

    image

5. Create an ALB instance

Create an Application Load Balancer (ALB) instance as the service endpoint.

  1. In the console, create an ALB instance.

    ①②: Click Create ALB.

    image

    ③: Region. Select China (Hangzhou) to be consistent with the VPC that you created in Step 1.

    ④: Network Type. Select Public to provide services over the internet.

    ⑤: VPC. Select the VPC that you created in Step 1.

    ⑥: Zone and vSwitch. Select the vSwitches that you created in Step 1.

    ⑦: Instance Name. alb-eci-deepseek-7B.

    ⑧: Click Buy Now and then complete the creation of the ALB instance as prompted.

    image

    image

  2. In the console, create a listener and a backend server group for the ALB instance.

    ①②: Find the ALB instance that you created and click Create Listener in the Actions column.

    If you cannot find the ALB instance, switch to a different region in the upper-left corner of the page.

    image

    ③: Select HTTP as the protocol.

    ④: Set the listener port to 80.

    ⑤: Click Next.

    ⑥: Click Create Server Group.

    image

    image

    ⑦: Server Group Type. Select Server.

    ⑧: Server Group Name. eci-deepseek-7B.

    ⑨: VPC. Select the VPC that you created in Step 1. This parameter is automatically selected.

    ⑩: Select Backend Server Protocol. HTTP.

    ⑪⑫: Enable Health Check.

    ⑬: Health check method. Select GET.

    ⑭: Health check path. Set the value to /health. After the inference service starts, ALB uses the /health path to determine the service status.

    ⑮⑯⑰: Click Create, click Next, and then click Submit. Wait for the creation to complete.

    image

    image

    image

    image

    image

6. Create a scaling group

Create a scaling group associated with the ALB instance. The group automatically manages ECI instances and adds them to the ALB backend server group.

  1. In the Auto Scaling console, create a scaling group and associate it with the ALB instance.

    ①②③: Click Create Scaling Group.

    image

    ④: Scaling Group Name. deepseek-7B-servers.

    ⑤: Type. Select ECI.

    ⑥: Instance Configuration Source. Select Create from Scratch.

    ⑦: Minimum Number of Instances. Set this parameter to 0. This is the minimum number of instances in the scaling group.

    ⑧: Maximum Number of Instances. Set this parameter to 10. This is the maximum number of instances in the scaling group.

    ⑨: VPC. Select the VPC that you created in Step 1.

    ⑩: vSwitch. Select all the vSwitches that you created in Step 1.

    ⑪: Click Show Advanced Settings.

    image

    Advanced settings:

    ⑫⑬: Enable Expected Number of Instances and set the value to 0. This creates an empty scaling group.

    ⑭: Click Add Server Group and set the Type to ALB.

    ⑮: Server Group. Select the server group that you created in Step 5.

    ⑯: Port. Select 30000. The inference service deployed in the ECI instance will use this port to provide services.

    ⑰: Click Create. Wait for the scaling group to be created. Then, you can create a scaling configuration as prompted.

    image

    image

  2. In the Auto Scaling console, create a scaling configuration.

    A scaling configuration is a template for creating instances during scale-out events.

    ①②③: Find the scaling group that you created and click its ID to go to the details page.

    image

    ④⑤⑥: Click Instance Configuration Sources > Scaling Configuration > Create Scaling Configuration.

    image

    ⑦: Billing Method. Select Pay-As-You-Go.

    ⑧: Select a Security Group.

    image

    Container group configuration:

    ⑨: Select Specify Instance Type.

    ⑩: Instance Type. ecs.gn7i-c8g1.2xlarge.

    ⑪: Select Automatically Match Image Cache.

    ⑫: Expand Advanced Configuration.

    ⑬⑭⑮⑯: Select OSS Persistence. Configure the Bucket and instance RAM Role.

    ⑰: Ephemeral Storage Size. 100 GiB.

    ⑱: GPU Driver Version. tesla=550.

    image

    Container configuration:

    Ⲅ: Image. egs-registry.cn-hangzhou.cr.aliyuncs.com/egs/vllm.

    ⑳: Image Tag. 0.6.4.post1-pytorch2.5.1-cuda12.4-ubuntu22.04.

    ㉑: Startup Command. Copy the following commands to the corresponding fields as shown in the figure.

    /bin/bash
    -c
    vllm serve /oss-data/DeepSeek-R1-Distill-Qwen-7B --port 30000 --served-model-name DeepSeek-R1-Distill-Qwen-7B --tensor-parallel-size 1 --max-model-len=16384 --enforce-eager --dtype=half --api-key api-key-example-abc123
    This command reads the model weight files from OSS and starts the inference service on port 30000. The API key is set to api-key-example-abc123.

    image

    ㉒: Expand container-1 advanced settings.

    ㉓: CPU. Set the value to 8 vCPU.

    ㉔: Memory. Set the value to 30 GiB.

    ㉕: GPU. Set the value to 1.

    ㉖㉗: Turn on Storage and Add storage.

    ㉘: Mount Path. /oss-data

    ㉙: Click Next: Other Settings.

    image

    ㉚: Elastic IP Addresses. Select Auto Create.

    ㉛: Maximum Bandwidth. 200 Mbit/s.

    ㉜: Click Confirm Configuration and complete the creation of the scaling configuration as prompted.

    image

    ㉝㉞㉟: Enable the scaling configuration and start the scaling group as prompted.

    image

    image

    image

7. Start the service

Important

Before proceeding, ensure that the model weight files from Step 4 have completely downloaded.

Trigger a scale-out by setting the expected instance count. This example scales to five ECI instances.

After you adjust the expected number of instances, there is a delay before the new instances are created. You can monitor the progress on the Scaling Activities tab.

image

image

Next steps

Dify integration

  1. Log in to Dify.

  2. Add a model provider.

    1. Click your profile picture, select Settings, and then navigate to Model Provider. Find OpenAI-API-compatible and click Add.

      If it is not installed, follow the on-screen instructions to install the model provider.

      image

      image

    2. Complete the following configurations and click Save.

      • Model Type: LLM.

      • Model Name: DeepSeek-R1-Distill-Qwen-7B.

      • API Key: api-key-example-abc123. This key must be the same as the api-key that you configured in the startup command for the container group in Step 6.

      • API endpoint URL:

        Important

        Replace <alb_domain_name> with the domain name of your ALB instance.

        View the domain name of the ALB instance

        Go to the console, find the ALB instance that you created in Step 5, and view the domain name as shown in the figure.

        image

        http://<alb_domain_name>/v1
  3. Create and interact with a chat assistant application.

    image

    image

    image

Clean up resources

Release the following resources to stop incurring charges.

  1. Delete the scaling group. Deleting the scaling group that you created in Step 6 also releases the instances that were automatically created by it.

  2. Release the ALB instance and delete the server group. Delete the ALB instance and server group that you created in Step 5.

  3. Release the pay-as-you-go EIP. Delete the EIP that was created when you created the image cache in Step 4.

  4. Delete the image cache and delete the ECI instance. Delete the image cache and the temporary ECI instance that you created in Step 4.

  5. Delete the instance RAM role and delete the policy. Delete the instance RAM role and policy that you created in Step 3.

  6. Delete the OSS bucket. Delete the OSS bucket that you created in Step 2.

  7. Delete the VPC. Delete the VPC that you created in Step 1.

Production considerations

Consider the following improvements for production environments.