基于 OpenClaw + Claude Code 的端到端研发自动化系统
| 节点角色 | 数量 | CPU | 内存 | 磁盘 | 用途 |
|---|---|---|---|---|---|
| Master (Control Plane) | 3 | 4 核+ | 8GB+ | 100GB+ | 集群控制平面、etcd |
| Worker (CI/CD) | 1 | 8 核+ | 16GB+ | 200GB+ | Jenkins Runner、构建任务 |
| Worker (Test) | 1 | 8 核+ | 16GB+ | 200GB+ | 自动化测试、集成测试 |
| Worker (App) | 1+ | 8 核+ | 16GB+ | 200GB+ | 应用部署、业务负载 |
| 操作系统 | 版本 | 内核版本 | 支持状态 |
|---|---|---|---|
| Ubuntu | 20.04 / 22.04 LTS | 4.15+ | ✅ 推荐 |
| CentOS | 7.6 - 7.9 | 3.10+ | ✅ 支持 |
| Rocky Linux | 8.x / 9.x | 4.18+ | ✅ 推荐 |
| Debian | 10 / 11 | 4.19+ | ✅ 支持 |
# 关闭防火墙和 SELinux
systemctl stop firewalld && systemctl disable firewalld
setenforce 0 && sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 关闭 Swap
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# 加载内核模块
cat > /etc/modules-load.d/k8s.conf < /etc/sysctl.d/k8s.conf <
# 赋予脚本执行权限
chmod +x k8s_deploy.sh
# 执行系统检查
./k8s_deploy.sh check
# 输出示例:
[INFO] 2026-03-13 14:30:00 - === 开始前置检查 ===
[INFO] 2026-03-13 14:30:00 - 操作系统:Ubuntu 22.04.3 LTS
[INFO] 2026-03-13 14:30:00 - CPU 核心数:8
[INFO] 2026-03-13 14:30:00 - 可用内存:32GB
[INFO] 2026-03-13 14:30:00 - 可用磁盘空间:500GB
[SUCCESS] 2026-03-13 14:30:01 - 前置检查完成
# 执行系统优化
./k8s_deploy.sh optimize
# 安装系统依赖
./k8s_deploy.sh deps
# 安装 Docker
./k8s_deploy.sh docker
# 验证 Docker 安装
docker --version
docker info
# 安装 KubeKey (Kubernetes 安装器)
./k8s_deploy.sh kubekey
# 验证安装
kk version
# 输出示例:
KubeKey version: v3.0.13
Kubernetes version: v1.28.7
KubeSphere version: v3.4.1
# 生成集群配置文件
./k8s_deploy.sh config
# 编辑配置文件
vim k8s_cluster_config.yaml
# 关键配置项:
# - hosts: 所有节点信息
# - roleGroups: 角色分组
# - controlPlaneEndpoint: 负载均衡配置
# - network: 网络插件配置
# - storage: 存储类配置
# 开始部署 Kubernetes 集群
./k8s_deploy.sh deploy
# 部署成功后验证
kubectl cluster-info
kubectl get nodes
kubectl get pods -n kube-system
# 输出示例:
Kubernetes control plane is running at https://192.168.10.100:6443
CoreDNS is running at https://192.168.10.100:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
NAME STATUS ROLES AGE VERSION
master-node-1 Ready control-plane 10m v1.28.7
master-node-2 Ready control-plane 10m v1.28.7
master-node-3 Ready control-plane 10m v1.28.7
worker-node-1 Ready worker 8m v1.28.7
worker-node-2 Ready worker 8m v1.28.7
worker-node-3 Ready worker 8m v1.28.7
# 赋予脚本执行权限
chmod +x kubesphere_install.sh
# 一键安装 KubeSphere (包含所有步骤)
./kubesphere_install.sh all
# 或分步执行:
# ./kubesphere_install.sh check # 前置检查
# ./kubesphere_install.sh backup # 创建备份
# ./kubesphere_install.sh install # 安装核心组件
# ./kubesphere_install.sh monitor # 监控安装进度
# ./kubesphere_install.sh verify # 验证安装
# ./kubesphere_install.sh access # 获取访问信息
# 实时查看安装日志
INSTALLER_POD=$(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}')
kubectl logs -n kubesphere-system $INSTALLER_POD -f
# 等待所有组件就绪
watch kubectl get pods -n kubesphere-system
AI Agents 辅助需求收集、分析和 PRD 文档自动生成
前后端技术方案自动生成、API 接口协议设计
基于设计文档,AI 辅助代码生成与人机协同开发
自动化单元测试生成与执行、覆盖率分析
API 集成测试、端到端测试自动化
Jenkins 流水线触发、Docker 镜像构建、K8s 自动部署
Selenium/CypressUI 自动化测试、验收报告生成
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
metadata:
name: jenkins-agent
spec:
containers:
- name: maven
image: maven:3.8-openjdk-17
command:
- cat
tty: true
- name: docker
image: docker:24.0
command:
- cat
tty: true
'''
}
}
environment {
REGISTRY = 'harbor.research-automation.local'
IMAGE_NAME = 'myapp-backend'
KUBECONFIG = credentials('kubeconfig')
}
stages {
stage('Checkout') {
steps {
git branch: 'main',
url: 'https://gitlab.research-automation.local/team/myapp.git'
}
}
stage('Code Quality') {
steps {
sh 'mvn sonar:sonar -Dsonar.host.url=http://sonarqube:9000'
}
}
stage('Unit Test') {
steps {
sh 'mvn test'
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
}
}
stage('Build & Push Image') {
steps {
script {
docker.withRegistry("https://${REGISTRY}", 'harbor-credentials') {
def image = docker.build("${IMAGE_NAME}:${BUILD_ID}")
image.push()
image.push('latest')
}
}
}
}
stage('Deploy to K8s') {
steps {
sh '''
kubectl set image deployment/${IMAGE_NAME} \
${IMAGE_NAME}=${REGISTRY}/${IMAGE_NAME}:${BUILD_ID} \
-n production
kubectl rollout status deployment/${IMAGE_NAME} -n production
'''
}
}
stage('UI Auto Test') {
steps {
sh 'npm run e2e:test'
}
}
}
post {
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed!'
}
}
}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: restricted
spec:
privileged: false
allowPrivilegeEscalation: false
requiredDropCapabilities:
- ALL
volumes:
- 'configMap'
- 'emptyDir'
- 'projected'
- 'secret'
- 'downwardAPI'
- 'persistentVolumeClaim'
hostNetwork: false
hostIPC: false
hostPID: false
runAsUser:
rule: 'MustRunAsNonRoot'
seLinux:
rule: 'RunAsAny'
fsGroup:
rule: 'RunAsAny'
readOnlyRootFilesystem: true
# Kubernetes 审计策略
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
# 记录所有写操作
- level: RequestResponse
verbs: ["create", "update", "patch", "delete"]
# 记录敏感资源的读操作
- level: Metadata
resources:
- group: ""
resources: ["secrets", "configmaps"]
# 默认级别
- level: Metadata
omitStages:
- "RequestReceived"
| 类别 | 指标 | 告警阈值 | 说明 |
|---|---|---|---|
| 节点资源 | CPU 使用率 | > 80% | 节点 CPU 负载 |
| 内存使用率 | > 85% | 节点内存压力 | |
| 磁盘使用率 | > 85% | 节点存储空间 | |
| Pod 状态 | 重启次数 | > 5 次/小时 | Pod 异常重启 |
| Pending 时间 | > 5 分钟 | 调度失败 | |
| CrashLoopBackOff | 立即 | 容器启动失败 | |
| 控制平面 | API Server 延迟 | > 1s | API 响应时间 |
| etcd 延迟 | > 100ms | etcd 性能 |
# 查询特定 Pod 的日志
kubectl logs -f -n
# 查询包含错误信息的日志
kubectl logs | grep -i error
# 查询最近 1 小时的日志
kubectl logs --since=1h
# 查询多容器 Pod 中指定容器的日志
kubectl logs -c
# 使用 stern 实时查看所有匹配 Pod 的日志
stern -n
可能原因:
排查命令:
kubectl describe pod
kubectl get events --sort-by='.lastTimestamp'
kubectl top nodes
kubectl get pvc
可能原因:
排查命令:
kubectl logs --previous
kubectl describe pod
kubectl get events
kubectl exec -- env
可能原因:
排查命令:
kubectl get endpoints
kubectl describe service
kubectl get networkpolicy
kubectl get pods -l
可能原因:
排查命令:
kubectl get pods -n kubesphere-system
kubectl get svc ks-console -n kubesphere-system
kubectl logs -n kubesphere-system -l app=ks-console
iptables -L -n | grep 30880
#!/bin/bash
# K8s 集群健康诊断脚本
echo "=== 节点状态 ==="
kubectl get nodes -o wide
echo -e "\n=== 系统 Pod 状态 ==="
kubectl get pods -n kube-system
echo -e "\n=== KubeSphere 组件 ==="
kubectl get pods -n kubesphere-system
echo -e "\n=== 资源使用情况 ==="
kubectl top nodes
kubectl top pods --all-namespaces
echo -e "\n=== 最近事件 ==="
kubectl get events --sort-by='.lastTimestamp' | tail -20
echo -e "\n=== PVC 状态 ==="
kubectl get pvc --all-namespaces
echo -e "\n=== 证书有效期 ==="
kubeadm certs check-expiration 2>/dev/null || echo "非 kubeadm 部署"
| 文件名 | 用途 | 说明 |
|---|---|---|
k8s_cluster_config.yaml |
K8s 集群配置 | KubeKey 集群定义文件 |
k8s_deploy.sh |
K8s 部署脚本 | 一键部署 Kubernetes 集群 |
kubesphere_config.yaml |
KubeSphere 配置 | KubeSphere 组件启用配置 |
kubesphere_install.sh |
KubeSphere 安装脚本 | 一键安装 KubeSphere 平台 |
k8s_kubesphere_deployment_report.html |
部署报告 | 本文档 (HTML 格式) |