This commit is contained in:
2025-11-26 15:44:15 +08:00
parent 1cd698ed64
commit 2418891634
42 changed files with 3715 additions and 5 deletions

View File

@@ -0,0 +1,70 @@
#!/bin/bash
# Nginx 配置迁移卸载脚本
# tags: kubernetes, k3s, traefik, cleanup, uninstall
# description: 卸载所有已部署的外部服务和 IngressRoute 配置
# title: 卸载脚本
# createdAt: 2025-11-26
set -e
echo "======================================"
echo "卸载 K3s 外部服务配置"
echo "======================================"
echo ""
# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# 确认卸载
read -p "确认要卸载所有外部服务和 IngressRoute 配置吗?(y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}取消卸载${NC}"
exit 0
fi
# 删除 IngressRoute
echo ""
echo -e "${YELLOW}步骤 1/2: 删除 IngressRoute...${NC}"
if kubectl get ingressroute -n default &> /dev/null; then
kubectl delete -f k8s/xiongxiao.me/ingress/apps-ingressroute.yaml || true
echo -e "${GREEN}✓ IngressRoute 已删除${NC}"
else
echo -e "${YELLOW}无 IngressRoute 需要删除${NC}"
fi
# 删除外部服务
echo ""
echo -e "${YELLOW}步骤 2/2: 删除外部服务和 Endpoints...${NC}"
if kubectl get svc -n default | grep -q external; then
kubectl delete -f k8s/xiongxiao.me/services/external-services.yaml || true
echo -e "${GREEN}✓ 外部服务已删除${NC}"
else
echo -e "${YELLOW}无外部服务需要删除${NC}"
fi
# 验证清理
echo ""
echo -e "${YELLOW}验证清理结果...${NC}"
REMAINING_SVC=$(kubectl get svc -n default | grep -c "external" || true)
REMAINING_ROUTES=$(kubectl get ingressroute -n default 2>/dev/null | grep -c "https" || true)
if [ "$REMAINING_SVC" -eq 0 ] && [ "$REMAINING_ROUTES" -eq 0 ]; then
echo -e "${GREEN}✓ 所有配置已清理完成${NC}"
else
echo -e "${RED}警告: 仍有 ${REMAINING_SVC} 个服务和 ${REMAINING_ROUTES} 个路由${NC}"
fi
echo ""
echo -e "${GREEN}======================================"
echo "卸载完成!"
echo "======================================${NC}"
echo ""
echo -e "${YELLOW}注意: Traefik 本身未被删除${NC}"
echo "如需删除 Traefik请运行"
echo " kubectl delete -f k8s/xiongxiao.me/traefik/traefik-complete.yaml"
echo ""