Files
2025-11-28 13:49:45 +08:00

105 lines
2.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 灵境万象系统 - Kubernetes 卸载脚本
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
NAMESPACE="${K8S_NAMESPACE:-ljwx-system}"
DELETE_PVC="${DELETE_PVC:-false}"
print_info() {
echo -e "${BLUE}ℹ ${NC}$1"
}
print_success() {
echo -e "${GREEN}✅${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠️${NC} $1"
}
print_error() {
echo -e "${RED}❌${NC} $1"
}
echo -e "${BLUE}=========================================${NC}"
echo -e "${BLUE}🗑️ 灵境万象系统 - K8s 卸载${NC}"
echo -e "${BLUE}=========================================${NC}"
echo ""
# 确认删除
print_warning "即将删除 Namespace: $NAMESPACE"
print_info "这将删除该命名空间下的所有资源"
if [ "$DELETE_PVC" = "true" ]; then
print_warning "包括持久化数据(PVC)"
fi
echo ""
read -p "确认删除? (输入 'yes' 确认): " -r
if [ "$REPLY" != "yes" ]; then
echo "取消删除"
exit 0
fi
echo ""
print_info "开始卸载..."
# 删除 Ingress
print_info "删除 Ingress..."
kubectl delete ingress --all -n $NAMESPACE --ignore-not-found=true
# 删除 Deployments
print_info "删除 Deployments..."
kubectl delete deployment --all -n $NAMESPACE --ignore-not-found=true
# 删除 StatefulSets
print_info "删除 StatefulSets..."
kubectl delete statefulset --all -n $NAMESPACE --ignore-not-found=true
# 删除 Services
print_info "删除 Services..."
kubectl delete svc --all -n $NAMESPACE --ignore-not-found=true
# 删除 ConfigMaps
print_info "删除 ConfigMaps..."
kubectl delete configmap --all -n $NAMESPACE --ignore-not-found=true
# 删除 Secrets
print_info "删除 Secrets..."
kubectl delete secret --all -n $NAMESPACE --ignore-not-found=true
# 删除 PVC(如果指定)
if [ "$DELETE_PVC" = "true" ]; then
print_warning "删除 PersistentVolumeClaims(数据将丢失)..."
kubectl delete pvc --all -n $NAMESPACE --ignore-not-found=true
fi
# 等待资源清理
print_info "等待资源清理..."
sleep 5
# 删除 Namespace
print_info "删除 Namespace: $NAMESPACE..."
kubectl delete namespace $NAMESPACE --ignore-not-found=true
echo ""
print_success "卸载完成!"
echo ""
if [ "$DELETE_PVC" != "true" ]; then
print_info "PVC 数据已保留,下次部署将复用现有数据"
print_info "如需完全删除数据,请运行: DELETE_PVC=true $0"
fi
echo ""
print_info "验证卸载:"
echo " kubectl get all -n $NAMESPACE"
echo ""