Skip to main content
Version: release-0.9

Manage Milvus with KubeBlocks

The popularity of generative AI (Generative AI) has aroused widespread attention and completely ignited the vector database (Vector Database) market.

Milvus is a highly flexible, reliable, and blazing-fast cloud-native, open-source vector database. It powers embedding similarity search and AI applications and strives to make vector databases accessible to every organization. Milvus can store, index, and manage a billion+ embedding vectors generated by deep neural networks and other machine learning (ML) models.

This tutorial illustrates how to create and manage a Milvus cluster by kbcli, kubectl or a YAML file. You can find the YAML examples and guides in the GitHub repository.

Before you start

Create a cluster

KubeBlocks implements a Cluster CRD to define a cluster. Here is an example of creating a Milvus cluster.

cat <<EOF | kubectl apply -f -
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: mycluster
namespace: demo
spec:
terminationPolicy: Delete
affinity:
podAntiAffinity: Preferred
topologyKeys:
- kubernetes.io/hostname
tenancy: SharedNode
tolerations:
- key: kb-data
operator: Equal
value: 'true'
effect: NoSchedule
componentSpecs:
- name: proxy
componentDef: milvus-proxy-0.9.0
replicas: 1
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
serviceRefs:
- cluster: etcdm-cluster
name: milvus-meta-storage
- cluster: pulsarm-cluster
name: milvus-log-storage
- name: milvus-object-storage
namespace: default
clusterServiceSelector:
cluster: miniom-cluster
service:
component: minio
service: headless
port: http
credential:
component: minio
name: admin
- name: mixcoord
componentDef: milvus-mixcoord-0.9.0
replicas: 1
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
serviceRefs:
- cluster: etcdm-cluster
name: milvus-meta-storage
- cluster: pulsarm-cluster
name: milvus-log-storage
- name: milvus-object-storage
namespace: default
clusterServiceSelector:
cluster: miniom-cluster
service:
component: minio
service: headless
port: http
credential:
component: minio
name: admin
- name: datanode
componentDef: milvus-datanode-0.9.0
replicas: 1
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
serviceRefs:
- cluster: etcdm-cluster
name: milvus-meta-storage
- cluster: pulsarm-cluster
name: milvus-log-storage
- name: milvus-object-storage
namespace: default
clusterServiceSelector:
cluster: miniom-cluster
service:
component: minio
service: headless
port: http
credential:
component: minio
name: admin
- name: indexnode
componentDef: milvus-indexnode-0.9.0
replicas: 1
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
serviceRefs:
- cluster: etcdm-cluster
name: milvus-meta-storage
- cluster: pulsarm-cluster
name: milvus-log-storage
- name: milvus-object-storage
namespace: default
clusterServiceSelector:
cluster: miniom-cluster
service:
component: minio
service: headless
port: http
credential:
component: minio
name: admin
- name: querynode
componentDef: milvus-querynode-0.9.0
replicas: 1
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
serviceRefs:
- cluster: etcdm-cluster
name: milvus-meta-storage
- cluster: pulsarm-cluster
name: milvus-log-storage
- name: milvus-object-storage
namespace: default
clusterServiceSelector:
cluster: miniom-cluster
service:
component: minio
service: headless
port: http
credential:
component: minio
name: admin
---
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: etcdm-cluster
namespace: demo
spec:
clusterDefinitionRef: etcd
clusterVersionRef: etcd-v3.5.6
terminationPolicy: WipeOut
affinity:
podAntiAffinity: Preferred
topologyKeys:
- kubernetes.io/hostname
tenancy: SharedNode
tolerations:
- key: kb-data
operator: Equal
value: 'true'
effect: NoSchedule
componentSpecs:
- name: etcd
componentDefRef: etcd
replicas: 1
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
storageClassName: null
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: pulsarm-cluster
namespace: demo
annotations:
"kubeblocks.io/extra-env": '{"KB_PULSAR_BROKER_NODEPORT": "false"}'
spec:
clusterDefinitionRef: pulsar
clusterVersionRef: pulsar-3.0.2
terminationPolicy: WipeOut
affinity:
podAntiAffinity: Preferred
topologyKeys:
- kubernetes.io/hostname
tenancy: SharedNode
tolerations:
- key: kb-data
operator: Equal
value: 'true'
effect: NoSchedule
componentSpecs:
- name: pulsar-broker
componentDefRef: pulsar-broker
disableExporter: true
replicas: 1
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- name: bookies
componentDefRef: bookies
disableExporter: true
replicas: 3
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: journal
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- name: ledgers
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- name: zookeeper
componentDefRef: zookeeper
disableExporter: true
replicas: 3
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: miniom-cluster
namespace: demo
spec:
terminationPolicy: WipeOut
componentSpecs:
- name: minio
componentDef: milvus-minio-0.9.0
replicas: 1
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
EOF
FieldDefinition
spec.terminationPolicyIt is the policy of cluster termination. The default value is Delete. Valid values are DoNotTerminate, Delete, WipeOut. For the detailed definition, you can refer to Termination Policy.
spec.affinityIt defines a set of node affinity scheduling rules for the cluster's Pods. This field helps control the placement of Pods on nodes within the cluster.
spec.affinity.podAntiAffinityIt specifies the anti-affinity level of Pods within a component. It determines how pods should spread across nodes to improve availability and performance.
spec.affinity.topologyKeysIt represents the key of node labels used to define the topology domain for Pod anti-affinity and Pod spread constraints.
spec.tolerationsIt is an array that specifies tolerations attached to the cluster's Pods, allowing them to be scheduled onto nodes with matching taints.
spec.componentSpecsIt is the list of components that define the cluster components. This field allows customized configuration of each component within a cluster.
spec.componentSpecs.componentDefRefIt is the name of the component definition that is defined in the cluster definition and you can get the component definition names with kubectl get clusterdefinition milvus -o json | jq '.spec.componentDefs[].name'.
spec.componentSpecs.nameIt specifies the name of the component.
spec.componentSpecs.disableExporterIt defines whether the monitoring function is enabled.
spec.componentSpecs.replicasIt specifies the number of replicas of the component.
spec.componentSpecs.resourcesIt specifies the resource requirements of the component.

KubeBlocks operator watches for the Cluster CRD and creates the cluster and all dependent resources. You can get all the resources created by the cluster with kubectl get all,secret,rolebinding,serviceaccount -l app.kubernetes.io/instance=mycluster -n demo.

kubectl get all,secret,rolebinding,serviceaccount -l app.kubernetes.io/instance=mycluster -n demo

Run the following command to see the created Milvus cluster object:

kubectl get cluster mycluster -n demo -o yaml

Scale

Currently, KubeBlocks supports vertically scaling a Milvus cluster.

Before you start

Check whether the cluster status is Running. Otherwise, the following operations may fail.

kubectl get cluster mycluster -n demo
>
NAME CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS AGE
mycluster milvus-2.3.2 Delete Running 4m29s

Steps

  1. Apply an OpsRequest to the specified cluster. Configure the parameters according to your needs.

    kubectl apply -f - <<EOF
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
    name: ops-vertical-scaling
    namespace: demo
    spec:
    clusterName: mycluster
    type: VerticalScaling
    verticalScaling:
    - componentName: milvus
    requests:
    memory: "2Gi"
    cpu: "1"
    limits:
    memory: "4Gi"
    cpu: "2"
    EOF
  2. Check the operation status to validate the vertical scaling.

    kubectl get ops -n demo
    >
    NAMESPACE NAME TYPE CLUSTER STATUS PROGRESS AGE
    demo ops-vertical-scaling VerticalScaling mycluster Succeed 3/3 6m

    If an error occurs, you can troubleshoot with kubectl describe ops -n demo command to view the events of this operation.

  3. Check whether the corresponding resources change.

    kubectl describe cluster mycluster -n demo

Volume Expansion

Before you start

Check whether the cluster status is Running. Otherwise, the following operations may fail.

kubectl get cluster mycluster -n demo
>
NAME CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS AGE
mycluster milvus-2.3.2 Delete Running 4m29s

Steps

  1. Change the value of storage according to your need and run the command below to expand the volume of a cluster.

    kubectl apply -f - <<EOF
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
    name: ops-volume-expansion
    namespace: demo
    spec:
    clusterName: mycluster
    type: VolumeExpansion
    volumeExpansion:
    - componentName: milvus
    volumeClaimTemplates:
    - name: data
    storage: "40Gi" # Set the volume storage size.
    EOF
  2. Validate the volume expansion operation.

    kubectl get ops -n demo
    >
    NAMESPACE NAME TYPE CLUSTER STATUS PROGRESS AGE
    demo ops-volume-expansion VolumeExpansion mycluster Succeed 3/3 6m

    If an error occurs to the vertical scaling operation, you can troubleshoot with kubectl describe ops -n demo command to view the events of this operation.

  3. Check whether the corresponding cluster resources change.

    kubectl describe cluster mycluster -n demo

Restart

  1. Restart a cluster.

    kubectl apply -f - <<EOF
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
    name: ops-restart
    namespace: demo
    spec:
    clusterName: mycluster
    type: Restart
    restart:
    - componentName: milvus
    EOF
  2. Check the pod and operation status to validate the restarting.

    kubectl get pod -n demo

    kubectl get ops ops-restart -n demo

    During the restarting process, there are two status types for pods.

    • STATUS=Terminating: it means the cluster restart is in progress.
    • STATUS=Running: it means the cluster has been restarted.

Stop/Start a cluster

You can stop/start a cluster to save computing resources. When a cluster is stopped, the computing resources of this cluster are released, which means the pods of Kubernetes are released, but the storage resources are reserved. You can start this cluster again to restore it to the state it was in before it was stopped.

Stop a cluster

  1. Configure the name of your cluster and run the command below to stop this cluster.

    Apply an OpsRequest to stop a cluster.

    kubectl apply -f - <<EOF
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
    name: ops-stop
    namespace: demo
    spec:
    clusterName: mycluster
    type: Stop
    EOF
  2. Check the status of the cluster to see whether it is stopped.

    kubectl get cluster mycluster -n demo

Start a cluster

  1. Configure the name of your cluster and run the command below to start this cluster.

    Apply an OpsRequest to start a cluster.

    kubectl apply -f - <<EOF
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
    name: ops-start
    namespace: demo
    spec:
    clusterName: mycluster
    type: Start
    EOF
  2. Check the status of the cluster to see whether it is running again.

    kubectl get cluster mycluster -n demo

Delete a cluster

Termination policy

note

The termination policy determines how a cluster is deleted.

terminationPolicyDeleting Operation
DoNotTerminateDoNotTerminate blocks delete operation.
HaltHalt deletes Cluster resources like Pods and Services but retains Persistent Volume Claims (PVCs), allowing for data preservation while stopping other operations. Halt policy is deprecated in v0.9.1 and will have same meaning as DoNotTerminate.
DeleteDelete extends the Halt policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
WipeOutWipeOut deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, especially in non-production environments, to avoid irreversible data loss.

To check the termination policy, execute the following command.

kubectl get cluster mycluster -n demo
>
NAME CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS AGE
mycluster milvus-2.3.2 Delete Running 14m

Steps

Run the command below to delete a specified cluster.

If you want to delete a cluster and its all related resources, you can modify the termination policy to WipeOut, then delete the cluster.

kubectl patch -n demo cluster mycluster -p '{"spec":{"terminationPolicy":"WipeOut"}}' --type="merge"

kubectl delete -n demo cluster mycluster