Files
aitsc/deploy-k8s.sh

64 lines
1.5 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
echo "🚀 开始Docker+K8s部署..."
# 检查Docker是否运行
if ! docker info > /dev/null 2>&1; then
echo "❌ Docker未运行请先启动Docker"
exit 1
fi
# 检查Kubernetes集群状态
if ! kubectl cluster-info > /dev/null 2>&1; then
echo "❌ Kubernetes集群未连接请先启动Minikube"
echo "运行: minikube start --driver=docker"
exit 1
fi
echo "✅ Docker和Kubernetes状态正常"
# 构建Docker镜像
echo "🔨 构建Docker镜像..."
docker build -t flask-prompt-master:latest .
if [ $? -ne 0 ]; then
echo "❌ Docker镜像构建失败"
exit 1
fi
echo "✅ Docker镜像构建成功"
# 部署到Kubernetes
echo "📦 部署到Kubernetes..."
kubectl apply -f k8s/simple-deployment.yaml
if [ $? -ne 0 ]; then
echo "❌ Kubernetes部署失败"
exit 1
fi
echo "✅ Kubernetes部署成功"
# 等待Pod启动
echo "⏳ 等待Pod启动..."
kubectl wait --for=condition=ready pod -l app=flask-prompt-master --timeout=300s
if [ $? -ne 0 ]; then
echo "❌ Pod启动超时"
exit 1
fi
echo "✅ Pod启动成功"
# 显示服务状态
echo "📊 服务状态:"
kubectl get pods -l app=flask-prompt-master
kubectl get services -l app=flask-prompt-master
# 获取访问地址
echo "🌐 访问地址:"
echo "本地访问: http://localhost:$(kubectl get service flask-prompt-master-service -o jsonpath='{.spec.ports[0].nodePort}')"
echo "负载均衡器: $(kubectl get service flask-prompt-master-loadbalancer -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
echo "🎉 部署完成!"