Published on December 28, 2024 by Australian AI Company
Milvus is a powerful open-source vector database designed for AI applications and similarity search at scale. In this comprehensive tutorial, you'll learn how to deploy Milvus on Azure Container Instances (ACI) using Docker Compose, providing a scalable and cost-effective solution for your vector database needs.
This guide will walk you through the complete process of setting up Milvus v2.6.0-rc1 on Azure, including etcd for metadata storage and MinIO for object storage, all orchestrated through Azure Container Instances.
Before we begin, ensure you have the following:
First, we'll create the necessary Azure resources including a resource group and storage account for persistent data.
First, we'll define the variables for our deployment. You can customize these values based on your preferences:
RESOURCE_GROUP="milvus-aci-rg-v2"
LOCATION="australiaeast"
STORAGE_ACCOUNT="milvusstorage$RANDOM"
FILE_SHARE="milvus-data"
You can copy the following code and paste it into your terminal to set up the environment variables:
RESOURCE_GROUP="milvus-aci-rg-v2"
LOCATION="australiaeast"
STORAGE_ACCOUNT="milvusstorage$RANDOM"
FILE_SHARE="milvus-data"
Create a new resource group to organize all our Milvus-related resources:
# Create a Resource Group
az group create --name $RESOURCE_GROUP --location $LOCATION
Create an Azure Storage Account that will provide persistent storage for our Milvus data:
az storage account create --name $STORAGE_ACCOUNT --resource-group $RESOURCE_GROUP --location $LOCATION --sku Standard_LRS
Retrieve the storage account key and create a file share for persistent data storage:
az storage account keys list \
--resource-group $RESOURCE_GROUP \
--account-name $STORAGE_ACCOUNT \
Create a file share for persistent data storage:
az storage share create --name $FILE_SHARE --account-name $STORAGE_ACCOUNT --account-key $STORAGE_KEY
Now we'll create the Azure Container Instances YAML configuration file that defines our Milvus deployment with all required services.
Create a file named deploy-aci-v2.yml
with the following content:
# ACI Configuration File for Milvus Standalone (v2.6.0-rc1)
apiVersion: 2023-05-01
location: australiaeast
name: milvus-container-group-v2
properties:
containers:
- name: milvus-etcd
properties:
image: quay.io/coreos/etcd:v3.5.18
resources:
requests:
cpu: 1.0
memoryInGB: 2.0
command:
- etcd
- -advertise-client-urls=http://localhost:2379
- -listen-client-urls
- http://0.0.0.0:2379
- --data-dir
- /etcd
environmentVariables:
- name: 'ETCD_AUTO_COMPACTION_MODE'
value: 'revision'
- name: 'ETCD_AUTO_COMPACTION_RETENTION'
value: '1000'
- name: 'ETCD_QUOTA_BACKEND_BYTES'
value: '4294967296'
- name: 'ETCD_SNAPSHOT_COUNT'
value: '50000'
volumeMounts:
- name: milvus-data-volume
mountPath: /etcd
livenessProbe:
exec:
command:
- etcdctl
- endpoint
- health
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 20
failureThreshold: 3
- name: milvus-minio
properties:
image: minio/minio:RELEASE.2023-03-20T20-16-18Z
resources:
requests:
cpu: 1.0
memoryInGB: 2.0
ports:
- port: 9000
protocol: TCP
- port: 9001
protocol: TCP
command:
- /bin/sh
- -c
- "minio server /minio_data --console-address :9001"
environmentVariables:
- name: 'MINIO_ACCESS_KEY'
value: 'minioadmin'
- name: 'MINIO_SECRET_KEY'
value: 'minioadmin'
volumeMounts:
- name: milvus-data-volume
mountPath: /minio_data
livenessProbe:
exec:
command:
- /bin/sh
- -c
- "curl -f http://localhost:9000/minio/health/live"
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 20
failureThreshold: 3
- name: milvus-standalone
properties:
image: milvusdb/milvus:v2.6.0-rc1
resources:
requests:
cpu: 2.0
memoryInGB: 4.0
ports:
- port: 19530
protocol: TCP
- port: 9091
protocol: TCP
command:
- milvus
- run
- standalone
environmentVariables:
- name: 'ETCD_ENDPOINTS'
value: 'localhost:2379'
- name: 'MINIO_ADDRESS'
value: 'localhost:9000'
- name: 'MQ_TYPE'
value: 'woodpecker'
volumeMounts:
- name: milvus-data-volume
mountPath: /var/lib/milvus
livenessProbe:
exec:
command:
- /bin/sh
- -c
- "curl -f http://localhost:9091/healthz"
initialDelaySeconds: 90
periodSeconds: 30
timeoutSeconds: 20
failureThreshold: 3
osType: Linux
ipAddress:
type: Public
ports:
- port: 19530
protocol: TCP
- port: 9091
protocol: TCP
- port: 9000
protocol: TCP
- port: 9001
protocol: TCP
dnsNameLabel: milvus-v2-demo-$RANDOM
volumes:
- name: milvus-data-volume
azureFile:
shareName: milvus-data
storageAccountName: YOUR_STORAGE_ACCOUNT_NAME
storageAccountKey: YOUR_STORAGE_ACCOUNT_KEY
YOUR_STORAGE_ACCOUNT_NAME
and YOUR_STORAGE_ACCOUNT_KEY
with the actual values from your Azure Storage Account.
Now we'll deploy our Milvus configuration to Azure Container Instances:
Replace the placeholder values in the YAML file with your actual storage account details:
# Replace placeholder values in the YAML file
sed -i.bak "s/YOUR_STORAGE_ACCOUNT_NAME/$STORAGE_ACCOUNT/g" deploy-aci-v2.yml
sed -i.bak "s/YOUR_STORAGE_ACCOUNT_KEY/$STORAGE_KEY/g" deploy-aci-v2.yml
Create the container group with all Milvus services:
# Deploy the container group
az container create \
--resource-group $RESOURCE_GROUP \
--file deploy-aci-v2.yml
Retrieve the public IP address of your deployed container group:
# Get the public IP address
az container show \
--resource-group $RESOURCE_GROUP \
--name milvus-container-group-v2 \
--query ipAddress.ip \
--output tsv
After deployment, verify that all services are running correctly:
Verify that all containers in the group are running properly:
# Check container status
az container show \
--resource-group $RESOURCE_GROUP \
--name milvus-container-group-v2 \
--query containers[].instanceView.currentState
Test the Milvus health endpoint (replace YOUR_PUBLIC_IP with your actual IP):
# Test Milvus connection (replace IP with your actual IP)
curl -X GET "http://YOUR_PUBLIC_IP:9091/healthz"
Verify that MinIO object storage is accessible:
# Test MinIO access
curl -X GET "http://YOUR_PUBLIC_IP:9000/minio/health/live"
Once deployed, you can connect to your Milvus instance using the Python SDK:
Use the following Python code to connect to your Milvus instance:
from pymilvus import connections, Collection
# Connect to Milvus
connections.connect(
alias="default",
host="YOUR_PUBLIC_IP", # Replace with your ACI public IP
port="19530"
)
# Verify connection
print("Connected to Milvus successfully!")
# You can now create collections and perform operations
# Example: List collections
from pymilvus import utility
print("Collections:", utility.list_collections())
If you encounter issues during deployment:
az container logs --resource-group $RESOURCE_GROUP --name milvus-container-group-v2 --container-name milvus-standalone
Now that you have Milvus running on Azure, you can:
Copyright © 2024 Australian AI Company