- 更新 Harbor 配置和部署脚本 - 添加 Gitea runner 配置和相关文件 - 完善 Tekton 流水线配置 - 添加 Harbor 镜像推送和管理脚本 - 修复 CI/CD 部署步骤和配置 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
174 lines
4.4 KiB
Markdown
174 lines
4.4 KiB
Markdown
# 🔧 Bookstore CI/CD 修复后的部署步骤
|
|
|
|
## ⚠️ 发现的问题和修复
|
|
|
|
### 原始配置问题:
|
|
1. **Harbor 未部署**: 配置中使用了 `harbor.shared:28081`,但 Harbor 没有实际部署
|
|
2. **服务地址错误**: 数据库和 Redis 服务命名空间不正确
|
|
3. **镜像仓库不可用**: 没有可用的容器镜像仓库
|
|
4. **缺少必要的密钥**: Harbor 和 Git 凭据不存在
|
|
|
|
### 修复方案:
|
|
1. ✅ 修改服务地址指向正确的命名空间 (`shared-base`)
|
|
2. ✅ 简化配置,使用公共镜像仓库进行测试
|
|
3. ✅ 移除对未部署服务的依赖
|
|
4. ✅ 创建渐进式部署流程
|
|
|
|
---
|
|
|
|
## 🚀 修复后的部署步骤
|
|
|
|
### 1. 部署修复后的 Tekton 配置
|
|
|
|
```bash
|
|
# 使用修复后的配置文件
|
|
kubectl apply -f devops/tekton/bookstore-tasks.yaml
|
|
kubectl apply -f devops/tekton/bookstore-pipeline-fixed.yaml
|
|
```
|
|
|
|
### 2. 创建数据库(如果需要)
|
|
```bash
|
|
# 在 shared-base 命名空间创建 bookstore 数据库
|
|
kubectl exec -n shared-base postgresql-0 -- psql -U postgres -c "CREATE DATABASE bookstore;"
|
|
kubectl exec -n shared-base postgresql-0 -- psql -U postgres -c "CREATE USER bookstore WITH PASSWORD 'bookstore123';"
|
|
kubectl exec -n shared-base postgresql-0 -- psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE bookstore TO bookstore;"
|
|
```
|
|
|
|
### 3. 部署修复后的应用
|
|
```bash
|
|
# 使用修复后的部署配置
|
|
kubectl apply -f devops/k8s/bookstore-deployment-fixed.yaml
|
|
```
|
|
|
|
### 4. 测试简化版流水线
|
|
```bash
|
|
# 运行修复后的流水线
|
|
kubectl apply -f devops/tekton/bookstore-pipelinerun-fixed.yaml
|
|
|
|
# 查看状态
|
|
kubectl get pipelineruns -n tekton-pipelines
|
|
tkn pipelinerun logs bookstore-pipeline-run-fixed-xxx -n tekton-pipelines
|
|
```
|
|
|
|
---
|
|
|
|
## 🔍 验证步骤
|
|
|
|
### 检查基础服务
|
|
```bash
|
|
# 检查 PostgreSQL
|
|
kubectl get pods -n shared-base | grep postgresql
|
|
kubectl exec -n shared-base postgresql-0 -- psql -l
|
|
|
|
# 检查 Redis
|
|
kubectl get pods -n shared-base | grep redis
|
|
kubectl exec -n shared-base redis-master-0 -- redis-cli ping
|
|
|
|
# 检查 Gitea
|
|
kubectl get pods -n gitea
|
|
curl http://localhost:30080
|
|
|
|
# 检查 ArgoCD
|
|
kubectl get pods -n argocd
|
|
curl http://localhost:30081
|
|
```
|
|
|
|
### 检查应用部署
|
|
```bash
|
|
# 检查 bookstore 命名空间
|
|
kubectl get all -n app-bookstore
|
|
|
|
# 检查 Pod 日志
|
|
kubectl logs -f deployment/bookstore -n app-bookstore
|
|
|
|
# 检查服务
|
|
kubectl get svc -n app-bookstore
|
|
```
|
|
|
|
### 检查 CI/CD 组件
|
|
```bash
|
|
# 检查 Tekton
|
|
kubectl get pods -n tekton-pipelines
|
|
tkn task list
|
|
tkn pipeline list
|
|
|
|
# 检查流水线运行状态
|
|
kubectl get pipelineruns -n tekton-pipelines -w
|
|
```
|
|
|
|
---
|
|
|
|
## 📋 完整部署顺序
|
|
|
|
### 阶段 1: 基础设施验证
|
|
```bash
|
|
# 1. 确保基础服务运行
|
|
kubectl get pods -n gitea
|
|
kubectl get pods -n argocd
|
|
kubectl get pods -n shared-base
|
|
kubectl get pods -n tekton-pipelines
|
|
|
|
# 2. 验证网络连通性
|
|
kubectl run test-pod --image=busybox --rm -it -- wget -qO- http://gitea.gitea:3000
|
|
```
|
|
|
|
### 阶段 2: CI/CD 配置
|
|
```bash
|
|
# 3. 部署 CI/CD 组件
|
|
kubectl apply -f devops/tekton/bookstore-tasks.yaml
|
|
kubectl apply -f devops/tekton/bookstore-pipeline-fixed.yaml
|
|
|
|
# 4. 验证任务和流水线
|
|
tkn task list
|
|
tkn pipeline list
|
|
```
|
|
|
|
### 阶段 3: 应用部署
|
|
```bash
|
|
# 5. 准备数据库
|
|
kubectl exec -n shared-base postgresql-0 -- psql -U postgres -c "SELECT 1;"
|
|
|
|
# 6. 部署应用
|
|
kubectl apply -f devops/k8s/bookstore-deployment-fixed.yaml
|
|
|
|
# 7. 验证应用运行
|
|
kubectl get pods -n app-bookstore
|
|
```
|
|
|
|
### 阶段 4: 流水线测试
|
|
```bash
|
|
# 8. 运行测试流水线
|
|
kubectl apply -f devops/tekton/bookstore-pipelinerun-fixed.yaml
|
|
|
|
# 9. 监控执行
|
|
kubectl get pipelineruns -n tekton-pipelines -w
|
|
tkn pipelinerun logs <pipeline-run-name> -f -n tekton-pipelines
|
|
```
|
|
|
|
---
|
|
|
|
## 🚨 当前限制和后续改进
|
|
|
|
### 当前限制:
|
|
1. **没有 Harbor**: 使用 Docker Hub 或其他公共仓库
|
|
2. **简化配置**: 移除了复杂的安全扫描和多环境部署
|
|
3. **临时镜像**: 使用 busybox 作为占位符
|
|
|
|
### 后续改进建议:
|
|
1. **部署 Harbor**: 添加本地镜像仓库
|
|
2. **完整镜像**: 构建真实的 Spring Boot 镜像
|
|
3. **添加监控**: 集成 Prometheus 和 Grafana
|
|
4. **多环境**: 完善开发/测试/生产环境配置
|
|
|
|
---
|
|
|
|
## ✅ 成功标准
|
|
|
|
部署成功应该看到:
|
|
- ✅ 所有 Pod 运行正常
|
|
- ✅ 数据库连接成功
|
|
- ✅ 服务可以访问
|
|
- ✅ 流水线可以执行
|
|
- ✅ ArgoCD 可以监控部署
|
|
|
|
**注意**: 当前配置是渐进式部署,先验证基础功能,再逐步完善。 |