πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Helm beginner ⏱ 10 minutes K8s 1.28+

Helm Sprig cat Function: Concatenate Strings

Use the Helm Sprig cat function to concatenate strings in templates. Syntax, examples, conditionals, and common Kubernetes patterns.

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: The Sprig cat function concatenates multiple values into a single space-separated string: {{ cat "hello" "world" }} outputs hello world. It automatically converts non-string types to strings, making it ideal for building dynamic labels, annotations, and resource names in Helm templates.

The Problem

When writing Helm templates, you often need to combine multiple values β€” variables, defaults, and conditionals β€” into a single string for labels, annotations, or resource names. Standard Go template syntax for string concatenation is verbose (printf "%s-%s") and doesn’t handle type conversion. You need a simpler way to join values together.

The Solution

Basic Syntax

# cat joins values with spaces
{{ cat "hello" "world" }}
# Output: hello world

# Works with variables
{{ cat .Release.Name .Chart.Name }}
# Output: my-release my-chart

# Handles multiple arguments
{{ cat "app" .Release.Name "v1" }}
# Output: app my-release v1

Common Patterns in Kubernetes Manifests

Dynamic Labels

# templates/deployment.yaml
metadata:
  labels:
    app.kubernetes.io/name: {{ cat .Chart.Name | replace " " "-" }}
    app.kubernetes.io/instance: {{ cat .Release.Name "-" .Chart.Name | nospace }}

Conditional String Building

# Build annotation string conditionally
annotations:
  description: {{ cat "Managed by Helm" (ternary "in production" "in development" .Values.production) }}
  # Output: "Managed by Helm in production" or "Managed by Helm in development"

Combining with Other Functions

# cat + lower + replace for safe resource names
metadata:
  name: {{ cat .Release.Name .Values.component | lower | replace " " "-" | trunc 63 }}

# cat + quote for annotation values
annotations:
  config: {{ cat .Values.region .Values.zone | quote }}
  # Output: "us-east-1 us-east-1a"

cat vs printf vs Other String Functions

FunctionSyntaxOutputBest For
cat{{ cat "a" "b" }}a bSpace-separated joining
printf{{ printf "%s-%s" "a" "b" }}a-bCustom separators
join{{ list "a" "b" | join "-" }}a-bList joining with delimiter
nospace{{ cat "a" "b" | nospace }}abNo-space concatenation

Auto Type Conversion

cat automatically converts non-string types:

# Numbers to strings
{{ cat "replicas" .Values.replicaCount }}
# Output: "replicas 3"

# Booleans to strings
{{ cat "debug" .Values.debug }}
# Output: "debug true"

# Nested values
{{ cat "version" .Chart.AppVersion "build" .Values.buildNumber }}
# Output: "version 1.0.0 build 42"

Real-World Example: ConfigMap Generator

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-config
data:
  APP_NAME: {{ cat .Chart.Name .Values.env | quote }}
  APP_VERSION: {{ cat "v" .Chart.AppVersion | nospace | quote }}
  CLUSTER_INFO: {{ cat .Values.region .Values.zone .Values.cluster | quote }}
  LOG_PREFIX: {{ cat "[" .Release.Name "]" | nospace | quote }}

Common Issues

Extra Spaces in Output

cat adds spaces between arguments. To remove them:

# Problem: "my - release" (unwanted spaces around dash)
{{ cat .Release.Name "-" .Values.suffix }}

# Solution 1: nospace
{{ cat .Release.Name "-" .Values.suffix | nospace }}
# Output: "myrelease-mysuffix" (removes ALL spaces)

# Solution 2: printf for precise control
{{ printf "%s-%s" .Release.Name .Values.suffix }}
# Output: "myrelease-mysuffix"

Nil Values Cause Empty Segments

# If .Values.optional is nil:
{{ cat "prefix" .Values.optional "suffix" }}
# Output: "prefix  suffix" (double space)

# Fix: use default
{{ cat "prefix" (default "none" .Values.optional) "suffix" }}

Best Practices

  • Use cat for human-readable strings β€” annotations, descriptions, comments
  • Use printf for resource names β€” when you need exact formatting with dashes/dots
  • Pipe through quote β€” always quote annotation and label values: {{ cat ... | quote }}
  • Pipe through trunc 63 β€” Kubernetes names must be ≀63 chars
  • Combine with lower and replace β€” ensure DNS-safe resource names

Key Takeaways

  • cat concatenates values with spaces β€” simplest way to join strings in Helm
  • Automatically converts numbers, booleans, and other types to strings
  • Combine with nospace, lower, replace, trunc for Kubernetes-safe output
  • Use printf when you need custom separators (dashes, dots, slashes)
  • Always quote the output when used in YAML values
#helm #sprig #cat #string-functions #templates
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens