#!/bin/bash # JPD集群完整自动化配置脚本 # 包括:Ingress配置、cert-manager、ArgoCD配置、测试应用部署 set -e export KUBECONFIG=/etc/rancher/k3s/k3s.yaml echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🚀 JPD集群完整自动化配置" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # ============================================ # 步骤 1: 配置Gitea Ingress # ============================================ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "📦 步骤 1/6: 配置Gitea Ingress" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" cat < JPD集群测试应用
🚀

JPD K3s集群测试应用

✅ 运行正常

集群名称: JPD Cluster

部署方式: Kubernetes Deployment

副本数: 3

容器镜像: nginx:alpine

访问域名: demo.jpd.net3w.com

GitOps工具: ArgoCD

Git仓库: Gitea

主机名: 加载中...

--- apiVersion: v1 kind: Service metadata: name: nginx-demo namespace: demo-app spec: selector: app: nginx-demo ports: - port: 80 targetPort: 80 type: ClusterIP --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: nginx-demo namespace: demo-app annotations: traefik.ingress.kubernetes.io/router.entrypoints: web spec: ingressClassName: traefik rules: - host: demo.jpd.net3w.com http: paths: - path: / pathType: Prefix backend: service: name: nginx-demo port: number: 80 --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: nginx-demo-https namespace: demo-app annotations: cert-manager.io/cluster-issuer: "letsencrypt-prod" traefik.ingress.kubernetes.io/router.entrypoints: websecure traefik.ingress.kubernetes.io/router.tls: "true" spec: ingressClassName: traefik tls: - hosts: - demo.jpd.net3w.com secretName: nginx-demo-tls rules: - host: demo.jpd.net3w.com http: paths: - path: / pathType: Prefix backend: service: name: nginx-demo port: number: 80 EOF echo "⏳ 等待测试应用就绪..." kubectl wait --for=condition=ready pod -l app=nginx-demo -n demo-app --timeout=120s echo "✅ 测试应用部署完成" echo " 访问地址: http://demo.jpd.net3w.com" echo " HTTPS访问: https://demo.jpd.net3w.com" echo "" # ============================================ # 步骤 6: 部署自动化测试 # ============================================ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "📦 步骤 6/6: 部署自动化测试" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # 创建自动化测试CronJob cat < /dev/null; then echo "✅ Gitea: 正常" else echo "❌ Gitea: 异常" exit 1 fi # 测试ArgoCD echo "测试 ArgoCD..." if curl -f -s -k http://argocd-server.argocd.svc.cluster.local > /dev/null; then echo "✅ ArgoCD: 正常" else echo "❌ ArgoCD: 异常" exit 1 fi # 测试Demo应用 echo "测试 Demo应用..." if curl -f -s http://nginx-demo.demo-app.svc.cluster.local > /dev/null; then echo "✅ Demo应用: 正常" else echo "❌ Demo应用: 异常" exit 1 fi echo "" echo "=== 所有服务健康检查通过 ===" restartPolicy: OnFailure EOF # 立即运行一次测试 kubectl create job --from=cronjob/health-check health-check-manual -n demo-app || true echo "✅ 自动化测试部署完成" echo " 测试频率: 每5分钟" echo " 查看测试日志: kubectl logs -n demo-app -l job-name=health-check-manual" echo "" # ============================================ # 最终状态检查 # ============================================ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🎉 部署完成!最终状态" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "📊 集群资源:" kubectl get nodes -o wide echo "" echo "📦 所有Pod:" kubectl get pods --all-namespaces | grep -E "NAMESPACE|Running|Completed" echo "" echo "🌐 所有Ingress:" kubectl get ingress --all-namespaces echo "" echo "🔐 访问信息:" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" echo "Gitea:" echo " HTTP: http://git.jpd.net3w.com" echo " HTTPS: https://git.jpd.net3w.com" echo " 用户名: gitea_admin" echo " 密码: GitAdmin@2026" echo "" echo "ArgoCD:" echo " HTTP: http://argocd.jpd.net3w.com" echo " HTTPS: https://argocd.jpd.net3w.com" echo " NodePort: http://149.13.91.216:$ARGOCD_PORT" echo " 用户名: admin" echo " 密码: $ARGOCD_PASSWORD" echo "" echo "测试应用:" echo " HTTP: http://demo.jpd.net3w.com" echo " HTTPS: https://demo.jpd.net3w.com" echo "" echo "💡 提示:" echo " - HTTPS证书需要1-2分钟签发" echo " - 自动化测试每5分钟运行一次" echo " - 查看测试日志: kubectl logs -n demo-app -l job-name=health-check-manual" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"