Working with Values Files
1. Creating values.yaml Default Values
| Property | Default Value | Description |
|---|---|---|
| replicaCount | 1 |
Number of replicas for the deployment |
| image.repository | nginx |
Container image repository name |
| image.tag | latest |
Container image tag |
| service.type | ClusterIP |
Kubernetes service type to expose the application |
| service.port | 80 |
Port to expose the service on |
| resources.limits.cpu | 500m |
CPU limit for the container |
| resources.limits.memory | 512Mi |
Memory limit for the container |
Example: Default values.yaml
replicaCount: 1
image:
repository: nginx
tag: latest
service:
type: ClusterIP
port: 80
resources:
limits:
cpu: 500m
memory: 512Mi
2. Understanding Values Hierarchy
| Level | File | Description |
|---|---|---|
| 1 | values.yaml |
Default values provided by the chart author |
| 2 | values.yaml in chart |
Override values within the chart's own values.yaml |
| 3 | values.yaml from --set |
Command-line overrides using --set flag |
| 4 | values.yaml from --set-string |
Command-line overrides for string values using --set-string |
| 5 | values.yaml from --set-file |
Command-line overrides using file content with --set-file |
| 6 | values.yaml from -f |
Override values using additional -f files (e.g., -f prod.yaml) |
| 7 | values.yaml from --values |
Override values using additional --values files (e.g., --values staging.yaml) |
Example: Values Hierarchy in Action
# Default values from chart
replicaCount: 1
image:
repository: nginx
tag: "latest"
pullPolicy: IfNotPresent
# Override in --set
--set image.tag="v1.23"
# Override via -f prod.yaml
image:
tag: "production-v1"
Note: The order of precedence is defined in the Helm documentation. Values from
--set and -f files override default values in the chart.
3. Using Custom Values Files
| Property | Values | Description |
|---|---|---|
| values.yaml | config: { port: 8080 } |
Default values file for chart configuration |
| --set | key=value |
Override values from command line |
| --values | custom-values.yaml |
Specify custom values file path |
4. Setting Individual Values
| Property | Value | Description |
|---|---|---|
| helm install --set key1=value1,key2=value2 | helm install my-release my-chart --set database.port=5432,database.username=admin |
Set individual values during installation using comma-separated key-value pairs |
| helm upgrade --set key1=value1 | helm upgrade my-release my-chart --set image.tag=v2.0 |
Update a release with new individual values |
| helm template --set key1=value1 | helm template my-release my-chart --set service.type=LoadBalancer |
Render templates with individual values without installing |
Example: Setting multiple values at once
helm install my-app stable/nginx --set image.tag=v2.0,image.pullPolicy=Always
5. Using String Values
| Property | Value Type | Description |
|---|---|---|
| app.name | string |
Name of the application |
| app.version | string |
Version of the application |
| app.image | string |
Docker image name and tag |
6. Setting File Content Values
| Property | Values | Description |
|---|---|---|
| configMap.data | string |
Data to be stored in the ConfigMap |
| configMap.binaryData | string |
Binary data to be stored in the ConfigMap |
| secret.data | string |
Data to be stored in the Secret |
| secret.stringData | string |
Unencoded string data to be stored in the Secret |
Example: Setting File Content in ConfigMap
configMap:
name: "app-config"
data:
app.properties: |
server.port=8080
logging.level=INFO
Example: Setting File Content in Secret
secret:
name: "app-secret"
stringData:
database.password: "secret123"
7. Setting JSON Values
| Property | Value | Description |
|---|---|---|
| jsonValue | {"key": "value"} |
Direct JSON object value |
| nested.json.key | "string" |
String value within nested JSON structure |
Note: JSON values in Helm are handled as YAML, so nested structures can be defined using standard YAML syntax.
8. Merging Multiple Values Files
Example: Merging values files
# values-dev.yaml
replicaCount: 2
image:
repository: nginx
tag: "1.21"
service:
type: ClusterIP
port: 80
# values-prod.yaml
replicaCount: 10
image:
tag: "1.22"
service:
type: LoadBalancer
port: 8080
nodePort: 30080
# Merged result (prod overrides dev)
replicaCount: 10
image:
repository: nginx
tag: "1.22"
service:
type: LoadBalancer
port: 8080
nodePort: 30080
| File | Merge Priority | Description |
|---|---|---|
| values.yaml | lowest |
Default values file, merged first |
| values-<env>.yaml | higher |
Environment-specific overrides |
| --set | highest |
Command-line overrides (highest priority) |
Note: Helm merges values files in the order they are specified, with later files taking precedence.
Workflow: Merging multiple values files
- Define base
values.yamlwith default settings - Create environment-specific files like
values-staging.yaml,values-prod.yaml - Use
helm install --values values-prod.yamlto merge files - Override with
--set key=valuefor last-minute changes
9. Creating Environment-Specific Values
Environment-specific values files allow you to customize Helm chart deployments for different environments like development, staging, and production.
| File Name Pattern | Description | Usage |
|---|---|---|
| values-dev.yaml | Values for the development environment | Used with helm install --values values-dev.yaml |
| values-staging.yaml | Values for the staging environment | Used with helm install --values values-staging.yaml |
| values-prod.yaml | Values for the production environment | Used with helm install --values values-prod.yaml |
Example: values-dev.yaml
replicaCount: 1
image:
repository: myapp
tag: "latest"
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 250m
memory: 256Mi
Example: values-prod.yaml
replicaCount: 3
image:
repository: myapp
tag: "v1.2.3"
pullPolicy: Always
service:
type: LoadBalancer
port: 80
resources:
limits:
cpu: 1000m
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
Note: Values files support YAML syntax and can be used to override any chart values. They are merged in order of precedence: default values < values file < --set overrides.
10. Documenting Values
Example: Using Comments in Values Files
# Helm Values File with Documentation
#
# Database Configuration
database:
# The hostname of the database server
host: "localhost"
# The port to connect to the database
port: 5432
# The name of the database to connect to
name: "myapp"
# The username for database authentication
username: "admin"
# The password for database authentication (use secrets in production)
password: "secret123"
# Service Configuration
service:
# The port to expose the service on
port: 8080
# The type of service to create (ClusterIP, NodePort, etc.)
type: "ClusterIP"
| Field | Description | Type | Default Value |
|---|---|---|---|
| database.host | Hostname of the database server | string | "localhost" |
| database.port | Port to connect to the database | integer | 5432 |
| database.name | Name of the database to connect to | string | "myapp" |
| database.username | Username for database authentication | string | "admin" |
| database.password | Password for database authentication | string | "secret123" |
| service.port | Port to expose the service on | integer | 8080 |
| service.type | Type of service to create (e.g., ClusterIP, NodePort) | string | "ClusterIP" |
Note: Comments in YAML files are not preserved when values are processed by Helm. For documentation purposes, consider using a separate README.md file or inline comments in templates.
11. Using Global Values
| Property | Description | Usage |
|---|---|---|
| global.imageRegistry | Registry to use for all images in the chart | global.imageRegistry: "my-registry.com" |
| global.replicaCount | Number of replicas for all deployments | global.replicaCount: 3 |
| global.storageClass | Storage class to use for persistent volumes | global.storageClass: "fast" |
Example: Setting global values in values.yaml
global:
imageRegistry: "my-registry.com"
replicaCount: 3
storageClass: "fast"
# Chart can reference these values using .Values.global.imageRegistry
Note: Global values are merged into the chart's values during template rendering and can be overridden at the chart level.