Files
k3s_auto_deploy/demo-gitops-update.sh

58 lines
1.6 KiB
Bash
Executable File
Raw 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
# GitOps自动更新演示脚本
echo "🎯 GitOps自动更新演示"
echo "======================="
echo ""
# 检查当前版本
echo "📊 当前应用版本:"
curl -s http://8.216.38.248:30081 | grep -o "Version: v[0-9.]*"
echo ""
# 提示用户
echo "现在我们将更新应用到 v2.0..."
echo "按Enter键继续..."
read
# SSH到master节点并更新
echo "🔄 正在更新应用..."
ssh fei@8.216.38.248 "cd /home/fei/k3s/test-app && ./update-app.sh v2.0"
echo ""
echo "✅ Git提交完成"
echo ""
echo "⏳ 等待ArgoCD检测变化并自动同步..."
echo " (ArgoCD每3分钟检查一次Git仓库)"
echo ""
# 监控同步状态
echo "📊 监控ArgoCD同步状态..."
for i in {1..12}; do
STATUS=$(ssh fei@8.216.38.248 "kubectl get application test-app -n argocd -o jsonpath='{.status.sync.status}'")
HEALTH=$(ssh fei@8.216.38.248 "kubectl get application test-app -n argocd -o jsonpath='{.status.health.status}'")
echo "[$i/12] Sync: $STATUS | Health: $HEALTH"
if [ "$STATUS" = "Synced" ] && [ "$HEALTH" = "Healthy" ]; then
echo ""
echo "✅ 同步完成!"
break
fi
sleep 15
done
echo ""
echo "🎉 验证更新后的版本:"
curl -s http://8.216.38.248:30081 | grep -o "Version: v[0-9.]*"
echo ""
echo "🌐 访问 http://8.216.38.248:30081 查看新版本(背景颜色已改变)"
echo ""
echo "📝 总结:"
echo " 1. 我们修改了Git仓库中的配置"
echo " 2. ArgoCD自动检测到变化"
echo " 3. ArgoCD自动部署了新版本"
echo " 4. 整个过程无需手动执行kubectl命令"
echo ""
echo "这就是GitOps的魅力🚀"