How to override a multi-line string with --set in helm install command?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Technically, you can force multi-line content through Helm's --set, but it is usually the wrong tool. Shell escaping, Helm parsing, and YAML quoting all stack on top of one another, which makes multi-line values brittle and hard to debug.
The practical answer is usually: do not use plain --set for multi-line strings. Use --set-file or pass a small override file with -f instead.
Why --set Is a Poor Fit for Multi-Line Content
--set works best for small scalar overrides such as:
Once the value contains embedded newlines, indentation, or large text blobs, the command line becomes fragile. A shell may interpret newline escapes one way, Helm may parse them another way, and the final YAML may still not look the way your template expects.
That is why multi-line configuration data such as scripts, certificates, or large config blocks should usually come from a file.
Best Option: --set-file
If the chart value is supposed to contain the literal contents of a file, use --set-file:
If your template expects a multi-line string, render it with a block scalar:
This is the cleanest approach for real multi-line payloads because the shell only passes a file path, not the whole text blob.
Another Good Option: Use an Override Values File
For larger or more structured overrides, use -f with a dedicated values file:
Then install with:
This is often the most maintainable solution because the YAML stays readable and versionable.
If You Absolutely Must Stay on the Command Line
In Bash or Zsh, process substitution can help you avoid editing a physical file:
This still uses a values file conceptually, but it is generated inline for one command. It is much safer than trying to cram literal newline escapes into plain --set.
What About --set-string
--set-string is helpful when Helm would otherwise coerce a scalar value such as true, 123, or 001 into the wrong type. It does not solve the general readability and escaping problems of multi-line text.
So for multi-line content:
- '
--set-stringis usually not the main answer' - '
--set-fileis usually the best answer' - '
-fis the most maintainable answer for structured overrides'
Common Pitfalls
- Forcing a multi-line config block through plain
--setand then fighting shell escaping. - Forgetting that the shell may process backslashes and newlines before Helm even sees them.
- Using a template that does not preserve indentation correctly for YAML block scalars.
- Reaching for
--set-stringwhen the real problem is not type coercion but multi-line structure. - Treating a large config blob as an inline CLI override when it really belongs in a file.
Summary
- Plain
--setis not a good tool for overriding multi-line strings. - Prefer
--set-filewhen the value should come from a file's contents. - Prefer
-fwith a small override YAML file when the override is structured or long. - Use process substitution if you need a file-like override without creating a permanent file.
- The more text you are trying to pass, the more likely it is that a file-based approach is the correct one.
Related reading
- How to override Dockerfile's entrypoint /bin/sh from kubernetes job's deployment yml?
- How to override the Release.namespace for subcharts?
- How to parse kubectl describe output and get the required field value
- How to pass a certificate as a variable in values.yaml of helm chart
- How to pass data between two helm charts?
- how to pass environment variable in kubectl deployment?
- How to pass Docker CLI --gpus Options in Kubernetes or enable GPU support without installing nvidia-docker2 Docker 19.03
- How to pass docker run parameter via kubernetes pod

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.