Template Functions
What you'll learn: How to use Helm's built-in functions to manipulate strings, convert types, set defaults, and add conditional logic in your chart templates.
Why Template Functions Matter
In Helm templates, raw values aren't always in the format you need. Template functions are like a Swiss Army knife—they transform, format, and control your template output. Think of them as mini-utilities that process data before it's inserted into your Kubernetes manifests.
Core Function Categories
String Manipulation
Functions like upper, lower, trim, and quote adjust text format. For example, converting a service name to uppercase or ensuring a value is properly quoted in YAML.
Type Conversion
Functions such as toString, toJson, and toYaml convert data between types. This is essential when you need to embed complex values structures or ensure integers are treated as strings where required.
Defaults and Fallbacks
The default function provides fallback values when a variable is empty or undefined. This prevents template errors and makes your charts more resilient.
Conditional Logic
Functions like ternary, eq, ne, and, and or enable decision-making within templates. You can output different values based on conditions without verbose if-else blocks.
How Functions Work
Functions use pipeline syntax: {{ .Values.name | upper | quote }}. The pipe (|) chains functions left-to-right, passing the result of each function to the next. This creates readable, composable transformations.
Key Takeaway: Helm's template functions transform raw values into properly formatted, conditional, and type-safe outputs, making your charts flexible and production-ready without complex scripting.