uninstall-kubeblocks.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. # Get the directory where this script is located
  3. DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
  4. # Load configuration file
  5. source "$DATABASE_SCRIPT_DIR/00-config.sh"
  6. # Check dependencies
  7. print "Checking dependencies..."
  8. command -v kubectl >/dev/null 2>&1 || { print "Error: kubectl command not found"; exit 1; }
  9. command -v helm >/dev/null 2>&1 || { print "Error: helm command not found"; exit 1; }
  10. print "Checking if Kubernetes is available..."
  11. if ! kubectl cluster-info &>/dev/null; then
  12. print "Error: Kubernetes cluster is not accessible. Please ensure you have proper access to a Kubernetes cluster."
  13. exit 1
  14. fi
  15. print "Checking if KubeBlocks is installed in kb-system namespace..."
  16. if ! kubectl get namespace kb-system &>/dev/null; then
  17. print "KubeBlocks is not installed in kb-system namespace."
  18. exit 0
  19. fi
  20. # Function for uninstalling KubeBlocks
  21. uninstall_kubeblocks() {
  22. print "Uninstalling KubeBlocks..."
  23. # Uninstall KubeBlocks Helm chart
  24. helm uninstall kubeblocks -n kb-system
  25. # Uninstall snapshot controller
  26. helm uninstall snapshot-controller -n kb-system
  27. # Delete KubeBlocks CRDs
  28. kubectl delete -f https://github.com/apecloud/kubeblocks/releases/download/v${KB_VERSION}/kubeblocks_crds.yaml --ignore-not-found=true
  29. # Delete CSI Snapshotter CRDs
  30. kubectl delete -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml --ignore-not-found=true
  31. kubectl delete -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml --ignore-not-found=true
  32. kubectl delete -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.2.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml --ignore-not-found=true
  33. # Delete the kb-system namespace
  34. print "Waiting for resources to be removed..."
  35. kubectl delete namespace kb-system --timeout=180s
  36. print "KubeBlocks has been successfully uninstalled!"
  37. }
  38. # Call the function to uninstall KubeBlocks
  39. uninstall_kubeblocks