示例:Spark Console(Java)
Traduction en coursCe guide est actuellement disponible en chinois simplifié. Une version traduite sera ajoutée ultérieurement.
本例演示一个 Java 17、Maven、Spring Boot 应用通过 K8S Pipeline 构建和发布。示例值来自 Spark Console 当前配置,不包含任何 Secret 明文;域名、集群、资源和仓库权限应替换为你的环境。
1. 目标结果
spark-all Git repository
→ mvn -DskipTests package
→ spark-console/target/spark-console.jar
→ spark-console/deploy/Dockerfile
→ hiforce/spark-console:<generated-tag>
→ K8S namespace prod
应用监听 6060,Dockerfile 使用 Java 17 基础镜像启动 /app/spark-console.jar。
2. 平台准备
- 创建可以读取
spark-all的 Git Secret。 - 注册 K8S Cluster,并允许
prodnamespace。 - 配置 Harbor Address、Harbor Secret、Git Clone Image、Kaniko Image 和 Java Builder Image。
- 在 Maven Config 中准备共享
.m2;私服需要认证时上传settings.xml。 - 创建 Java 兼容的 Deployment Template。
images/spark-pipeline-example-java-platform-01.webp3. App 与 Repository
创建 App:
App Name: Spark Console
App Code: spark-console
Capabilities: Repository, Pipeline
Repository:
Language: Java
Repository Type: Git
Repository URL: https://gitlab.hiforce.ai/spark-force/spark-all.git
Baseline Branch: master
Git Secret: <选择可读取该仓库的 Git Secret>
4. Production 环境
创建环境:
Environment Code: prod
Environment Name: Production
Environment Type: PROD
Default Environment: On
Cluster Type: K8S
Namespace: prod
关键 Deployment Configuration:
| 配置 | 示例值 |
|---|---|
| Container Name | spark-console |
| Dockerfile Path | spark-console/deploy/Dockerfile |
| Image Repository | hiforce/spark-console |
| Replicas | 1 |
| Container / Service Port | 6060 / 6060 |
| Domain | spark.hiforce.ai(示例) |
| Startup / Liveness / Readiness | /health/startup、/health/liveness、/health/readiness |
| CPU Request / Limit | 1000m / 4000m |
| Memory Request / Limit | 1024Mi / 2048Mi |
| Config Path | spark-console/src/main/resources/application-eu.properties |
| Config Branch | master |
| Log Path | /root/log/spark-console |
Dockerfile 在仓库子目录,但 Build Context 保持 .,因为它需要读取仓库根目录下构建出的模块产物。
images/spark-pipeline-example-java-deployment-02.webp5. Pipeline
Build Settings:
Build Context Path: .
Build Command: mvn -DskipTests package
阶段:
1. Build Image
2. Test Gate
3. Deploy to K8S
Release Channel 关联 master 或本次要发布的 release branch。点击 Start Build 后,先确认 Maven 日志中 spark-console.jar 已生成,再检查 Kaniko 推送的镜像地址。
6. Gate 验证
Approve 前至少检查:
- Maven 构建成功且没有跳过必须执行的生成步骤。
- 镜像包含最新的 Console 静态资源和后端 JAR。
- 配置文件不包含错误环境的数据库、IDAAS 或外部服务地址。
/health/startup、/health/liveness、/health/readiness与当前应用真实端点一致。
点击 Deploy 后,在 Release Details 核对 Deployment、Service、Ingress/Domain 和最终镜像;再访问 Console 登录页和一条认证业务接口完成冒烟验证。
7. 常见调整
- 只构建必要模块时,可以将 Build Command 改为经过验证的 Maven reactor 命令,但必须确保 Dockerfile 引用的所有产物存在。
- 如果 Maven 下载慢,先优化 Cluster Maven Config,不要在每个 App 中复制私服密码。
- 如果 Dockerfile 移到其他目录,同时更新 Deployment Configuration;Build Settings 中不再单独维护 Dockerfile Path。