You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于base-microservice父Chart创建customapp子Chart的Helm配置咨询

Alright, let's walk through setting up your customapp Chart that inherits from the base-microservice parent Chart, including dependency configuration, template overrides, and values customization.

1. Create the Target Directory Structure

First, build out the directory structure exactly as you specified. You can use these commands to scaffold it quickly:

mkdir -p customapp-service/customapp/{charts,templates,src}
touch customapp-service/customapp/{Chart.yaml,requirements.yaml,values.yaml}

The final structure will look like this:

customapp-service
└── customapp
    ├── Chart.yaml
    ├── charts
    ├── requirements.yaml
    ├── values.yaml
    ├── src          # For app code, custom helper scripts, or extra templates
    └── templates    # For overriding parent Chart templates (optional)

Update the requirements.yaml to declare a dependency on your base-microservice Chart. This tells Helm where to pull the parent Chart from:

# customapp/requirements.yaml
dependencies:
  - name: base-microservice
    version: "0.1.0"
    repository: "https://mycompany.github.com/pages/base-microservice"

Alternatively, for Helm 3+, you can define dependencies directly in Chart.yaml (this replaces requirements.yaml in newer versions):

# customapp/Chart.yaml
apiVersion: v2
name: customapp
description: A custom microservice inheriting from base-microservice
version: 0.1.0
dependencies:
  - name: base-microservice
    version: "0.1.0"
    repository: "https://mycompany.github.com/pages/base-microservice"

After setting up dependencies, run helm dependency build to pull the parent Chart into the charts directory.

3. Override Parent Chart Values

To customize the parent Chart's default configuration, update your customapp/values.yaml with the values you want to override. Use the parent Chart's name as a top-level key to target its values:

# customapp/values.yaml
# Override base-microservice's default values
base-microservice:
  # Example: Override deployment replica count
  replicaCount: 3
  # Example: Update service port
  service:
    port: 8080
  # Example: Customize ingress host
  ingress:
    hosts:
      - host: customapp.mycompany.com
        paths: ["/"]

# Add custom values specific to customapp (if needed)
customapp:
  image:
    repository: mycompany/customapp
    tag: v1.0.0

Helm will merge these values with the parent Chart's values.yaml, with your overrides taking precedence.

4. Override Parent Chart Templates

If you need to modify the parent Chart's templates (like deployment.yaml, service.yaml, etc.), create a 同名模板文件 in customapp/templates/. Helm will prioritize the child Chart's template over the parent's when rendering.

For example, to override the parent's deployment.yaml:

# customapp/templates/deployment.yaml
# Start with the parent's template content, then modify as needed
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "base-microservice.fullname" . }}
  labels:
    {{- include "base-microservice.labels" . | nindent 4 }}
    # Add custom label for customapp
    app.kubernetes.io/component: customapp
spec:
  replicas: {{ .Values.base-microservice.replicaCount }}
  selector:
    matchLabels:
      {{- include "base-microservice.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "base-microservice.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: customapp
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          # Use customapp's image instead of parent's default
          image: "{{ .Values.customapp.image.repository }}:{{ .Values.customapp.image.tag }}"
          imagePullPolicy: {{ .Values.imagePullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.base-microservice.service.port }}
              protocol: TCP
          # Add custom liveness/readiness probes for customapp
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 10
            periodSeconds: 5
          readinessProbe:
            httpGet:
              path: /readyz
              port: http
            initialDelaySeconds: 5
            periodSeconds: 3
          {{- with .Values.resources }}
          resources:
            {{- toYaml . | nindent 12 }}
          {{- end }}

This way, you retain the parent Chart's base structure but inject customizations specific to customapp.

5. Using the src Directory

The src directory can be used for:

  • Custom application code (if you're packaging the app with the Chart)
  • Helper scripts (e.g., pre-install/post-upgrade hooks)
  • Additional template fragments that don't override parent templates (you can include these in your custom templates using {{ include "customapp.my-helper" . }})

内容的提问来源于stack exchange,提问作者hackmabrain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:22:54