示例:Pulse Force Server(Python)
本例演示 Python 服务使用仓库 Dockerfile 构建,并分别配置 K8S Production 与 Docker Production 两个环境。两个环境共用 Repository,但拥有独立部署配置、Pipeline 和历史。
1. 仓库构建模型
Pulse Force Server 的 Dockerfile:
- 基于 Miniconda
- 使用
environment.yml创建 Python 3.10 环境 - 复制应用并设置
docker-entrypoint.sh - 通过 Gunicorn + Uvicorn Worker 在
6080端口提供服务
Git source → Dockerfile installs Conda/Python dependencies
→ image spark/pulse-force-server:<generated-tag>
→ K8S or Docker runtime
2. App 与 Repository
App Name: Pulse Force Server
App Code: pulse-force-server
Capabilities: Repository, Pipeline
Language: Python
Repository URL: https://e.coding.net/hiforce-inc/pluse-force/pulse-force-server.git
Baseline Branch: master
Git Secret: <选择可读取该仓库的 Git Secret>
Python Language 必须正确选择,否则 Spark 会使用错误的 builder 和语言扩展。
3. K8S Production
环境:
Code: prod
Type: PROD
Cluster Type: K8S
Namespace: prod
关键配置:
| 配置 | 示例值 |
|---|---|
| Container Name | pulse-force-server |
| Dockerfile Path | Dockerfile |
| Image Repository | spark/pulse-force-server |
| Replicas | 2 |
| Container / Service Port | 6080 / 6080 |
| Health Paths | /health |
| CPU Request / Limit | 500m / 4000m |
| Memory Request / Limit | 512Mi / 2048Mi |
| Domain | pulse-ap.hiforce.ai(示例) |
| Log Path | /${user.home}/log/pulse-force-server |
images/spark-pipeline-example-python-k8s-01.webpBuild Settings 使用 Context .。依赖安装由 Dockerfile 完成,因此不需要额外的宿主机 Python 构建命令;如要在构建镜像前运行测试,可配置经过验证的非交互测试命令。
阶段:
Build Image → Test Gate → Deploy to K8S
4. Docker Production
先准备 Docker Cluster:
- 添加能运行 Docker 的 SSH Host。
- 建立
pulse-groupHost Group。 - 创建 Python + Local Build 兼容的 Run Template。
环境:
Code: docker-eu
Name: Docker Production
Type: PROD
Cluster Type: Docker
Host Group: pulse-group
Deployment Configuration:
| 配置 | 示例值 |
|---|---|
| Build Mode | LOCAL_BUILD |
| Dockerfile / Context | Dockerfile / . |
| Image Repository | spark/pulse-force-server |
| Container Name | pulse-force-server-docker-eu |
| Restart Policy | unless-stopped |
| Log Driver | json-file |
| Log Rotation | 10m × 3 |
| Container / Host Port | 6080 / 6080 |
| Health Path | /health |
| Deploy Batch Size | 1 |
| Failure Policy | STOP_ON_FAILURE |
Pipeline 的最后阶段改为 Deploy to Docker。
images/spark-pipeline-example-python-docker-02.webp5. Gate 验证
- Dockerfile 中 Conda channel 可在构建网络中访问。
- 依赖版本固定,构建不是依赖开发机缓存偶然成功。
- 容器启动日志显示 Gunicorn 正常监听
0.0.0.0:6080。 /health在容器内部和部署入口均返回成功。- K8S 的两个副本都 Ready;Docker Host 上旧容器已按模板正确替换。
6. 选择 K8S 还是 Docker
- 需要副本调度、Service、Ingress、资源限制和标准化集群运维时选择 K8S。
- 已有少量固定服务器、希望使用 SSH + Docker CLI 管理时选择 Docker。
- 可以为同一仓库保留两种环境,但发布时务必确认 Pipeline 顶部选择的是正确 Environment。