部署方案 #

一、部署方式概览 #

text
Milvus部署方式:

┌─────────────────────────────────────────┐
│           部署方式选择                   │
├─────────────────────────────────────────┤
│                                         │
│  ┌─────────────────────────────────┐   │
│  │  开发测试                        │   │
│  │  - Docker Compose               │   │
│  │  - Docker单容器                  │   │
│  └─────────────────────────────────┘   │
│                                         │
│  ┌─────────────────────────────────┐   │
│  │  生产环境                        │   │
│  │  - Kubernetes + Milvus Operator │   │
│  │  - Helm Chart                   │   │
│  └─────────────────────────────────┘   │
│                                         │
│  ┌─────────────────────────────────┐   │
│  │  云服务                          │   │
│  │  - Zilliz Cloud                 │   │
│  │  - 阿里云、AWS等                 │   │
│  └─────────────────────────────────┘   │
│                                         │
└─────────────────────────────────────────┘

二、Kubernetes部署 #

2.1 前置条件 #

bash
kubectl version --short

helm version

kubectl get nodes

2.2 安装Milvus Operator #

bash
kubectl apply -f https://github.com/zilliztech/milvus-operator/releases/download/v0.9.0/milvus-operator.yaml

kubectl get pods -n milvus-operator

2.3 部署Milvus集群 #

yaml
apiVersion: milvus.io/v1beta1
kind: Milvus
metadata:
  name: my-release
  namespace: milvus
spec:
  mode: cluster
  components:
    proxy:
      replicas: 2
      resources:
        requests:
          cpu: "1"
          memory: "2Gi"
        limits:
          cpu: "2"
          memory: "4Gi"
    queryNode:
      replicas: 3
      resources:
        requests:
          cpu: "2"
          memory: "8Gi"
        limits:
          cpu: "4"
          memory: "16Gi"
    dataNode:
      replicas: 2
      resources:
        requests:
          cpu: "1"
          memory: "4Gi"
        limits:
          cpu: "2"
          memory: "8Gi"
    indexNode:
      replicas: 2
      resources:
        requests:
          cpu: "2"
          memory: "8Gi"
        limits:
          cpu: "4"
          memory: "16Gi"
  config:
    common:
      retentionDuration: 432000
    dataCoord:
      segment:
        maxSize: 512
  dependencies:
    etcd:
      inCluster:
        values:
          replicaCount: 3
    pulsar:
      inCluster:
        values:
          broker:
            replicaCount: 2
    minio:
      inCluster:
        values:
          mode: distributed
          replicas: 4
bash
kubectl apply -f milvus-cluster.yaml

kubectl get pods -n milvus

2.4 部署单机版 #

yaml
apiVersion: milvus.io/v1beta1
kind: Milvus
metadata:
  name: my-standalone
  namespace: milvus
spec:
  mode: standalone
  components:
    resources:
      requests:
        cpu: "2"
        memory: "8Gi"
      limits:
        cpu: "4"
        memory: "16Gi"
  dependencies:
    etcd:
      inCluster:
        values:
          replicaCount: 1
    minio:
      inCluster:
        values:
          mode: standalone

三、Helm部署 #

3.1 添加Helm仓库 #

bash
helm repo add milvus https://zilliztech.github.io/milvus-helm/
helm repo update

3.2 创建命名空间 #

bash
kubectl create namespace milvus

3.3 部署Milvus #

bash
helm install my-release milvus/milvus \
  --namespace milvus \
  --set cluster.enabled=true \
  --set proxy.replicas=2 \
  --set queryNode.replicas=3 \
  --set dataNode.replicas=2 \
  --set etcd.replicaCount=3 \
  --set minio.mode=distributed \
  --set minio.replicas=4

3.4 自定义values.yaml #

yaml
cluster:
  enabled: true

image:
  repository: milvusdb/milvus
  tag: v2.4.0
  pullPolicy: IfNotPresent

proxy:
  replicas: 2
  resources:
    requests:
      cpu: "1"
      memory: "2Gi"
    limits:
      cpu: "2"
      memory: "4Gi"
  service:
    type: LoadBalancer
    port: 19530

queryNode:
  replicas: 3
  resources:
    requests:
      cpu: "2"
      memory: "8Gi"
    limits:
      cpu: "4"
      memory: "16Gi"

dataNode:
  replicas: 2
  resources:
    requests:
      cpu: "1"
      memory: "4Gi"
    limits:
      cpu: "2"
      memory: "8Gi"

indexNode:
  replicas: 2
  resources:
    requests:
      cpu: "2"
      memory: "8Gi"
    limits:
      cpu: "4"
      memory: "16Gi"

etcd:
  replicaCount: 3
  resources:
    requests:
      cpu: "500m"
      memory: "1Gi"

pulsar:
  enabled: true
  broker:
    replicaCount: 2

minio:
  mode: distributed
  replicas: 4
  resources:
    requests:
      cpu: "500m"
      memory: "1Gi"

logs:
  level: info
bash
helm install my-release milvus/milvus \
  --namespace milvus \
  -f values.yaml

四、服务暴露 #

4.1 LoadBalancer #

yaml
proxy:
  service:
    type: LoadBalancer
    port: 19530
    annotations:
      service.beta.kubernetes.io/aws-load-balancer-type: nlb

4.2 NodePort #

yaml
proxy:
  service:
    type: NodePort
    port: 19530
    nodePort: 30001

4.3 Ingress #

yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: milvus-ingress
  namespace: milvus
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: grpc
spec:
  rules:
  - host: milvus.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-release-milvus
            port:
              number: 19530

五、存储配置 #

5.1 持久化存储 #

yaml
minio:
  persistence:
    enabled: true
    storageClass: "standard"
    accessMode: ReadWriteOnce
    size: 100Gi

etcd:
  persistence:
    enabled: true
    storageClass: "standard"
    accessMode: ReadWriteOnce
    size: 10Gi

pulsar:
  bookkeeper:
    volumes:
      journal:
        size: 10Gi
      ledgers:
        size: 50Gi

5.2 使用外部存储 #

yaml
externalS3:
  enabled: true
  host: "s3.amazonaws.com"
  port: "443"
  accessKey: "your-access-key"
  secretKey: "your-secret-key"
  useSSL: true
  bucketName: "milvus-bucket"
  rootPath: "milvus"

六、监控配置 #

6.1 启用监控 #

yaml
metrics:
  enabled: true
  serviceMonitor:
    enabled: true
    namespace: monitoring
    labels:
      release: prometheus

log:
  level: info
  file:
    enabled: true
    path: /var/log/milvus

6.2 Prometheus配置 #

yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: milvus-monitor
  namespace: monitoring
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: milvus
  endpoints:
  - port: metrics
    interval: 30s

6.3 Grafana Dashboard #

bash
kubectl apply -f https://raw.githubusercontent.com/milvus-io/milvus/master/deployments/exporter/grafana-dashboard.json

七、云服务部署 #

7.1 Zilliz Cloud #

text
Zilliz Cloud特点:

┌─────────────────────────────────────────┐
│           Zilliz Cloud                   │
├─────────────────────────────────────────┤
│  优点:                                  │
│  - 全托管服务                            │
│  - 自动扩缩容                            │
│  - 高可用保障                            │
│  - 专业支持                              │
│  - 免运维                                │
├─────────────────────────────────────────┤
│  部署步骤:                              │
│  1. 注册Zilliz Cloud账号                 │
│  2. 创建集群                             │
│  3. 获取连接信息                         │
│  4. 使用SDK连接                          │
└─────────────────────────────────────────┘

7.2 连接Zilliz Cloud #

python
from pymilvus import connections

connections.connect(
    alias="default",
    host="your-cluster.zillizcloud.com",
    port="19530",
    user="db_user",
    password="your_password",
    secure=True
)

八、生产环境配置 #

8.1 资源规划 #

text
资源规划建议:

┌─────────────────────────────────────────┐
│           小规模部署                     │
├─────────────────────────────────────────┤
│  数据量: < 1000万向量                   │
│  QPS: < 1000                            │
│  Proxy: 2副本                           │
│  QueryNode: 2副本                       │
│  DataNode: 1副本                        │
│  IndexNode: 1副本                       │
└─────────────────────────────────────────┘

┌─────────────────────────────────────────┐
│           中规模部署                     │
├─────────────────────────────────────────┤
│  数据量: 1000万-1亿向量                 │
│  QPS: 1000-10000                        │
│  Proxy: 3副本                           │
│  QueryNode: 5副本                       │
│  DataNode: 3副本                        │
│  IndexNode: 2副本                       │
└─────────────────────────────────────────┘

┌─────────────────────────────────────────┐
│           大规模部署                     │
├─────────────────────────────────────────┤
│  数据量: > 1亿向量                      │
│  QPS: > 10000                           │
│  Proxy: 5+副本                          │
│  QueryNode: 10+副本                     │
│  DataNode: 5+副本                       │
│  IndexNode: 5+副本                      │
└─────────────────────────────────────────┘

8.2 高可用配置 #

yaml
proxy:
  replicas: 3
  podDisruptionBudget:
    enabled: true
    minAvailable: 2

queryNode:
  replicas: 5
  podDisruptionBudget:
    enabled: true
    minAvailable: 3

etcd:
  replicaCount: 5

minio:
  mode: distributed
  replicas: 8

8.3 自动扩缩容 #

yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: milvus-querynode-hpa
  namespace: milvus
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-release-milvus-querynode
  minReplicas: 3
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80

九、运维操作 #

9.1 升级 #

bash
helm repo update

helm upgrade my-release milvus/milvus \
  --namespace milvus \
  -f values.yaml

9.2 扩容 #

bash
kubectl scale deployment my-release-milvus-querynode \
  --replicas=5 \
  -n milvus

9.3 备份 #

bash
kubectl exec -it my-release-milvus-minio-0 -n milvus -- \
  mc mirror local/milvus /backup/milvus-$(date +%Y%m%d)

9.4 日志查看 #

bash
kubectl logs -f deployment/my-release-milvus-proxy -n milvus

kubectl logs -f deployment/my-release-milvus-querynode -n milvus

十、总结 #

部署方式速查表:

方式 适用场景 复杂度 可扩展性
Docker Compose 开发测试
Helm 生产环境
Milvus Operator 生产环境
Zilliz Cloud 全托管

下一步,让我们学习运维管理!

最后更新:2026-04-04