helm-values

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Helm Values

Helm Values

Managing values files and configuration overrides in Helm.
在Helm中管理values文件和配置覆盖。

Values Hierarchy

Values 层级结构

Helm merges values from multiple sources (lower precedence first):
  1. Built-in default values
  2. Chart's
    values.yaml
  3. Parent chart's values
  4. Values files specified with
    -f
    (can be multiple)
  5. Individual parameters with
    --set
Helm会从多个来源合并values(优先级从低到高):
  1. 内置默认值
  2. Chart的
    values.yaml
  3. 父Chart的values
  4. 通过
    -f
    指定的values文件(可指定多个)
  5. 使用
    --set
    指定的单个参数

values.yaml Structure

values.yaml 结构

Organize by Resource

按资源组织

yaml
undefined
yaml
undefined

Global settings

Global settings

global: environment: production domain: example.com
global: environment: production domain: example.com

Application settings

Application settings

app: name: myapp version: "1.0.0"
app: name: myapp version: "1.0.0"

Image settings

Image settings

image: repository: myregistry/myapp pullPolicy: IfNotPresent tag: "" # Overrides appVersion
image: repository: myregistry/myapp pullPolicy: IfNotPresent tag: "" # Overrides appVersion

Service settings

Service settings

service: type: ClusterIP port: 80 targetPort: 8080
service: type: ClusterIP port: 80 targetPort: 8080

Ingress settings

Ingress settings

ingress: enabled: false className: nginx annotations: {} hosts: - host: myapp.example.com paths: - path: / pathType: Prefix tls: []
ingress: enabled: false className: nginx annotations: {} hosts: - host: myapp.example.com paths: - path: / pathType: Prefix tls: []

Resources

Resources

resources: limits: cpu: 500m memory: 512Mi requests: cpu: 250m memory: 256Mi
resources: limits: cpu: 500m memory: 512Mi requests: cpu: 250m memory: 256Mi

Persistence

Persistence

persistence: enabled: false storageClass: "" accessMode: ReadWriteOnce size: 8Gi
undefined
persistence: enabled: false storageClass: "" accessMode: ReadWriteOnce size: 8Gi
undefined

Override Strategies

覆盖策略

Override with File

使用文件覆盖

bash
undefined
bash
undefined

Single file

Single file

helm install myrelease ./mychart -f custom-values.yaml
helm install myrelease ./mychart -f custom-values.yaml

Multiple files (later files override earlier)

Multiple files (later files override earlier)

helm install myrelease ./mychart
-f values-base.yaml
-f values-production.yaml
undefined
helm install myrelease ./mychart
-f values-base.yaml
-f values-production.yaml
undefined

Override with --set

使用--set覆盖

bash
undefined
bash
undefined

Single value

Single value

helm install myrelease ./mychart --set image.tag=2.0.0
helm install myrelease ./mychart --set image.tag=2.0.0

Multiple values

Multiple values

helm install myrelease ./mychart
--set image.tag=2.0.0
--set replicaCount=5
helm install myrelease ./mychart
--set image.tag=2.0.0
--set replicaCount=5

Nested values

Nested values

helm install myrelease ./mychart
--set ingress.enabled=true
--set ingress.hosts[0].host=myapp.com
undefined
helm install myrelease ./mychart
--set ingress.enabled=true
--set ingress.hosts[0].host=myapp.com
undefined

Override with --set-string

使用--set-string覆盖

bash
undefined
bash
undefined

Force string type (useful for numeric-looking strings)

Force string type (useful for numeric-looking strings)

helm install myrelease ./mychart
--set-string version="1.0"
undefined
helm install myrelease ./mychart
--set-string version="1.0"
undefined

Override with --set-file

使用--set-file覆盖

bash
undefined
bash
undefined

Read value from file

Read value from file

helm install myrelease ./mychart
--set-file config=./config.json
undefined
helm install myrelease ./mychart
--set-file config=./config.json
undefined

Environment-Specific Values

环境专属Values

values-development.yaml

values-development.yaml

yaml
replicaCount: 1

image:
  tag: "dev-latest"
  pullPolicy: Always

resources:
  limits:
    cpu: 200m
    memory: 256Mi

ingress:
  enabled: true
  hosts:
    - host: dev.myapp.com

postgresql:
  enabled: true
yaml
replicaCount: 1

image:
  tag: "dev-latest"
  pullPolicy: Always

resources:
  limits:
    cpu: 200m
    memory: 256Mi

ingress:
  enabled: true
  hosts:
    - host: dev.myapp.com

postgresql:
  enabled: true

values-production.yaml

values-production.yaml

yaml
replicaCount: 5

image:
  tag: "1.0.0"
  pullPolicy: IfNotPresent

resources:
  limits:
    cpu: 1000m
    memory: 1Gi

ingress:
  enabled: true
  hosts:
    - host: myapp.com
  tls:
    - secretName: myapp-tls
      hosts:
        - myapp.com

postgresql:
  enabled: false
  external:
    host: prod-db.example.com
yaml
replicaCount: 5

image:
  tag: "1.0.0"
  pullPolicy: IfNotPresent

resources:
  limits:
    cpu: 1000m
    memory: 1Gi

ingress:
  enabled: true
  hosts:
    - host: myapp.com
  tls:
    - secretName: myapp-tls
      hosts:
        - myapp.com

postgresql:
  enabled: false
  external:
    host: prod-db.example.com

Global Values

全局Values

Parent Chart values.yaml

父Chart的values.yaml

yaml
global:
  environment: production
  storageClass: fast-ssd

  postgresql:
    auth:
      existingSecret: db-credentials
yaml
global:
  environment: production
  storageClass: fast-ssd

  postgresql:
    auth:
      existingSecret: db-credentials

Subchart Access

子Chart访问

yaml
undefined
yaml
undefined

In subchart template

In subchart template

environment: {{ .Values.global.environment }}
undefined
environment: {{ .Values.global.environment }}
undefined

Schema Validation

Schema 验证

values.schema.json

values.schema.json

json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["image"],
  "properties": {
    "replicaCount": {
      "type": "integer",
      "minimum": 1,
      "maximum": 10
    },
    "image": {
      "type": "object",
      "required": ["repository"],
      "properties": {
        "repository": {
          "type": "string"
        },
        "tag": {
          "type": "string"
        },
        "pullPolicy": {
          "type": "string",
          "enum": ["Always", "IfNotPresent", "Never"]
        }
      }
    },
    "service": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["ClusterIP", "NodePort", "LoadBalancer"]
        },
        "port": {
          "type": "integer",
          "minimum": 1,
          "maximum": 65535
        }
      }
    }
  }
}
json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["image"],
  "properties": {
    "replicaCount": {
      "type": "integer",
      "minimum": 1,
      "maximum": 10
    },
    "image": {
      "type": "object",
      "required": ["repository"],
      "properties": {
        "repository": {
          "type": "string"
        },
        "tag": {
          "type": "string"
        },
        "pullPolicy": {
          "type": "string",
          "enum": ["Always", "IfNotPresent", "Never"]
        }
      }
    },
    "service": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["ClusterIP", "NodePort", "LoadBalancer"]
        },
        "port": {
          "type": "integer",
          "minimum": 1,
          "maximum": 65535
        }
      }
    }
  }
}

Secrets in Values

Values中的密钥

Don't Commit Secrets

不要提交密钥

yaml
undefined
yaml
undefined

values.yaml - public defaults

values.yaml - public defaults

database: host: "" username: "" password: ""
database: host: "" username: "" password: ""

values-secrets.yaml - not in git

values-secrets.yaml - not in git

database: host: "prod-db.example.com" username: "dbuser" password: "super-secret"
undefined
database: host: "prod-db.example.com" username: "dbuser" password: "super-secret"
undefined

Use External Secrets

使用外部密钥

yaml
undefined
yaml
undefined

values.yaml

values.yaml

database: useExistingSecret: true existingSecretName: db-credentials

```yaml
database: useExistingSecret: true existingSecretName: db-credentials

```yaml

In template

In template

{{- if .Values.database.useExistingSecret }} secretKeyRef: name: {{ .Values.database.existingSecretName }} key: password {{- else }} value: {{ .Values.database.password | quote }} {{- end }}
undefined
{{- if .Values.database.useExistingSecret }} secretKeyRef: name: {{ .Values.database.existingSecretName }} key: password {{- else }} value: {{ .Values.database.password | quote }} {{- end }}
undefined

Complex Value Structures

复杂值结构

Lists

列表

yaml
undefined
yaml
undefined

values.yaml

values.yaml

extraEnvVars:
  • name: LOG_LEVEL value: info
  • name: API_KEY valueFrom: secretKeyRef: name: api-secret key: key

```yaml
extraEnvVars:
  • name: LOG_LEVEL value: info
  • name: API_KEY valueFrom: secretKeyRef: name: api-secret key: key

```yaml

template

template

{{- range .Values.extraEnvVars }}
  • name: {{ .name }} {{- if .value }} value: {{ .value | quote }} {{- else if .valueFrom }} valueFrom: {{- toYaml .valueFrom | nindent 4 }} {{- end }} {{- end }}
undefined
{{- range .Values.extraEnvVars }}
  • name: {{ .name }} {{- if .value }} value: {{ .value | quote }} {{- else if .valueFrom }} valueFrom: {{- toYaml .valueFrom | nindent 4 }} {{- end }} {{- end }}
undefined

Maps

映射

yaml
undefined
yaml
undefined

values.yaml

values.yaml

annotations: prometheus.io/scrape: "true" prometheus.io/port: "9090"
labels: team: platform environment: production

```yaml
annotations: prometheus.io/scrape: "true" prometheus.io/port: "9090"
labels: team: platform environment: production

```yaml

template

template

annotations: {{- range $key, $value := .Values.annotations }} {{ $key }}: {{ $value | quote }} {{- end }}
undefined
annotations: {{- range $key, $value := .Values.annotations }} {{ $key }}: {{ $value | quote }} {{- end }}
undefined

Best Practices

最佳实践

Document Values

为Values添加文档

yaml
undefined
yaml
undefined

values.yaml with comments

values.yaml with comments

Number of replicas

Number of replicas

@param replicaCount - Number of pod replicas

@param replicaCount - Number of pod replicas

replicaCount: 3
replicaCount: 3

Image configuration

Image configuration

@param image.repository - Docker image repository

@param image.repository - Docker image repository

@param image.tag - Docker image tag (defaults to Chart appVersion)

@param image.tag - Docker image tag (defaults to Chart appVersion)

image: repository: myapp tag: ""
undefined
image: repository: myapp tag: ""
undefined

Sensible Defaults

合理的默认值

yaml
undefined
yaml
undefined

Provide production-ready defaults

Provide production-ready defaults

replicaCount: 3 # Not 1
resources: limits: cpu: 500m memory: 512Mi requests: cpu: 500m # Same as limit for guaranteed QoS memory: 512Mi
undefined
replicaCount: 3 # Not 1
resources: limits: cpu: 500m memory: 512Mi requests: cpu: 500m # Same as limit for guaranteed QoS memory: 512Mi
undefined

Feature Flags

功能开关

yaml
undefined
yaml
undefined

Allow enabling/disabling features

Allow enabling/disabling features

features: metrics: enabled: true port: 9090
tracing: enabled: false endpoint: ""
undefined
features: metrics: enabled: true port: 9090
tracing: enabled: false endpoint: ""
undefined

View Computed Values

查看计算后的值

bash
undefined
bash
undefined

See final merged values

See final merged values

helm get values myrelease
helm get values myrelease

See all values (including defaults)

See all values (including defaults)

helm get values myrelease --all
helm get values myrelease --all

Template with values

Template with values

helm template myrelease ./mychart -f custom-values.yaml
undefined
helm template myrelease ./mychart -f custom-values.yaml
undefined