Customizing a Helm chart allows us to tailor the deployment of a solution in K8s to our specific needs. We can override the default settings of a chart using values, either by specifying them directly via the command line, using a custom
values.yaml
file, or a combination of both.Using the command line or the values.yaml file depends on how much customization we need for our Chart. We could differentiate two types of chart customizations: basic or advanced.
Basic Customization
If we need to override just a few parameters, especially simple values like setting a replica count or changing a service type, the--set
flag in the command line is much more convenient.For example, if we just need to modify the number of replicas for an NGINX chart, we could just install the chart with the command:
helm install my-nginx bitnami/nginx --set replicaCount=3
Also, If we’re using automation tools or scripts to deploy Helm charts, the
--set
flag can be very handy for dynamic values that might change based on the environment (e.g., different values for development, staging, production). Example:helm install my-app bitnami/nginx --set image.tag=$IMAGE_TAG
helm install my-app bitnami/nginx -f my-values.yaml --set replicaCount=5
Advanced Customization
If we need deeper customization, we might edit the chart’s templates. This is more advanced and requires understanding Helm’s templating language.
When the installation of our chart requires changing a lot of parameters or the changes required are more complex, then using the values.yaml file seems a better approach.
Firstly, for simplicity. For configurations that involve deeply nested structures, using the
--set
flag can become cumbersome and error-prone. In addition, using long and hard-to-read command lines is not something I’d recommend if we’re working on a team on the same installations.For example, we could use our own values.yaml file for cutomizing multiple values in an NGINX chart
# my-values.yaml file
replicaCount: 2
service:
type: NodePort
nodePort: 30080
ingress:
enabled: true
hostname: my-nginx.local
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi
helm install my-nginx bitnami/nginx -f my-values.yaml
values.yaml
file is ideal when we want to reuse the configuration across different environments or teams. It can be version-controlled, making it easy to track changes over time. We can create different values.yaml
files for different environments (e.g., values-prod.yaml
, values-dev.yaml
).For example:
helm install my-app bitnami/nginx -f values-prod.yaml
values.yaml
file helps maintain that consistency.Combining both
There will be also situations in which we put all the customizations we need for our chart in our values.yaml file but, eventually, we just need to change one or two parameters. In those cases, we can just combine--set
with a values.yaml
file for more flexibility. For example, we can run the following to use our own values.yaml file and change the number of replicas with one parameter in the —set flag:helm install my-nginx bitnami/nginx -f my-values.yaml —set replicaCount=4
In a nutshell...
- Use
--set
for simplicity: Quick and simple overrides, or when testing. - Use
values.yaml
for maintainability: Complex, reusable configurations, or when working in teams. - Combine both for flexibility: When you have a base
values.yaml
and need to override just a few specific settings dynamically.