install_milvus.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # Licensed to the LF AI & Data foundation under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # Exit immediately for non zero status
  18. # set -e
  19. # Print commands
  20. set -x
  21. MILVUS_HELM_REPO="${MILVUS_HELM_REPO:-https://zilliztech.github.io/milvus-helm/}"
  22. MILVUS_HELM_RELEASE_NAME="${MILVUS_HELM_RELEASE_NAME:-milvus-testing}"
  23. MILVUS_CLUSTER_ENABLED="${MILVUS_CLUSTER_ENABLED:-false}"
  24. MILVUS_IMAGE_REPO="${MILVUS_IMAGE_REPO:-milvusdb/milvus}"
  25. MILVUS_IMAGE_TAG="${MILVUS_IMAGE_TAG:-latest}"
  26. MILVUS_HELM_NAMESPACE="${MILVUS_HELM_NAMESPACE:-default}"
  27. # Increase timeout from 500 to 800 because pulsar has one more node now
  28. MILVUS_INSTALL_TIMEOUT="${MILVUS_INSTALL_TIMEOUT:-800s}"
  29. # Delete any previous Milvus cluster
  30. echo "Deleting previous Milvus cluster with name=${MILVUS_HELM_RELEASE_NAME}"
  31. if ! (helm uninstall -n "${MILVUS_HELM_NAMESPACE}" "${MILVUS_HELM_RELEASE_NAME}" > /dev/null 2>&1); then
  32. echo "No existing Milvus cluster with name ${MILVUS_HELM_RELEASE_NAME}. Continue..."
  33. else
  34. MILVUS_LABELS1="app.kubernetes.io/instance=${MILVUS_HELM_RELEASE_NAME}"
  35. MILVUS_LABELS2="release=${MILVUS_HELM_RELEASE_NAME}"
  36. kubectl delete pvc -n "${MILVUS_HELM_NAMESPACE}" $(kubectl get pvc -n "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS1}" -o jsonpath='{range.items[*]}{.metadata.name} ') || true
  37. kubectl delete pvc -n "${MILVUS_HELM_NAMESPACE}" $(kubectl get pvc -n "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS2}" -o jsonpath='{range.items[*]}{.metadata.name} ') || true
  38. fi
  39. if [[ "${TEST_ENV}" == "kind-metallb" ]]; then
  40. MILVUS_SERVICE_TYPE="${MILVUS_SERVICE_TYPE:-LoadBalancer}"
  41. else
  42. MILVUS_SERVICE_TYPE="${MILVUS_SERVICE_TYPE:-ClusterIP}"
  43. fi
  44. if [[ -n "${DISABLE_KIND:-}" ]]; then
  45. # Use cluster IP to deploy milvus when kinD cluster is removed
  46. MILVUS_SERVICE_TYPE="ClusterIP"
  47. fi
  48. # Use helm repo to install milvus charts
  49. helm repo add zilliztech ${MILVUS_HELM_REPO}
  50. helm repo update
  51. MILVUS_HELM_CHART_PATH="zilliztech/milvus"
  52. # Create namespace when it does not exist
  53. kubectl create namespace "${MILVUS_HELM_NAMESPACE}" > /dev/null 2>&1 || true
  54. echo "[debug] cluster type is ${MILVUS_SERVICE_TYPE}"
  55. if [[ "${MILVUS_CLUSTER_ENABLED}" == "true" ]]; then
  56. helm install --wait --timeout "${MILVUS_INSTALL_TIMEOUT}" \
  57. --set image.all.repository="${MILVUS_IMAGE_REPO}" \
  58. --set image.all.tag="${MILVUS_IMAGE_TAG}" \
  59. --set image.all.pullPolicy="${MILVUS_PULL_POLICY:-Always}" \
  60. --set cluster.enabled="${MILVUS_CLUSTER_ENABLED}" \
  61. --set service.type="${MILVUS_SERVICE_TYPE}" \
  62. --set pulsar.broker.replicaCount=2 \
  63. --set minio.mode=standalone \
  64. --namespace "${MILVUS_HELM_NAMESPACE}" \
  65. "${MILVUS_HELM_RELEASE_NAME}" \
  66. ${@:-} "${MILVUS_HELM_CHART_PATH}"
  67. else
  68. helm install --wait --timeout "${MILVUS_INSTALL_TIMEOUT}" \
  69. --set image.all.repository="${MILVUS_IMAGE_REPO}" \
  70. --set image.all.tag="${MILVUS_IMAGE_TAG}" \
  71. --set image.all.pullPolicy="${MILVUS_PULL_POLICY:-Always}" \
  72. --set cluster.enabled="${MILVUS_CLUSTER_ENABLED}" \
  73. --set pulsar.enabled=false \
  74. --set minio.mode=standalone \
  75. --set etcd.replicaCount=1 \
  76. --set service.type="${MILVUS_SERVICE_TYPE}" \
  77. --namespace "${MILVUS_HELM_NAMESPACE}" \
  78. "${MILVUS_HELM_RELEASE_NAME}" \
  79. ${@:-} "${MILVUS_HELM_CHART_PATH}"
  80. fi
  81. exitcode=$?
  82. # List pod list & pvc list before exit after helm install
  83. kubectl get pods -n ${MILVUS_HELM_NAMESPACE} -o wide | grep "${MILVUS_HELM_RELEASE_NAME}-"
  84. restart_pods=$(kubectl get pods -n ${MILVUS_HELM_NAMESPACE} | grep "${MILVUS_HELM_RELEASE_NAME}-" | grep 'ago)' | awk '{print $1}')
  85. for restart_pod in ${restart_pods}
  86. do
  87. reason=$(kubectl get pod ${restart_pod} -n ${MILVUS_HELM_NAMESPACE} -o json | jq .status.containerStatuses[0].lastState.terminated.reason )
  88. restart_count=$(kubectl get pod ${restart_pod} -n ${MILVUS_HELM_NAMESPACE} -o json | jq .status.containerStatuses[0].restartCount )
  89. echo "${restart_pod} restarts ${restart_count}, last terminateed reason is ${reason}"
  90. done
  91. # Show related events when helm install failed
  92. if [[ ${exitcode} -ne 0 ]];then
  93. failed_pods=$(kubectl get pods --field-selector status.phase!=Running,status.phase!=Completed -n ${MILVUS_HELM_NAMESPACE} | grep "${MILVUS_HELM_RELEASE_NAME}-" | awk '{print $1}' )
  94. for failed_pod in ${failed_pods}
  95. do
  96. kubectl get events -n ${MILVUS_HELM_NAMESPACE} --field-selector involvedObject.name="${failed_pod}"
  97. done
  98. fi
  99. kubectl get pvc -n ${MILVUS_HELM_NAMESPACE} | grep "${MILVUS_HELM_RELEASE_NAME}-" | awk '{$3=null;print $0}'
  100. if [[ -n ${SHOW_MILVUS_CONFIGMAP} ]]; then
  101. echo "-----------------milvus config --------------------"
  102. kubectl get configmap ${MILVUS_HELM_RELEASE_NAME}-milvus -n ${MILVUS_HELM_NAMESPACE} -o jsonpath="{$.data}"
  103. fi
  104. exit ${exitcode}