Explorar o código

feat: Implement Umbrella Chart with base template library and multi-environment support

- Transform project to Umbrella Chart architecture
- Create base library chart for template code reuse
- Add three example microservices: user-service, order-service, payment-service
- Implement multi-environment configuration (dev, staging, prod)
- Add comprehensive README with architecture documentation
- Enable flexible service enable/disable configuration
- Support global configuration sharing across all services
DevOps Team hai 3 meses
pai
achega
2bf3877965

+ 30 - 3
Chart.yaml

@@ -1,6 +1,33 @@
 apiVersion: v2
-name: java-microservice
-description: A Helm chart for Java microservice with Deployment, Service and ConfigMap
+name: microservice-platform
+description: Umbrella Helm chart for managing multiple microservices with shared configuration and templating
 type: application
-version: 0.1.0
+version: 1.0.0
 appVersion: "1.0"
+keywords:
+  - microservices
+  - kubernetes
+  - umbrella
+home: https://github.com/jiangkai/microservice-helm
+sources:
+  - https://github.com/jiangkai/microservice-helm
+maintainers:
+  - name: DevOps Team
+    email: devops@example.com
+dependencies:
+  - name: base
+    version: 1.0.0
+    repository: file://../charts/base
+    condition: base.enabled
+  - name: user-service
+    version: 1.0.0
+    repository: file://../charts/user-service
+    condition: user-service.enabled
+  - name: order-service
+    version: 1.0.0
+    repository: file://../charts/order-service
+    condition: order-service.enabled
+  - name: payment-service
+    version: 1.0.0
+    repository: file://../charts/payment-service
+    condition: payment-service.enabled

+ 279 - 392
README.md

@@ -1,445 +1,363 @@
-# Java Microservice Helm Chart
+# Microservice Platform - Helm Chart
 
-## 概述
+## 📋 概述
 
-这是一个用于部署Java微服务应用到Kubernetes集群的Helm Chart。该Chart提供了完整的Kubernetes资源配置,包括Deployment、Service和ConfigMap,支持灵活的应用配置和资源管理
+这是一个企业级微服务平台的Helm Chart实现,采用**Umbrella Chart + 通用模板库**的混合架构。支持多个Java微服务的统一部署、配置管理和多环境部署
 
-**Chart版本:** 0.1.0  
-**应用版本:** 1.0  
-**API版本:** v2
+**架构版本:** 1.0.0  
+**支持的微服务:** user-service, order-service, payment-service(可扩展)  
+**部署环境:** dev, staging, production
 
 ---
 
-## 主要特性
+## 🎯 主要特性
 
-✅ **开箱即用的Deployment配置** - 包含health checks、资源限制和安全上下文  
-✅ **灵活的服务发现** - 支持ClusterIP、NodePort和LoadBalancer类型  
-✅ **应用配置管理** - 通过ConfigMap管理application.properties和application.yml  
-✅ **Spring Boot集成** - 原生支持Spring Boot Actuator端点  
-✅ **可扩展设计** - 完整的Helm模板化和参数配置  
-✅ **生产就绪** - 包含liveness probe和readiness probe  
+✅ **Umbrella Chart架构** - 统一部署管理多个微服务  
+✅ **模板代码复用** - 通用base chart,减少重复代码  
+✅ **灵活的服务启用/禁用** - 可按需启用或禁用任意微服务  
+✅ **多环境配置管理** - 开发、测试、生产环境差异化配置  
+✅ **全局配置共享** - 支持跨服务的全局配置  
+✅ **Spring Boot原生支持** - 完整的Actuator、日志、配置管理  
+✅ **生产就绪** - 包含health check、资源限制、副本控制  
+✅ **易于扩展** - 快速添加新的微服务  
 
 ---
 
-## 项目结构
-
-```
-java-microservice/
-├── Chart.yaml                    # Helm Chart定义文件
-├── values.yaml                   # 默认配置值
-├── README.md                      # 本文件
-└── templates/
-    ├── deployment.yaml           # Kubernetes Deployment资源模板
-    ├── service.yaml              # Kubernetes Service资源模板
-    └── configmap.yaml            # Kubernetes ConfigMap资源模板
+## 📁 项目结构
+
+```
+microservice-helm/
+├── Chart.yaml                          # Umbrella Chart定义
+├── values.yaml                         # 全局配置(各服务默认值)
+├── README.md                           # 本文档
+├── templates/                          # 根级templates
+│   ├── configmap.yaml
+│   ├── deployment.yaml
+│   └── service.yaml
+├── charts/                             # 子Chart目录
+│   ├── base/                           # 通用模板库(不部署)
+│   │   ├── Chart.yaml
+│   │   ├── values.yaml
+│   │   └── templates/
+│   │       ├── configmap.yaml
+│   │       ├── deployment.yaml
+│   │       └── service.yaml
+│   ├── user-service/                   # 用户服务
+│   │   ├── Chart.yaml
+│   │   ├── values.yaml
+│   │   └── templates/
+│   ├── order-service/                  # 订单服务
+│   │   ├── Chart.yaml
+│   │   ├── values.yaml
+│   │   └── templates/
+│   └── payment-service/                # 支付服务
+│       ├── Chart.yaml
+│       ├── values.yaml
+│       └── templates/
+└── environments/                       # 环境特定配置
+    ├── dev-values.yaml
+    ├── staging-values.yaml
+    └── prod-values.yaml
 ```
 
-### 文件说明
-
-| 文件 | 说明 |
-|------|------|
-| **Chart.yaml** | 定义Helm Chart的元数据(名称、版本、描述等) |
-| **values.yaml** | 包含所有可配置的默认值和参数 |
-| **templates/deployment.yaml** | 定义Kubernetes Pod、副本和容器配置 |
-| **templates/service.yaml** | 定义Service用于服务发现和负载均衡 |
-| **templates/configmap.yaml** | 定义ConfigMap用于存储应用配置文件 |
-
 ---
 
-## 快速开始
+## 🚀 快速开始
 
 ### 前置条件
 
-- Kubernetes集群 (1.16+)
+- Kubernetes集群 1.16+
 - Helm 3.0+
-- Docker镜像仓库访问权限
+- kubectl 已配置并能访问集群
 
 ### 安装
 
-#### 1. 使用默认配置安装
+#### 1️⃣ 部署全部微服务(默认配置)
+
+```bash
+helm install microservice-platform ./
+```
+
+#### 2️⃣ 部署特定环境
 
 ```bash
-helm install java-app ./java-microservice
+# 开发环境
+helm install microservice-platform ./ \
+  -f environments/dev-values.yaml
+
+# 预发布环境
+helm install microservice-platform ./ \
+  -f environments/staging-values.yaml
+
+# 生产环境
+helm install microservice-platform ./ \
+  -f environments/prod-values.yaml
 ```
 
-#### 2. 自定义配置安装
+#### 3️⃣ 选择性部署微服务
 
 ```bash
-helm install java-app ./java-microservice \
-  --set image.repository=your-registry/java-app \
-  --set image.tag=1.0.0 \
-  --set app.replicaCount=3
+# 仅部署user-service和order-service
+helm install microservice-platform ./ \
+  --set user-service.enabled=true \
+  --set order-service.enabled=true \
+  --set payment-service.enabled=false
 ```
 
-#### 3. 使用自定义values文件安装
+#### 4️⃣ 自定义镜像仓库和版本
 
 ```bash
-helm install java-app ./java-microservice -f custom-values.yaml
+helm install microservice-platform ./ \
+  --set global.image.registry=your-registry \
+  --set user-service.image.tag=v2.0.0 \
+  --set order-service.image.tag=v1.5.0
 ```
 
-#### 4. 验证安装
+#### 5️⃣ 验证安装
 
 ```bash
-# 查看已安装的Release
+# 查看Release状态
 helm list
 
-# 获取Deployment详情
-kubectl get deployment java-microservice
+# 查看已部署的资源
+kubectl get all -l platform=microservice-platform
+
+# 查看Deployment状态
+kubectl get deployment
 
 # 查看Pod状态
-kubectl get pods -l app=java-microservice
+kubectl get pods
 
-# 查看Service
-kubectl get svc java-microservice
+# 查看Service和暴露的端口
+kubectl get svc
 ```
 
 ---
 
-## 配置参数
+## 📊 配置详解
+
+### 全局配置(values.yaml)
+
+所有微服务共享的全局配置。详见 `values.yaml` 文件中的 `global` 部分。
+
+### 微服务配置
 
-### 应用配置
+#### User Service 配置
 
 | 参数 | 默认值 | 说明 |
 |------|--------|------|
-| `app.name` | `java-microservice` | 应用名称,用于Deployment和Service命名 |
-| `app.replicaCount` | `1` | Pod副本数量 |
+| `user-service.enabled` | `true` | 是否启用该服务 |
+| `user-service.app.replicaCount` | `1` | Pod副本数 |
+| `user-service.image.tag` | `1.0.0` | 镜像标签 |
+| `user-service.service.port` | `8080` | 服务端口 |
 
-### 镜像配置
+#### Order Service 配置
 
 | 参数 | 默认值 | 说明 |
 |------|--------|------|
-| `image.repository` | `your-registry/java-app` | Docker镜像仓库地址 |
-| `image.tag` | `1.0.0` | Docker镜像标签/版本 |
-| `image.pullPolicy` | `IfNotPresent` | 镜像拉取策略(Always/IfNotPresent/Never) |
+| `order-service.enabled` | `true` | 是否启用该服务 |
+| `order-service.app.replicaCount` | `1` | Pod副本数 |
+| `order-service.image.tag` | `1.0.0` | 镜像标签 |
+| `order-service.service.port` | `8081` | 服务端口 |
 
-### Service配置
+#### Payment Service 配置
 
 | 参数 | 默认值 | 说明 |
 |------|--------|------|
-| `service.type` | `ClusterIP` | Service类型(ClusterIP/NodePort/LoadBalancer) |
-| `service.port` | `8080` | Service暴露的端口 |
-| `service.targetPort` | `8080` | 容器目标端口 |
+| `payment-service.enabled` | `true` | 是否启用该服务 |
+| `payment-service.app.replicaCount` | `1` | Pod副本数 |
+| `payment-service.image.tag` | `1.0.0` | 镜像标签 |
+| `payment-service.service.port` | `8082` | 服务端口 |
 
-### 应用属性配置
+---
 
-#### Properties文件配置(`.properties` 格式)
+## 🌍 环境配置
 
-```yaml
-application.properties:
-spring.application.name={{ app.name }}
-spring.protocol.name=spring
-server.port={{ app.port }}
-```
+该项目支持多环境部署:
 
-#### YAML文件配置(`.yml` 格式)
+### 开发环境 (dev-values.yaml)
 
-```yaml
-config.yml:
-  logging:
-    level:
-      root: INFO
-      com:
-        example: DEBUG
-  management:
-    endpoints:
-      web:
-        exposure:
-          include: health,info,metrics
-    endpoint:
-      health:
-        show-details: when-authorized
+- 单副本部署
+- DEBUG日志级别
+- 最新开发镜像
+- 宽松的DDL策略(create-drop)
+
+**部署方式:**
+```bash
+helm install microservice-platform ./ -f environments/dev-values.yaml
 ```
 
-### 资源配置
+### 预发布环境 (staging-values.yaml)
 
-| 参数 | 默认值 | 说明 |
-|------|--------|------|
-| `resources.requests.cpu` | `250m` | CPU请求量 |
-| `resources.requests.memory` | `256Mi` | 内存请求量 |
-| `resources.limits.cpu` | `500m` | CPU限制量 |
-| `resources.limits.memory` | `512Mi` | 内存限制量 |
+- 双副本部署
+- INFO日志级别
+- 最新staging镜像
+- 严格的DDL策略(validate)
 
-### 高级配置
+### 生产环境 (prod-values.yaml)
 
-| 参数 | 默认值 | 说明 |
-|------|--------|------|
-| `podAnnotations` | `{}` | Pod注解 |
-| `securityContext` | `{}` | Pod安全上下文 |
-| `nodeSelector` | `{}` | 节点选择器 |
-| `tolerations` | `[]` | 容忍度配置 |
-| `affinity` | `{}` | Pod亲和力配置 |
+- 三副本高可用部署
+- WARN日志级别
+- 固定版本镜像(不使用latest)
+- 严格的资源限制
+- 完全的DDL验证
 
 ---
 
-## 使用示例
+## 💡 使用示例
 
-### 示例1:部署到开发环境
+### 示例1:基础部署
 
 ```bash
-helm install java-dev ./java-microservice \
-  --namespace dev \
-  --create-namespace \
-  --set image.repository=your-registry/java-app \
-  --set image.tag=dev-latest \
-  --set app.replicaCount=1
+helm install my-platform ./
 ```
 
-### 示例2:生产环境部署(高可用)
+### 示例2:生产环境部署
 
 ```bash
-helm install java-prod ./java-microservice \
+helm install microservice-prod ./ \
   --namespace prod \
   --create-namespace \
-  --values prod-values.yaml
+  -f environments/prod-values.yaml
 ```
 
-其中 `prod-values.yaml` 内容如下:
-
-```yaml
-app:
-  replicaCount: 3
-
-image:
-  repository: your-registry/java-app
-  tag: "1.0.0"
-
-service:
-  type: LoadBalancer
-  port: 80
-  targetPort: 8080
-
-resources:
-  requests:
-    cpu: 500m
-    memory: 512Mi
-  limits:
-    cpu: 1000m
-    memory: 1024Mi
-```
-
-### 示例3:更新现有Release
+### 示例3:添加新的微服务
 
+1. 创建Chart目录:
 ```bash
-helm upgrade java-app ./java-microservice \
-  --set image.tag=1.1.0
+mkdir -p charts/notification-service/templates
 ```
 
-### 示例4:配置数据库连接
+2. 创建Chart.yaml和values.yaml
 
-编辑 `values.yaml` 中的数据库配置:
+3. 在Chart.yaml中添加依赖声明
 
-```yaml
-config:
-  properties:
-    spring.datasource.url: jdbc:mysql://mysql-service:3306/mydb
-    spring.datasource.username: appuser
-    spring.datasource.password: secure-password
-```
+4. 在environments/中为新服务添加配置
+
+详见README中的详细说明部分。
 
-然后安装或升级:
+### 示例4:升级应用版本
 
 ```bash
-helm install java-app ./java-microservice
+helm upgrade microservice-platform ./ \
+  --set user-service.image.tag=1.1.0 \
+  --set order-service.image.tag=1.1.0 \
+  --set payment-service.image.tag=1.1.0
 ```
 
----
-
-## 模板详解
-
-### Deployment Template (deployment.yaml)
+### 示例5:灾难恢复
 
-**功能:**
-- 定义应用Pod的部署配置
-- 配置容器镜像、端口和环境变量
-- 挂载ConfigMap作为配置文件
-- 配置health checks(liveness和readiness probe)
-- 支持资源限制和安全策略
+```bash
+# 查看发布历史
+helm history microservice-platform
 
-**关键特性:**
-```yaml
-# Health Check配置
-livenessProbe:
-  httpGet:
-    path: /actuator/health
-    port: http
-  initialDelaySeconds: 30
-  periodSeconds: 10
-
-readinessProbe:
-  httpGet:
-    path: /actuator/health
-    port: http
-  initialDelaySeconds: 5
-  periodSeconds: 5
-
-# 环境变量配置
-env:
-  - name: JAVA_OPTS
-    value: "-Xmx512m -Xms256m"
-
-# ConfigMap挂载
-volumeMounts:
-  - name: config-volume
-    mountPath: /etc/config
-    readOnly: true
+# 回滚到前一个版本
+helm rollback microservice-platform 1
 ```
 
-### Service Template (service.yaml)
-
-**功能:**
-- 暴露应用服务到集群内外
-- 支持多种服务类型
-- 配置端口映射和负载均衡
-
-**支持的Service类型:**
-- `ClusterIP`:仅在集群内访问(默认)
-- `NodePort`:通过节点IP和端口访问
-- `LoadBalancer`:通过外部负载均衡器访问
-
-### ConfigMap Template (configmap.yaml)
-
-**功能:**
-- 将应用配置外部化
-- 支持`.properties`和`.yml`两种格式
-- 配置无需重新构建镜像
-
-**配置文件位置(容器内):**
-- `/etc/config/application.properties`
-- `/etc/config/application.yml`
-
 ---
 
-## 常见操作
+## 🔍 常见操作
 
-### 查看Release状态
+### 查看部署状态
 
 ```bash
-helm status java-app
-```
+# 查看Release信息
+helm status microservice-platform
 
-### 查看Release使用的Values
+# 查看Release使用的values
+helm get values microservice-platform
 
-```bash
-helm get values java-app
+# 查看Release部署的资源
+helm get manifest microservice-platform
 ```
 
-### 查看Release部署的资源
+### 调试和测试
 
 ```bash
-helm get manifest java-app
-```
+# 验证Chart语法
+helm lint ./
 
-### 测试模板渲染
+# 渲染模板(不实际部署)
+helm template microservice-platform ./
 
-```bash
-helm template java-app ./java-microservice --debug
+# 详细渲染(查看完整输出)
+helm template microservice-platform ./ --debug
 ```
 
-### 删除Release
+### 日志和监控
 
 ```bash
-helm uninstall java-app
-```
+# 查看所有微服务日志
+kubectl logs -l platform=microservice-platform -f
 
-### 查看Pod日志
+# 查看特定服务日志
+kubectl logs -l app=user-service -f
 
-```bash
-kubectl logs -l app=java-microservice -f
+# 查看Pod详情
+kubectl describe pod <pod-name>
 ```
 
-### 访问应用
-
-#### 本地端口转发(开发环境)
+### 端口转发(本地测试)
 
 ```bash
-kubectl port-forward svc/java-microservice 8080:8080
-curl http://localhost:8080/actuator/health
-```
-
-#### 通过Service(集群内)
+# 转发user-service
+kubectl port-forward svc/user-service 8080:8080
 
-```bash
-curl http://java-microservice:8080/actuator/health
+# 在另一个终端测试
+curl http://localhost:8080/actuator/health
 ```
 
-#### 通过NodePort
+### 删除Release
 
 ```bash
-# 获取节点IP和NodePort
-kubectl get nodes -o wide
-kubectl get svc java-microservice
+# 删除Release(保留PVC)
+helm uninstall microservice-platform
 
-# 访问
-curl http://<NODE_IP>:<NODE_PORT>/actuator/health
+# 删除namespace
+kubectl delete namespace <namespace>
 ```
 
 ---
 
-## 故障排查
+## 🏗️ 架构说明
 
-### 问题1:Pod处于Pending状态
+### Umbrella Chart设计
 
-```bash
-# 查看Pod事件
-kubectl describe pod <pod-name>
-
-# 检查资源可用性
-kubectl top nodes
-```
+**Umbrella Chart** 的核心作用:
+1. 作为多个子Chart的容器
+2. 提供全局配置和共享值
+3. 支持子Chart的条件启用/禁用
+4. 实现统一的部署管理
 
-**解决方案:**
-- 检查集群资源是否充足
-- 调整资源请求和限制
-- 检查节点是否有污点(taints)
+### 模板继承
 
-### 问题2:镜像拉取失败
+各微服务的templates通过引用base chart实现代码复用:
 
-```bash
-# 查看Pod日志
-kubectl describe pod <pod-name>
+```yaml
+{{- include "base.deployment" . -}}
+{{- include "base.service" . -}}
+{{- include "base.configmap" . -}}
 ```
 
-**解决方案:**
-- 验证镜像仓库地址
-- 检查镜像标签是否正确
-- 配置镜像拉取密钥(如果为私有仓库)
-
-### 问题3:应用无法启动
-
-```bash
-# 查看容器日志
-kubectl logs <pod-name>
+这样可以:
+- 避免重复代码
+- 统一部署配置
+- 快速添加新服务
+- 简化维护
 
-# 进入容器调试
-kubectl exec -it <pod-name> -- /bin/bash
-```
+---
 
-**解决方案:**
-- 检查应用配置是否正确
-- 验证数据库连接信息
-- 检查Spring Boot Actuator是否正确配置
+## ⚙️ 高级配置
 
-### 问题4:Health Check失败
+### 副本自动扩展(HPA)
 
 ```bash
-# 手动测试health endpoint
-kubectl exec -it <pod-name> -- curl localhost:8080/actuator/health
+kubectl autoscale deployment user-service \
+  --min=2 --max=10 --cpu-percent=80
 ```
 
-**解决方案:**
-- 调整probe的initialDelaySeconds
-- 检查应用是否正确实现了health endpoint
-- 查看应用日志获取更多信息
-
----
-
-## 安全最佳实践
-
-### 1. 配置资源限制
-
-始终为容器设置CPU和内存限制,防止资源耗尽。
-
-### 2. 安全上下文配置
+### 安全上下文
 
 ```yaml
 securityContext:
@@ -448,151 +366,120 @@ securityContext:
   readOnlyRootFilesystem: true
 ```
 
-### 3. RBAC配置
-
-为应用创建最小权限的Service Account。
+### 资源限制
 
-### 4. 敏感信息管理
-
-- 使用Kubernetes Secrets存储密码和API Key
-- 不要在ConfigMap中存储敏感信息
-- 定期轮换凭证
+始终为容器定义资源请求和限制,防止资源耗尽。详见environment配置。
 
 ---
 
-## 性能优化
+## 🔐 安全最佳实践
 
-### 1. 调整JVM内存参数
+### 1. 资源限制和请求
 
-```yaml
-env:
-  - name: JAVA_OPTS
-    value: "-Xmx1024m -Xms512m -XX:+UseG1GC"
-```
+详见environment配置文件中的资源设置。
 
-### 2. 优化Health Check
+### 2. 敏感信息管理
 
-```yaml
-livenessProbe:
-  initialDelaySeconds: 60  # 增加初始延迟时间
-  periodSeconds: 30        # 减少检查频率
-```
+- ✅ 使用Kubernetes Secrets存储密码
+- ✅ 不要在ConfigMap中存储敏感信息
+- ✅ 定期轮换凭证
 
-### 3. 配置副本和自动扩展
+### 3. 健康检查
 
-```bash
-# 使用HPA(Horizontal Pod Autoscaler)
-kubectl autoscale deployment java-microservice \
-  --min=2 --max=10 --cpu-percent=80
-```
+已包含的liveness和readiness probe配置可防止故障pod继续服务。
 
 ---
 
-## 升级和回滚
+## 📈 性能优化
 
-### 升级应用版本
+### 调整JVM参数
 
-```bash
-# 使用新镜像标签升级
-helm upgrade java-app ./java-microservice \
-  --set image.tag=1.1.0
+在environment配置中修改JAVA_OPTS。
 
-# 查看升级状态
-helm status java-app
-```
+### 优化健康检查
 
-### 回滚到前一版本
+- 增加初始延迟时间:initialDelaySeconds
+- 减少检查频率:periodSeconds
 
-```bash
-# 查看历史发布
-helm history java-app
+### Pod亲和力配置
 
-# 回滚到指定版本
-helm rollback java-app 1
-```
+实现Pod高可用分布,避免单点故障。
 
 ---
 
-## 监控和日志
+## 🐛 故障排查
 
-### 查看应用日志
+### Pod处于Pending状态
 
 ```bash
-# 查看当前Pod日志
-kubectl logs -l app=java-microservice
-
-# 跟踪日志(实时)
-kubectl logs -l app=java-microservice -f
-
-# 查看前50行日志
-kubectl logs -l app=java-microservice --tail=50
+kubectl describe pod <pod-name>
+kubectl top nodes
 ```
 
-### Spring Boot Actuator端
+**原因:** 资源不足或节点有污点
 
-该Chart已配置以下Actuator端点:
+### 镜像拉取失败
 
-- `/actuator/health` - 应用健康状态
-- `/actuator/info` - 应用信息
-- `/actuator/metrics` - 应用指标
+**原因:** 镜像地址错误、标签不存在或凭证不正确
 
-访问这些端点:
+### 应用无法启动
 
 ```bash
-kubectl exec -it <pod-name> -- \
-  curl -s http://localhost:8080/actuator/health | json_pp
+kubectl logs <pod-name>
+kubectl logs <pod-name> --previous
 ```
 
+**原因:** 配置错误、依赖服务不可用
+
 ---
 
-## 贡献指南
+## 📚 相关资源
 
-欢迎提交Issue和Pull Request来改进此Chart。
+- [Helm官方文档](https://helm.sh/docs/)
+- [Kubernetes官方文档](https://kubernetes.io/docs/)
+- [Spring Boot官方文档](https://spring.io/projects/spring-boot)
+- [Helm Chart最佳实践](https://helm.sh/docs/chart_best_practices/)
 
 ---
 
-## 许可证
+## 📝 更新日志
 
-此Chart遵循开源许可证。
+### v1.0.0 (2026-01-15)
+- ✅ 初始化Umbrella Chart架构
+- ✅ 创建base通用模板库
+- ✅ 实现3个示例微服务(user、order、payment)
+- ✅ 创建多环境配置(dev、staging、prod)
+- ✅ 完整的文档和示例
 
 ---
 
-## 相关资源
+## ❓ 常见问题(FAQ)
 
-- [Helm官方文档](https://helm.sh/docs/)
-- [Kubernetes官方文档](https://kubernetes.io/docs/)
-- [Spring Boot官方文档](https://spring.io/projects/spring-boot)
-- [Spring Boot Actuator文档](https://spring.io/guides/gs/actuator-service/)
+**Q: 如何添加新的微服务?**  
+A: 在charts目录下创建新的Chart,按照现有服务的结构创建Chart.yaml、values.yaml和templates,然后在Umbrella Chart的Chart.yaml中声明依赖。
 
----
-
-## 更新日志
+**Q: 如何为单个服务禁用某个功能?**  
+A: 在该服务对应的environment配置中进行覆盖。
 
-### v0.1.0 (2026-01-15)
-- 初始版本
-- 支持基础Deployment、Service和ConfigMap
-- 包含Spring Boot应用配置管理
-- 配置Health Check和资源限制
+**Q: 如何实现灰度部署?**  
+A: 使用Helm分阶段升级,先更新镜像标签到新版本的一部分副本。
 
----
+**Q: base chart的版本如何管理?**  
+A: 在Umbrella Chart的Chart.yaml中指定版本,提升base版本时更新依赖声明。
 
-## 常见问题(FAQ)
+**Q: 是否支持Helm values的继承?**  
+A: 是的,子Chart的values会自动与全局values合并。
 
-**Q: 如何修改应用配置而不重新部署?**  
-A: 编辑ConfigMap并重启Pod即可:
-```bash
-kubectl rollout restart deployment/java-microservice
-```
+---
 
-**Q: 支持多环境部署吗?**  
-A: 是的,为每个环境创建不同的values文件,使用`-f`参数指定。
+## 📞 支持
 
-**Q: 如何扩展副本数量?**  
-A: 使用`--set app.replicaCount=N`或编辑values.yaml。
+遇到问题或有建议?
 
-**Q: 支持灰度发布吗?**  
-A: 可以使用Helm升级,并通过修改镜像标签来实现灰度。
+- 提交Issue:https://github.com/jiangkai/microservice-helm/issues
+- 发起讨论:https://github.com/jiangkai/microservice-helm/discussions
 
 ---
 
-更多帮助请查看[官方Helm文档](https://helm.sh/docs/)
+**最后更新:** 2026-01-15  
+**维护者:** DevOps Team

+ 6 - 0
charts/base/Chart.yaml

@@ -0,0 +1,6 @@
+apiVersion: v2
+name: base
+description: Base templates and utilities for microservices
+type: library
+version: 1.0.0
+appVersion: "1.0"

+ 13 - 0
charts/base/templates/configmap.yaml

@@ -0,0 +1,13 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ .Values.app.name }}-config
+  labels:
+    app: {{ .Values.app.name }}
+data:
+  application.properties: |
+    {{- range $key, $value := .Values.config.properties }}
+    {{ $key }}={{ $value }}
+    {{- end }}
+  application.yml: |
+    {{- .Values.config.yml | toYaml | nindent 4 }}

+ 71 - 0
charts/base/templates/deployment.yaml

@@ -0,0 +1,71 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Values.app.name }}
+  labels:
+    app: {{ .Values.app.name }}
+spec:
+  replicas: {{ .Values.app.replicaCount }}
+  selector:
+    matchLabels:
+      app: {{ .Values.app.name }}
+  template:
+    metadata:
+      labels:
+        app: {{ .Values.app.name }}
+      {{- with .Values.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+    spec:
+      {{- with .Values.securityContext }}
+      securityContext:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      containers:
+      - name: {{ .Values.app.name }}
+        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
+        imagePullPolicy: {{ .Values.image.pullPolicy }}
+        ports:
+        - name: http
+          containerPort: {{ .Values.service.targetPort }}
+          protocol: TCP
+        volumeMounts:
+        - name: config-volume
+          mountPath: /etc/config
+          readOnly: true
+        env:
+        - name: JAVA_OPTS
+          value: "-Xmx512m -Xms256m"
+        {{- with .Values.resources }}
+        resources:
+          {{- toYaml . | nindent 12 }}
+        {{- end }}
+        livenessProbe:
+          httpGet:
+            path: /actuator/health
+            port: http
+          initialDelaySeconds: 30
+          periodSeconds: 10
+        readinessProbe:
+          httpGet:
+            path: /actuator/health
+            port: http
+          initialDelaySeconds: 5
+          periodSeconds: 5
+      volumes:
+      - name: config-volume
+        configMap:
+          name: {{ .Values.app.name }}-config
+      {{- with .Values.nodeSelector }}
+      nodeSelector:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.affinity }}
+      affinity:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.tolerations }}
+      tolerations:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}

+ 15 - 0
charts/base/templates/service.yaml

@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Values.app.name }}
+  labels:
+    app: {{ .Values.app.name }}
+spec:
+  type: {{ .Values.service.type }}
+  ports:
+    - port: {{ .Values.service.port }}
+      targetPort: http
+      protocol: TCP
+      name: http
+  selector:
+    app: {{ .Values.app.name }}

+ 1 - 0
charts/base/values.yaml

@@ -0,0 +1 @@
+# Base chart - no values needed as it only contains templates

+ 6 - 0
charts/order-service/Chart.yaml

@@ -0,0 +1,6 @@
+apiVersion: v2
+name: order-service
+description: Order Service Microservice Helm Chart
+type: application
+version: 1.0.0
+appVersion: "1.0"

+ 1 - 0
charts/order-service/templates/configmap.yaml

@@ -0,0 +1 @@
+{{- include "base.configmap" . -}}

+ 1 - 0
charts/order-service/templates/deployment.yaml

@@ -0,0 +1 @@
+{{- include "base.deployment" . -}}

+ 1 - 0
charts/order-service/templates/service.yaml

@@ -0,0 +1 @@
+{{- include "base.service" . -}}

+ 45 - 0
charts/order-service/values.yaml

@@ -0,0 +1,45 @@
+app:
+  name: order-service
+  replicaCount: 1
+
+image:
+  repository: your-registry/order-service
+  tag: "1.0.0"
+  pullPolicy: IfNotPresent
+
+service:
+  type: ClusterIP
+  port: 8081
+  targetPort: 8081
+
+resources:
+  requests:
+    cpu: 250m
+    memory: 256Mi
+  limits:
+    cpu: 500m
+    memory: 512Mi
+
+config:
+  properties:
+    spring.application.name: order-service
+    spring.jpa.hibernate.ddl-auto: update
+    spring.datasource.url: jdbc:mysql://mysql-service:3306/orderdb
+    spring.datasource.username: root
+    spring.datasource.password: password
+    server.port: "8081"
+  yml:
+    logging:
+      level:
+        root: INFO
+    management:
+      endpoints:
+        web:
+          exposure:
+            include: health,info,metrics
+
+podAnnotations: {}
+securityContext: {}
+nodeSelector: {}
+tolerations: []
+affinity: {}

+ 6 - 0
charts/payment-service/Chart.yaml

@@ -0,0 +1,6 @@
+apiVersion: v2
+name: payment-service
+description: Payment Service Microservice Helm Chart
+type: application
+version: 1.0.0
+appVersion: "1.0"

+ 1 - 0
charts/payment-service/templates/configmap.yaml

@@ -0,0 +1 @@
+{{- include "base.configmap" . -}}

+ 1 - 0
charts/payment-service/templates/deployment.yaml

@@ -0,0 +1 @@
+{{- include "base.deployment" . -}}

+ 1 - 0
charts/payment-service/templates/service.yaml

@@ -0,0 +1 @@
+{{- include "base.service" . -}}

+ 45 - 0
charts/payment-service/values.yaml

@@ -0,0 +1,45 @@
+app:
+  name: payment-service
+  replicaCount: 1
+
+image:
+  repository: your-registry/payment-service
+  tag: "1.0.0"
+  pullPolicy: IfNotPresent
+
+service:
+  type: ClusterIP
+  port: 8082
+  targetPort: 8082
+
+resources:
+  requests:
+    cpu: 250m
+    memory: 256Mi
+  limits:
+    cpu: 500m
+    memory: 512Mi
+
+config:
+  properties:
+    spring.application.name: payment-service
+    spring.jpa.hibernate.ddl-auto: update
+    spring.datasource.url: jdbc:mysql://mysql-service:3306/paymentdb
+    spring.datasource.username: root
+    spring.datasource.password: password
+    server.port: "8082"
+  yml:
+    logging:
+      level:
+        root: INFO
+    management:
+      endpoints:
+        web:
+          exposure:
+            include: health,info,metrics
+
+podAnnotations: {}
+securityContext: {}
+nodeSelector: {}
+tolerations: []
+affinity: {}

+ 6 - 0
charts/user-service/Chart.yaml

@@ -0,0 +1,6 @@
+apiVersion: v2
+name: user-service
+description: User Service Microservice Helm Chart
+type: application
+version: 1.0.0
+appVersion: "1.0"

+ 1 - 0
charts/user-service/templates/configmap.yaml

@@ -0,0 +1 @@
+{{- include "base.configmap" . -}}

+ 1 - 0
charts/user-service/templates/deployment.yaml

@@ -0,0 +1 @@
+{{- include "base.deployment" . -}}

+ 1 - 0
charts/user-service/templates/service.yaml

@@ -0,0 +1 @@
+{{- include "base.service" . -}}

+ 45 - 0
charts/user-service/values.yaml

@@ -0,0 +1,45 @@
+app:
+  name: user-service
+  replicaCount: 1
+
+image:
+  repository: your-registry/user-service
+  tag: "1.0.0"
+  pullPolicy: IfNotPresent
+
+service:
+  type: ClusterIP
+  port: 8080
+  targetPort: 8080
+
+resources:
+  requests:
+    cpu: 250m
+    memory: 256Mi
+  limits:
+    cpu: 500m
+    memory: 512Mi
+
+config:
+  properties:
+    spring.application.name: user-service
+    spring.jpa.hibernate.ddl-auto: update
+    spring.datasource.url: jdbc:mysql://mysql-service:3306/userdb
+    spring.datasource.username: root
+    spring.datasource.password: password
+    server.port: "8080"
+  yml:
+    logging:
+      level:
+        root: INFO
+    management:
+      endpoints:
+        web:
+          exposure:
+            include: health,info,metrics
+
+podAnnotations: {}
+securityContext: {}
+nodeSelector: {}
+tolerations: []
+affinity: {}

+ 53 - 0
environments/dev-values.yaml

@@ -0,0 +1,53 @@
+# Development Environment Configuration
+# Override values for development environment
+
+global:
+  labels:
+    environment: development
+
+user-service:
+  enabled: true
+  app:
+    replicaCount: 1
+  image:
+    tag: dev-latest
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: create-drop
+      spring.datasource.url: jdbc:mysql://mysql-dev:3306/userdb
+    yml:
+      logging:
+        level:
+          root: DEBUG
+          com:
+            example: DEBUG
+
+order-service:
+  enabled: true
+  app:
+    replicaCount: 1
+  image:
+    tag: dev-latest
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: create-drop
+      spring.datasource.url: jdbc:mysql://mysql-dev:3306/orderdb
+    yml:
+      logging:
+        level:
+          root: DEBUG
+
+payment-service:
+  enabled: true
+  app:
+    replicaCount: 1
+  image:
+    tag: dev-latest
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: create-drop
+      spring.datasource.url: jdbc:mysql://mysql-dev:3306/paymentdb
+    yml:
+      logging:
+        level:
+          root: DEBUG

+ 87 - 0
environments/prod-values.yaml

@@ -0,0 +1,87 @@
+# Production Environment Configuration
+# Override values for production environment
+
+global:
+  labels:
+    environment: production
+
+user-service:
+  enabled: true
+  app:
+    replicaCount: 3
+  image:
+    tag: "1.0.0"  # Use specific version tags in production
+  resources:
+    requests:
+      cpu: 500m
+      memory: 512Mi
+    limits:
+      cpu: 1000m
+      memory: 1024Mi
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: validate
+      spring.datasource.url: jdbc:mysql://mysql-prod:3306/userdb
+    yml:
+      logging:
+        level:
+          root: WARN
+      management:
+        endpoints:
+          web:
+            exposure:
+              include: health,metrics
+
+order-service:
+  enabled: true
+  app:
+    replicaCount: 3
+  image:
+    tag: "1.0.0"
+  resources:
+    requests:
+      cpu: 500m
+      memory: 512Mi
+    limits:
+      cpu: 1000m
+      memory: 1024Mi
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: validate
+      spring.datasource.url: jdbc:mysql://mysql-prod:3306/orderdb
+    yml:
+      logging:
+        level:
+          root: WARN
+      management:
+        endpoints:
+          web:
+            exposure:
+              include: health,metrics
+
+payment-service:
+  enabled: true
+  app:
+    replicaCount: 3
+  image:
+    tag: "1.0.0"
+  resources:
+    requests:
+      cpu: 500m
+      memory: 512Mi
+    limits:
+      cpu: 1000m
+      memory: 1024Mi
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: validate
+      spring.datasource.url: jdbc:mysql://mysql-prod:3306/paymentdb
+    yml:
+      logging:
+        level:
+          root: WARN
+      management:
+        endpoints:
+          web:
+            exposure:
+              include: health,metrics

+ 51 - 0
environments/staging-values.yaml

@@ -0,0 +1,51 @@
+# Staging Environment Configuration
+# Override values for staging environment
+
+global:
+  labels:
+    environment: staging
+
+user-service:
+  enabled: true
+  app:
+    replicaCount: 2
+  image:
+    tag: staging-latest
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: validate
+      spring.datasource.url: jdbc:mysql://mysql-staging:3306/userdb
+    yml:
+      logging:
+        level:
+          root: INFO
+
+order-service:
+  enabled: true
+  app:
+    replicaCount: 2
+  image:
+    tag: staging-latest
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: validate
+      spring.datasource.url: jdbc:mysql://mysql-staging:3306/orderdb
+    yml:
+      logging:
+        level:
+          root: INFO
+
+payment-service:
+  enabled: true
+  app:
+    replicaCount: 2
+  image:
+    tag: staging-latest
+  config:
+    properties:
+      spring.jpa.hibernate.ddl-auto: validate
+      spring.datasource.url: jdbc:mysql://mysql-staging:3306/paymentdb
+    yml:
+      logging:
+        level:
+          root: INFO

+ 133 - 65
values.yaml

@@ -1,70 +1,138 @@
-# Default values for java-microservice
-# This is a YAML-formatted file with configuration values
+# Microservice Platform - Umbrella Chart Configuration
+# This file contains global configuration for all microservices
 
-# Application configuration
-app:
-  name: java-microservice
-  replicaCount: 1
+# Global configuration shared across all services
+global:
+  # Global image configuration
+  image:
+    registry: your-registry
+    pullPolicy: IfNotPresent
+  
+  # Global labels applied to all resources
+  labels:
+    platform: microservice-platform
+    version: "1.0"
+  
+  # Global annotations
+  annotations: {}
 
-# Docker image configuration
-image:
-  repository: your-registry/java-app
-  tag: "1.0.0"
-  pullPolicy: IfNotPresent
+# Base chart configuration (common templates and utilities)
+base:
+  enabled: true
 
-# Service configuration
-service:
-  type: ClusterIP
-  port: 8080
-  targetPort: 8080
+# User Service Configuration
+user-service:
+  enabled: true
+  app:
+    name: user-service
+    replicaCount: 1
+  image:
+    repository: your-registry/user-service
+    tag: "1.0.0"
+    pullPolicy: IfNotPresent
+  service:
+    type: ClusterIP
+    port: 8080
+    targetPort: 8080
+  resources:
+    requests:
+      cpu: 250m
+      memory: 256Mi
+    limits:
+      cpu: 500m
+      memory: 512Mi
+  config:
+    properties:
+      spring.application.name: user-service
+      spring.jpa.hibernate.ddl-auto: update
+      spring.datasource.url: jdbc:mysql://mysql-service:3306/userdb
+      spring.datasource.username: root
+      spring.datasource.password: password
+      server.port: "8080"
+    yml:
+      logging:
+        level:
+          root: INFO
+      management:
+        endpoints:
+          web:
+            exposure:
+              include: health,info,metrics
 
-# Application properties configuration
-config:
-  # application.properties variables
-  properties:
-    spring.application.name: java-microservice
-    spring.jpa.hibernate.ddl-auto: update
-    spring.datasource.url: jdbc:mysql://localhost:3306/mydb
-    spring.datasource.username: root
-    spring.datasource.password: password
-    server.port: "8080"
-    
-  # application.yml variables (as key-value pairs)
-  yml:
-    logging:
-      level:
-        root: INFO
-        com:
-          example: DEBUG
-    management:
-      endpoints:
-        web:
-          exposure:
-            include: health,info,metrics
-      endpoint:
-        health:
-          show-details: when-authorized
+# Order Service Configuration
+order-service:
+  enabled: true
+  app:
+    name: order-service
+    replicaCount: 1
+  image:
+    repository: your-registry/order-service
+    tag: "1.0.0"
+    pullPolicy: IfNotPresent
+  service:
+    type: ClusterIP
+    port: 8081
+    targetPort: 8081
+  resources:
+    requests:
+      cpu: 250m
+      memory: 256Mi
+    limits:
+      cpu: 500m
+      memory: 512Mi
+  config:
+    properties:
+      spring.application.name: order-service
+      spring.jpa.hibernate.ddl-auto: update
+      spring.datasource.url: jdbc:mysql://mysql-service:3306/orderdb
+      spring.datasource.username: root
+      spring.datasource.password: password
+      server.port: "8081"
+    yml:
+      logging:
+        level:
+          root: INFO
+      management:
+        endpoints:
+          web:
+            exposure:
+              include: health,info,metrics
 
-# Resources configuration
-resources:
-  limits:
-    cpu: 500m
-    memory: 512Mi
-  requests:
-    cpu: 250m
-    memory: 256Mi
-
-# Pod configuration
-podAnnotations: {}
-
-# Security context
-securityContext: {}
-
-# Node selector
-nodeSelector: {}
-
-# Tolerations
-tolerations: []
-
-# Affinity
-affinity: {}
+# Payment Service Configuration
+payment-service:
+  enabled: true
+  app:
+    name: payment-service
+    replicaCount: 1
+  image:
+    repository: your-registry/payment-service
+    tag: "1.0.0"
+    pullPolicy: IfNotPresent
+  service:
+    type: ClusterIP
+    port: 8082
+    targetPort: 8082
+  resources:
+    requests:
+      cpu: 250m
+      memory: 256Mi
+    limits:
+      cpu: 500m
+      memory: 512Mi
+  config:
+    properties:
+      spring.application.name: payment-service
+      spring.jpa.hibernate.ddl-auto: update
+      spring.datasource.url: jdbc:mysql://mysql-service:3306/paymentdb
+      spring.datasource.username: root
+      spring.datasource.password: password
+      server.port: "8082"
+    yml:
+      logging:
+        level:
+          root: INFO
+      management:
+        endpoints:
+          web:
+            exposure:
+              include: health,info,metrics