All Products
Search
Document Center

Elastic Container Instance:Deploy and autoscale DeepSeek-R1 series models

Last Updated:Aug 28, 2026

Use DataCache to quickly deploy a DeepSeek-R1 series model on Elastic Container Instance (ECI), and auto-scale the inference service with a HorizontalPodAutoscaler (HPA) that reads custom GPU metrics.

Why deploy DeepSeek on ECI

  • Elastic Container Instance (ECI) offers zero O&M, flexible deployment, high elasticity, and low cost. For more information, see Benefits.

  • With its DataCache and ImageCache features, ECI saves time pulling container images and downloading models, reduces network resource consumption, and improves system efficiency.

    Note

    Deploying a containerized large model inference service involves several stages: container creation and startup, container image pulling, model file downloading, and the inference service loading the model and starting up. Because these container images and models are large (for example, the vLLM image is about 16.5 GB and the DeepSeek-R1-Distill-Qwen-7B model is about 14 GB), pulling them consumes significant time and network bandwidth. ECI uses ImageCache and DataCache to save time pulling images and downloading models.

Prerequisites

  • A DataCache custom resource definition (CRD) deployed in the cluster. See Deploy a DataCache CRD.

  • A virtual private cloud (VPC) with an Internet NAT gateway and an SNAT entry configured, so resources in the VPC can reach the internet.

    Note
    If no Internet NAT gateway is available, associate an Elastic IP Address (EIP) with the VPC before creating the DataCache and deploying the application.
  • Managed Service for Prometheus — The Managed Service for Prometheus component is deployed in the cluster. For instructions, see Connect and configure Managed Service for Prometheus.

  • ack-alibaba-cloud-metrics-adapter — The ack-alibaba-cloud-metrics-adapter component is deployed in the cluster.

    To deploy the component, log on to the Container Service for Kubernetes (ACK) console and use the Marketplace > Marketplace page.

  • KServe — KServe is deployed in the cluster. KServe is a Kubernetes-based machine learning model serving framework that uses Kubernetes CRDs to deploy one or more trained models to a model serving runtime. For instructions, see Install the ack-kserve component.

  • Ingress gateway — An ingress gateway exposes the inference service. The verification steps in this topic read the IP address of the nginx-ingress-lb service in the kube-system namespace. Adjust the service name and namespace to match your cluster.

  • GPU instance type — The GPU instance types specified for the deployment meet the requirements listed in the following section.

Prepare the environment

Different DeepSeek models have different runtime requirements. This topic uses the DeepSeek-R1-Distill-Qwen-7B model as an example.

  • Recommended instance types

    The GPU instance type must meet the following requirements. For a list of GPU instance types that ECI supports, see ECI instance types.

    • CPU: No strict limit

    • Memory: > 16 GiB

    • GPU: ≥ 1

    • GPU memory: ≥ 20 GB. An A10 GPU is recommended. Insufficient GPU memory may cause an out-of-memory (OOM) error.

  • Software environment

    Deploying large models involves many libraries and configurations. vLLM is a popular inference engine for large models. This topic uses vLLM to deploy the inference service. ECI provides a public container image that you can use directly or as a base image for further development. The image is available at registry.cn-hangzhou.aliyuncs.com/eci_open/vllm-openai:v0.7.2, and its size is approximately 16.5 GB.

Step 1: Create a DataCache

For first-time use, create a DataCache in advance. This removes the wait for pulling model data inside the pod and accelerates the DeepSeek deployment.

  1. Go to Hugging Face and get the model ID.

    This example uses the main revision of the DeepSeek-R1-Distill-Qwen-7B model. After you find the model on Hugging Face, you can copy the model ID from the top of the model details page.

  2. Create a DataCache from a YAML configuration file to pull the DeepSeek-R1-Distill-Qwen-7B model.

    kubectl create -f datacache-test.yaml

    The following is an example of the datacache-test.yaml file:

    apiVersion: eci.aliyun.com/v1alpha1
    kind: DataCache
    metadata:
      name: deepseek-r1-distill-qwen-7b
    spec:
      bucket: test
      path: /model/deepseek-r1-distill-qwen-7b
      dataSource:
        type: URL
        options:
          repoSource: HuggingFace/Model                          # The data source is a Hugging Face model.
          repoId: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B        # The model ID.
          revision: main                                         # The model revision.
      netConfig:
        securityGroupId: sg-bp1***********
        vSwitchId: vsw-bp1uo************                 # A vSwitch with SNAT configured.
        # If the vSwitch has no SNAT configured for internet access, an EIP is automatically created and associated.
        eipCreateParam:                                  
          bandwidth: 5                                   # The EIP bandwidth.
  3. Query the status of the DataCache.

    kubectl get edc

    The DataCache is ready to use when its status changes to Available. Alibaba Cloud provides a warm-loading feature for DeepSeek-R1 series models, which allows you to create a DataCache in seconds.

    NAME                          AGE   DATACACHEID                STATUS      PROGRESS   BUCKET    PATH
    deepseek-r1-distill-qwen-7b   40s   edc-uf6btsb4q5j4b9ue****   Available   100%       test      /model/deepseek-r1-distill-qwen-7b

Step 2: Configure GPU metric adapter rules

Auto scaling based on custom metrics relies on the ack-alibaba-cloud-metrics-adapter component provided by ACK and the Kubernetes HPA mechanism. The following table describes the metrics that GPU HPA supports. For details, see Auto scaling based on GPU metrics.

Metric name

Description

Unit

DCGM_FI_DEV_GPU_UTIL

The utilization of the GPU card. This metric is valid only for exclusive GPU scheduling.

%

DCGM_FI_DEV_FB_USED

The GPU memory usage of the GPU card. This metric is valid only for exclusive GPU scheduling.

MiB

DCGM_CUSTOM_PROCESS_SM_UTIL

The GPU utilization of the container.

%

DCGM_CUSTOM_PROCESS_MEM_USED

The GPU memory usage of the container.

MiB

  1. Log on to the Container Service for Kubernetes (ACK) console. On the Clusters page, click the name of the target cluster.

  2. In the left-side navigation pane of the cluster management page, choose Applications > Helm.

  3. In the Helm list, find ack-alibaba-cloud-metrics-adapter and click Update in the Actions column.

  4. Add rules under the custom field as needed.

    Click to expand the rules

    - metricsQuery: avg(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
      resources:
        overrides:
          NodeName:
            resource: node
      seriesQuery: DCGM_FI_DEV_GPU_UTIL{} # GPU utilization.
    - metricsQuery: avg(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
      resources:
        overrides:
          NamespaceName:
            resource: namespace
          NodeName:
            resource: node
          PodName:
            resource: pod
      seriesQuery: DCGM_CUSTOM_PROCESS_SM_UTIL{} # Container GPU utilization.
    - metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
      resources:
        overrides:
          NodeName:
            resource: node
      seriesQuery: DCGM_FI_DEV_FB_USED{} # GPU memory usage.
    - metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
      resources:
        overrides:
          NamespaceName:
            resource: namespace
          NodeName:
            resource: node
          PodName:
            resource: pod
      seriesQuery: DCGM_CUSTOM_PROCESS_MEM_USED{} # Container GPU memory usage.
    - metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>) / sum(DCGM_CUSTOM_CONTAINER_MEM_ALLOCATED{}) by (<<.GroupBy>>)
      name:
        as: ${1}_GPU_MEM_USED_RATIO
        matches: ^(.*)_MEM_USED
      resources:
        overrides:
          NamespaceName:
            resource: namespace
          PodName:
            resource: pod
      seriesQuery: DCGM_CUSTOM_PROCESS_MEM_USED{NamespaceName!="",PodName!=""}  # Container GPU memory utilization.

Step 3: Deploy the DeepSeek inference service with auto scaling

  1. Create a YAML configuration file for the application, and then use it to deploy the DeepSeek inference application.

    kubectl create -f deepseek-r1-7b-kserve.yaml

    The configuration works as follows:

    • It uses a GPU instance type, mounts the DeepSeek-R1-Distill-Qwen-7B model.

    • The predictor of the InferenceService uses an image that contains vLLM. After the container starts, it runs vllm serve /deepseek-r1-7b --tensor-parallel-size 1 --max-model-len 24384 --enforce-eager to start the OpenAI-compatible server.

    • It scales the application on the DCGM_CUSTOM_PROCESS_SM_UTIL metric, which is the GPU utilization of the container. The example sets a target average value of 50, so the HPA scales out the application when the average utilization reaches 50%, up to the number of pods specified by maxReplicas. Adjust averageValue to match your own latency and throughput targets.

    The following code provides an example of the deepseek-r1-7b-kserve.yaml file:

    apiVersion: serving.kserve.io/v1beta1
    kind: InferenceService
    metadata:
     name: deepseek-r1-7b-kserve
     labels:
       alibabacloud.com/eci: "true"
     annotations:
       serving.kserve.io/autoscalerClass: external
       k8s.aliyun.com/eci-use-specs: ecs.gn7i-c16g1.4xlarge,ecs.gn7i-c32g1.8xlarge  # Specify GPU instance types. Specifying multiple types reduces the risk of insufficient inventory.
       k8s.aliyun.com/eci-extra-ephemeral-storage: "20Gi"   # The frameworks required at startup are large, so additional temporary storage space is required (billable).
       k8s.aliyun.com/eci-data-cache-bucket: "test"      # Specify the DataCache bucket.
       # If you require faster loading, enable an ESSD AutoPL disk.
       k8s.aliyun.com/eci-data-cache-provisionedIops: "15000"   # Set the provisioned read/write IOPS of the ESSD AutoPL disk.
       k8s.aliyun.com/eci-data-cache-burstingEnabled: "true"    # Enable bursting for the ESSD AutoPL disk to accelerate application startup.
    spec:
     predictor:
       containers:
         - name: vllm
           command:
             - /bin/sh
           args:
             - -c
             - vllm serve /deepseek-r1-7b --port 8080 --tensor-parallel-size 1 --max-model-len 24384 --enforce-eager
           image: registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/vllm-openai:v0.7.2
           resources:
             limits:
               cpu: "16"
               memory: "60Gi"
               nvidia.com/gpu: "1"
             requests:
               cpu: "16"
               memory: "60Gi"
               nvidia.com/gpu: "1"
           volumeMounts:
             - mountPath: /deepseek-r1-7b # The path of the model.
               name: llm-model
       volumes:
         - name: llm-model
           hostPath:
             path: /model/deepseek-r1-distill-qwen-7b  # The path where the data is stored.
    ---
    apiVersion: autoscaling/v2
    kind: HorizontalPodAutoscaler
    metadata:
     name: deepseek-r1-7b-kserve-predictor
     namespace: default
    spec:
     scaleTargetRef:
       apiVersion: apps/v1
       kind: Deployment
       name: deepseek-r1-7b-kserve-predictor
     metrics:
       - pods:
           metric:
             name: DCGM_CUSTOM_PROCESS_SM_UTIL       # The name of the metric to monitor.
           target:
             type: AverageValue                     # The target type. AverageValue is required when you set averageValue.
             averageValue: '50'                     # The target average value of the metric.
         type: Pods
     minReplicas: 1                                # The minimum number of pods to keep running.
     maxReplicas: 100                              # The maximum number of pods allowed.

    The following output is returned:

    inferenceservice.serving.kserve.io/deepseek-r1-7b-kserve created
    horizontalpodautoscaler.autoscaling/deepseek-r1-7b-kserve-predictor created

  2. Check the deployment status of the application.

    kubectl get pods --selector=app=isvc.deepseek-r1-7b-kserve-predictor

    The following output is returned:

    NAME                                               READY   STATUS    RESTARTS   AGE
    deepseek-r1-7b-kserve-predictor-6785df7b7f-r7kjx   1/1     Running   0          116s

Step 4: Verify the inference service

  1. Get the IP address and hostname of the load balancing service that corresponds to the DeepSeek inference application, and set them as variables.

    NGINX_INGRESS_IP=$(kubectl -n kube-system get svc nginx-ingress-lb -ojsonpath='{.status.loadBalancer.ingress[0].ip}')
    SERVICE_HOSTNAME=$(kubectl get inferenceservice deepseek-r1-7b-kserve -o jsonpath='{.status.url}' | cut -d "/" -f 3)

    If NGINX_INGRESS_IP is empty, the ingress service name or namespace in your cluster differs from the example. Adjust the command accordingly.

  2. Send an inference request to the model inference service.

curl -X POST http://$NGINX_INGRESS_IP:80/v1/chat/completions \
    -H "Host: $SERVICE_HOSTNAME" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "/deepseek-r1-7b",
          "messages": [
              {
                  "role": "user",
                  "content": "Briefly describe a container in one sentence"
              }
          ],
          "temperature": 0.6,
          "max_tokens": 3000
        }' \
    --verbose

The following output is returned:

{"id":"chatcmpl-56e6ff393d999571ce6ead1b72f9302d","object":"chat.completion","created":1739340308,"model":"/deepseek-r1-7b","choices":[{"index":0,"message":{"role":"assistant","reasoning_content":null,"content":"<think>\nWell, I need to briefly introduce containers. What is a container? I remember that in programming, especially when using Docker, a container seems to be an isolated environment that lets an application run independently. Containerization makes development and deployment more convenient, right? So a container should be a lightweight runtime that isolates an application and its dependencies and makes development and deployment more efficient. Right? So a one-sentence introduction to containers should cover isolation, being lightweight, and independent resource operation. It might also mention where containerization is used, such as cloud-native and microservices architectures. OK, now I'll organize these thoughts into one sentence.\n</think>\n\nA container is an isolated runtime environment that allows an application to run independently, provides lightweight and efficient resource management, and supports cloud-native and microservices architectures.","tool_calls":[]},"logprobs":null,"finish_reason":"stop","stop_reason":null}],"usage":{"prompt_tokens":8,"total_tokens":168,"completion_tokens":160,"prompt_tokens_details":null},"prompt_logprobs":null}

The content within the <think></think> tags records the intermediate reasoning steps that the model performs before it generates the final answer, and is not part of the final answer. The final answer is the following text:

A container is an isolated runtime environment that allows an application to run independently, provides lightweight and efficient resource management, and supports cloud-native and microservices architectures.

Step 5: Verify auto scaling

  1. View the pods.

    kubectl get pods --selector=app=isvc.deepseek-r1-7b-kserve-predictor

    The following output is returned. One pod is running.

    NAME                                               READY   STATUS    RESTARTS   AGE
    deepseek-r1-7b-kserve-predictor-6785df7b7f-r7kjx   1/1     Running   0          6m54s
  2. View the HPA.

    kubectl get hpa

    The following output is returned. The TARGETS column shows the current average value of DCGM_CUSTOM_PROCESS_SM_UTIL across the tracked pods against the target average value of 50.

    NAME                              REFERENCE                                    TARGETS    MINPODS   MAXPODS   REPLICAS   AGE
    deepseek-r1-7b-kserve-predictor   Deployment/deepseek-r1-7b-kserve-predictor   9/50       1         100       1          8m
  3. Run a stress test with Hey.

    hey -z 2m -c 20 -m POST -host $SERVICE_HOSTNAME -H "Content-Type: application/json" -d '{"model": "/deepseek-r1-7b", "messages": [{"role": "user", "content": "hello world!"}], "max_tokens": 512, "temperature": 0.7, "top_p": 0.9, "seed": 10}' http://$NGINX_INGRESS_IP:80/v1/chat/completions

    For more information about the Hey stress testing tool, see Hey.

  4. View the pods again to confirm the scale-out.

    kubectl get pods --selector=app=isvc.deepseek-r1-7b-kserve-predictor

    The following output is returned. The application has been automatically scaled out.

    NAME                                               READY   STATUS    RESTARTS   AGE
    deepseek-r1-7b-kserve-predictor-6785df7b7f-r7kjx   1/1     Running   0          8m5s
    deepseek-r1-7b-kserve-predictor-6785df7b7f-6l2kj   1/1     Running   0          104s
    deepseek-r1-7b-kserve-predictor-6785df7b7f-3q5dz   1/1     Running   0          104s
  5. View the HPA again.

kubectl get hpa

The following output is returned. REPLICAS has increased from 1 to 3. Because TARGETS reports an average across the tracked pods, the reading can drop after the new pods start serving traffic.

NAME                              REFERENCE                                    TARGETS    MINPODS   MAXPODS   REPLICAS   AGE
deepseek-r1-7b-kserve-predictor   Deployment/deepseek-r1-7b-kserve-predictor   5/50       1         100       3          10m