Download models from modelscope using Kubernetes Jobs, also supports using docker.
When I deploy models on my clusters I use the following solution:
- On all the "model deployment capable" nodes I have SSD disks mounted on specific locations. The nodes are labeled so I can target them with selectors.
- I pre-decide which nodes could run these models, let's say I want to deploy a 400B model, I see it could run on 3 servers.
- I copy the model to the model SSD disk on the target nodes, and label them to mark it has it, for example, if the model was Qwen/Qwen3.5-397B-A17B, it would be located on the model mount path at
/Qwen/Qwen3.5-397B-A17Band the nodes with this model are labeled likehas-model/Qwen_Qwen3.5-397B-A17B=1 - When I deploy the inference servers, I use nodeSelectors to let Kubernetes decide which node to run, the model is bind-mounted to
/model.
This solution avoids repeating model download, you spend a little more time preparing but it is faster to boot.
This project provides a container image, Helm chart, and helper scripts to download these models (from modelscope). The download runs as a Kubernetes Job, making it easy to manage and monitor.
modelscope-download-job/
├── compose.yaml # Docker Compose for local testing
├── docker/
│ └── Dockerfile # Container image definition
├── README.md # This file
├── chart/
│ ├── Chart.yaml # Helm chart metadata
│ ├── values.yaml # Default configuration values
│ └── templates/
│ ├── helpers.tpl # Template helper functions
│ ├── job.yaml # Job template
│ └── pvc.yaml # PVC template (for new PVC)
└── scripts/
├── download-model.sh # Linux/macOS helper script
└── download-model.ps1 # Windows PowerShell helper script
The docker/Dockerfile creates a Python-based container with modelscope pre-installed.
| Argument | Default | Description |
|---|---|---|
REGISTRY |
docker.io |
Container registry |
PIP_INDEX_URL |
https://pypi.org/simple |
PyPI package index |
# Build with default settings (no registry prefix)
docker build -t aaronps/modelscope-download:latest ./docker
# Build with custom registry
docker build --build-arg REGISTRY=ghcr.io -t ghcr.io/aaronps/modelscope-download:latest ./docker
# Build with custom pip index
docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple -t aaronps/modelscope-download:latest ./dockerFor local development or testing, you can use Docker Compose:
# Download model using environment variable
docker compose run --rm -e MODEL=Qwen/Qwen3.5-9B download
# Download preconfigured Qwen model
docker compose run --rm download-qwenThe compose file defines three services:
template- Base configuration (not run directly)download- UsesMODELenvironment variable (passed via-e)download-qwen- Preconfigured for Qwen/Qwen3.5-0.8B
Note: The
downloadservice uses shell expansion ($$MODEL) to read the environment variable at runtime, whiledownload-qwenhas the model hardcoded in the command. This is becausedocker compose run -esets the environment variable in the container, but the command is parsed when the service is defined.
You can use the same idea to download the models using docker command directly.
The Helm chart creates a Kubernetes Job that runs modelscope download.
# Download with local bind-mount (requires nodeSelector to match the node with the path)
helm template download-qwen35 ./chart \
--set model=Qwen/Qwen3.5-9B \
--set storage.local.path=/mnt/data/models \
--set nodeSelector.kubernetes\.io/hostname=test \
| kubectl apply -f - -n mynamespace
# Download with existing PVC
helm template . download-qwen35 \
--set model=Qwen/Qwen3.5-9B \
--set storage.pvc.name=my-pvc \
| kubectl apply -f - -n mynamespace
# Download with new PVC
helm template . download-qwen35 \
--set model=Qwen/Qwen3.5-9B \
--set storage.newPvc.name=models-pvc \
--set storage.newPvc.size=50Gi \
| kubectl apply -f - -n mynamespace
# Download on specific node
helm template . download-qwen35 \
--set model=Qwen/Qwen3.5-9B \
--set storage.local.path=/mnt/data/models \
--set nodeSelector.kubernetes\.io/hostname=test \
| kubectl apply -f - -n mynamespace | Key | Type | Default | Description |
|---|---|---|---|
global.imageRegistry |
string | "" |
Global container registry (used if image.registry is empty) |
image.registry |
string | "" |
Container registry (overrides global) |
image.repository |
string | aaronps/modelscope-download |
Image repository |
image.tag |
string | latest |
Image tag |
image.pullPolicy |
string | IfNotPresent |
Image pull policy |
model |
string | "" |
Required Model name (e.g., Qwen/Qwen3.5-9B) |
downloadPath |
string | "" |
Path within /data (defaults to model name) |
storage.local.path |
string | "" |
Host path for local bind-mount |
storage.local.type |
string | Directory |
Host path type |
storage.pvc.name |
string | "" |
Existing PVC name |
storage.newPvc.name |
string | "" |
New PVC name |
storage.newPvc.size |
string | "" |
New PVC size (required if newPvc.name is set) |
storage.newPvc.storageClass |
string | "" |
Storage class for new PVC |
nodeSelector |
object | {} |
Node selector labels |
tolerations |
array | [] |
Pod tolerations |
affinity |
object | {} |
Pod affinity rules |
job.backoffLimit |
int | 3 |
Number of retry attempts |
job.activeDeadlineSeconds |
int | `` | Job timeout |
job.ttlSecondsAfterFinished |
int | `` | TTL for completed job |
pod.restartPolicy |
string | Never |
Pod restart policy |
resources |
object | {} |
Resource limits/requests |
imagePullSecrets |
array | [] |
Image pull secrets |
# Make script executable
chmod +x scripts/download-model.sh
# Download with local bind-mount
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B -l /mnt/models
# Download with existing PVC
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B -p my-pvc
# Download with new PVC
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B --new-pvc model-pvc 50Gi
# Download on specific node, remeber to escape dots.
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B -l /mnt/models --node-selector kubernetes\\.io/hostname=worker-1
# Dry run (show YAML without applying)
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B -l /mnt/models --dry-run# Download with local bind-mount
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -LocalPath "/mnt/models"
# Download with existing PVC
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -PvcName "my-pvc"
# Download with new PVC, on powershell you need to use a comma to separate both values.
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -NewPvc model-pvc, 50Gi
# Download on specific node, escape the dot on kuberente.io
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -LocalPath "/mnt/models" -NodeSelector "kubernetes\.io/hostname=worker-1"
# Dry run (show YAML without applying)
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -LocalPath "/mnt/models" -DryRun