Cpte-Boot/k8s/README.md

451 lines
8.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# WMS 微服务 Kubernetes + KubeSphere 部署文档
## 📋 目录
1. [部署前准备](#部署前准备)
2. [扩展组件选择](#扩展组件选择)
3. [快速部署](#快速部署)
4. [分步部署](#分步部署)
5. [中间件部署](#中间件部署)
6. [验证和测试](#验证和测试)
7. [常见问题](#常见问题)
---
## 部署前准备
### 1. 环境要求
- Kubernetes 1.28.x
- KubeSphere 3.4.x
- Helm 3.x
- kubectl 已配置集群访问
- 存储类StorageClassnfs-sc
### 2. 修改配置文件
#### 2.1 修改 Secretsecrets.yaml
```yaml
# Redis 密码
wms-redis-secret:
password: "修改为强密码"
# MySQL 密码
wms-mysql-secret:
password: "修改为强密码"
# MinIO 密钥
wms-minio-secret:
access-key: "修改为自定义密钥"
secret-key: "修改为强密钥"
# TLS 证书
wms-tls-secret:
tls.crt: "替换为实际证书"
tls.key: "替换为实际私钥"
# 镜像仓库凭证
wms-docker-registry-secret:
password: "修改为仓库密码"
```
#### 2.2 修改 Ingress 域名ingress.yaml
```yaml
# 生产环境
- host: wms.yourcompany.com # 修改为实际域名
# 开发环境
- host: wms-dev.yourcompany.com # 修改为实际域名
```
#### 2.3 修改镜像地址deployments/*.yaml
```yaml
image: registry.yourcompany.com/wms/cpte-wms-basic-service:latest
# 修改为实际的镜像仓库地址
```
---
## 扩展组件选择
### ✅ 必选组件21 个)
在 KubeSphere 扩展组件选择界面,勾选以下组件:
#### 核心组件
- [x] Metrics Server
- [x] KubeSphere 网关
- [x] KubeSphere 网络
- [x] KubeSphere 存储
#### 可观察性
- [x] WizTelemetry 监控
- [x] WizTelemetry 日志
- [x] WizTelemetry 告警
- [x] WizTelemetry 通知
- [x] WizTelemetry 事件
- [x] WizTelemetry 审计
- [x] WizTelemetry 全局监控
- [x] KubeEye 巡检
#### DevOps
- [x] DevOps
- [x] 镜像构建器
#### 安全和集成
- [x] cert-manager
- [x] OAuth2-Proxy
- [x] Gatekeeper
- [x] KubeSphere Spring Cloud
- [x] KEDA for KubeSphere
#### 应用管理
- [x] KubeSphere 应用商店管理
- [x] KubeSphere 应用路由工具
### ❌ 不需要的组件
以下组件**不要勾选**
- 所有 AI/ML 相关算力设备管理、DeepSeek、KAITO、NVIDIA 相关)
- 多集群相关Karmada、联邦集群
- 专用数据库ob-operator、OceanBase
- 服务网格Istio、KubeSphere 服务网格)
---
## 快速部署
### 一键部署
```bash
# 进入 k8s 目录
cd k8s
# 执行部署脚本
chmod +x deploy.sh
./deploy.sh
# 选择选项 1) 完整部署
```
### 部署后验证
```bash
# 查看所有 Pod 状态
kubectl get pods -n wms-system
# 查看服务状态
kubectl get services -n wms-system
# 查看 Ingress
kubectl get ingress -n wms-system
# 查看 HPA
kubectl get hpa -n wms-system
```
---
## 分步部署
### 步骤 1: 创建命名空间
```bash
kubectl apply -f namespace.yaml
```
### 步骤 2: 创建 Secret
```bash
# 先修改 secrets.yaml 中的密码和证书
kubectl apply -f secrets.yaml
```
### 步骤 3: 创建 ConfigMap
```bash
kubectl apply -f configmap.yaml
```
### 步骤 4: 创建存储
```bash
kubectl apply -f pvc.yaml
```
### 步骤 5: 部署中间件
详见 [中间件部署](#中间件部署)
### 步骤 6: 部署微服务
```bash
# 部署所有微服务
kubectl apply -f deployments/
# 或逐个部署
kubectl apply -f deployments/wms-basic-deployment.yaml
kubectl apply -f deployments/wms-inbound-deployment.yaml
kubectl apply -f deployments/wms-outbound-deployment.yaml
kubectl apply -f deployments/wms-inventory-deployment.yaml
kubectl apply -f deployments/wms-schedule-deployment.yaml
```
### 步骤 7: 部署网络和网关
```bash
kubectl apply -f services.yaml
kubectl apply -f ingress.yaml
```
### 步骤 8: 配置自动扩缩容
```bash
kubectl apply -f hpa.yaml
```
---
## 中间件部署
### 方式一Helm 部署(推荐)
```bash
# 添加 Helm Repo
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add minio https://charts.min.io/
helm repo update
# 部署 MySQL
helm install mysql bitnami/mysql \
-f helm/mysql-values.yaml \
-n wms-system
# 部署 Redis
helm install redis bitnami/redis \
-f helm/redis-values.yaml \
-n wms-system
# 部署 MinIO
helm install minio minio/minio \
-f helm/minio-values.yaml \
-n wms-system
```
### 方式二:使用已有中间件
如果已有 MySQL/Redis/MinIO 服务,只需修改 `secrets.yaml` 中的连接信息:
```yaml
# wms-redis-secret
stringData:
host: "已有 Redis 服务地址"
port: "6379"
password: "Redis 密码"
# wms-mysql-secret
stringData:
host: "已有 MySQL 服务地址"
port: "3306"
username: "数据库用户名"
password: "数据库密码"
# wms-minio-secret
stringData:
access-key: "MinIO 访问密钥"
secret-key: "MinIO 密钥"
endpoint: "http://minio 地址9000"
```
---
## 验证和测试
### 1. 检查 Pod 状态
```bash
kubectl get pods -n wms-system -o wide
```
期望输出:
```
NAME READY STATUS RESTARTS AGE
wms-basic-service-xxxxx-xxxxx 1/1 Running 0 5m
wms-inbound-service-xxxxx-xxxxx 1/1 Running 0 5m
wms-outbound-service-xxxxx-xxxxx 1/1 Running 0 5m
wms-inventory-service-xxxxx-xxxxx 1/1 Running 0 5m
wms-schedule-service-xxxxx-xxxxx 1/1 Running 0 5m
```
### 2. 检查服务连接
```bash
# 测试基础服务
kubectl exec -it deployment/wms-basic-service -n wms-system -- \
curl -s http://localhost:8080/actuator/health
# 查看服务日志
kubectl logs -f deployment/wms-basic-service -n wms-system
```
### 3. 访问 API 接口
```bash
# 获取 Ingress 地址
kubectl get ingress -n wms-system
# 测试 API替换为实际域名
curl -k https://wms.yourcompany.com/api/wms/basic/health
curl -k https://wms.yourcompany.com/doc.html
```
### 4. 访问 MinIO 控制台
```bash
# 获取 MinIO 控制台地址
kubectl get ingress -n wms-system | grep minio
# 浏览器访问https://minio-console.yourcompany.com
# 默认账号密码minioadmin / minioadmin123
```
### 5. 测试自动扩缩容
```bash
# 查看 HPA 状态
kubectl get hpa -n wms-system
# 模拟负载测试
kubectl run -i --tty load-tester --image=busybox --rm --restart=Never -- \
while true; do wget -q -O- http://wms-basic-service.wms-system.svc.cluster.local/actuator/health; done
```
---
## 常见问题
### Q1: Pod 无法启动
```bash
# 查看 Pod 详情
kubectl describe pod <pod-name> -n wms-system
# 查看日志
kubectl logs <pod-name> -n wms-system
# 常见问题:
# 1. 镜像拉取失败 -> 检查镜像地址和仓库凭证
# 2. 数据库连接失败 -> 检查 Secret 配置
# 3. 健康检查失败 -> 增加 startupProbe 的 failureThreshold
```
### Q2: 无法访问服务
```bash
# 检查 Ingress Controller
kubectl get pods -n ingress-nginx
# 检查 Ingress 配置
kubectl describe ingress wms-ingress -n wms-system
# 检查 DNS 解析
nslookup wms.yourcompany.com
```
### Q3: HPA 不工作
```bash
# 检查 Metrics Server
kubectl get pods -n kube-system | grep metrics-server
# 查看 HPA 详情
kubectl describe hpa wms-basic-hpa -n wms-system
# 确保 Pod 有 resources 配置
kubectl get deployment wms-basic-service -n wms-system -o yaml
```
### Q4: 存储卷挂载失败
```bash
# 检查 StorageClass
kubectl get sc
# 检查 PVC 状态
kubectl get pvc -n wms-system
# 查看 NFS Provisioner 日志
kubectl logs -n kube-system -l app=nfs-subdir-external-provisioner
```
### Q5: 数据库初始化
```bash
# 连接 MySQL
kubectl run -it --rm --image=mysql:8.0 --restart=Never mysql-client \
-- mysql -h mysql-primary.wms-system.svc.cluster.local -u root -p
# 创建数据库
CREATE DATABASE IF NOT EXISTS `cpte-wms` DEFAULT CHARACTER SET utf8mb4;
```
---
## 监控和运维
### 查看监控指标
1. 登录 KubeSphere 控制台
2. 进入"可观察性" -> "监控"
3. 选择 wms-system 命名空间
### 配置告警
1. 进入"告警管理" -> "告警策略"
2. 创建新的告警规则
3. 配置通知渠道(邮件/钉钉/企业微信)
### 日志查询
1. 进入"可观察性" -> "日志"
2. 选择命名空间wms-system
3. 选择容器进行查询
---
## 升级和回滚
### 升级微服务
```bash
# 更新镜像版本
kubectl set image deployment/wms-basic-service \
wms-basic=registry.yourcompany.com/wms/cpte-wms-basic-service:v3.8.4 \
-n wms-system
# 查看升级状态
kubectl rollout status deployment/wms-basic-service -n wms-system
```
### 回滚
```bash
# 回滚到上一版本
kubectl rollout undo deployment/wms-basic-service -n wms-system
# 回滚到指定版本
kubectl rollout undo deployment/wms-basic-service:2 -n wms-system
```
---
## 联系支持
如有问题,请联系:
- 技术支持cpte@163.com
- 文档http://www.cpte.com/docs