Kubernetes
Helm Charts
Variables
Forward Slash
Kubernetes Deployment

How to use variables with forward slash in kubernetes chart?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

In Helm charts, forward slashes are usually harmless when they appear inside a string value such as an image path or URL. The real complication appears when the slash is part of a map key, which is common for annotations like cert-manager.io/cluster-issuer or nginx.ingress.kubernetes.io/rewrite-target.

Slash in a value is usually easy

If the slash is part of the string itself, keep the value quoted in values.yaml and use it normally in the template.

yaml
1image:
2  repository: "ghcr.io/acme/api"
3api:
4  baseUrl: "https://service.example.com/v1"
yaml
1containers:
2  - name: api
3    image: {{ .Values.image.repository | quote }}
4    env:
5      - name: API_BASE_URL
6        value: {{ .Values.api.baseUrl | quote }}

This works because the slash is just part of the string value, not part of the template lookup path.

Slash in a key needs index

Dot notation is convenient only for simple keys. Once the key contains slashes or dots, use index instead of chained field access.

yaml
1ingress:
2  annotations:
3    cert-manager.io/cluster-issuer: "letsencrypt-prod"
4    nginx.ingress.kubernetes.io/rewrite-target: "/"

Template access:

yaml
1metadata:
2  annotations:
3    cert-manager.io/cluster-issuer: {{ index .Values.ingress.annotations "cert-manager.io/cluster-issuer" | quote }}
4    nginx.ingress.kubernetes.io/rewrite-target: {{ index .Values.ingress.annotations "nginx.ingress.kubernetes.io/rewrite-target" | quote }}

This is the safe pattern because index treats the whole key as one literal string.

Rendering the whole map is often cleaner

If you do not need to manipulate each annotation individually, render the whole annotations map instead of pulling out one key at a time:

yaml
1metadata:
2  annotations:
3{{- with .Values.ingress.annotations }}
4{{ toYaml . | nindent 4 }}
5{{- end }}

This avoids duplicated template logic and is often the cleanest solution for user-supplied annotation blocks.

Helm CLI and escaping rules

Things become trickier when setting these values from the command line. In --set, dots in keys are path separators, so they need escaping. Slashes are not the main problem, but the full key often contains both dots and slashes.

Example:

bash
helm upgrade myapp ./chart \
  --set-string ingress.annotations."cert-manager\.io/cluster-issuer"=letsencrypt-prod

This is one reason many teams prefer values files over large --set commands for annotations.

A values file is easier to read and much easier to review:

yaml
ingress:
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"

Then apply it with:

bash
helm upgrade myapp ./chart -f values-prod.yaml

Validating the rendered manifest

Always render the chart before applying it to a cluster:

bash
helm lint ./chart
helm template myapp ./chart -f values.yaml

If a key lookup is wrong, the rendered output usually makes the mistake obvious. This is especially helpful when you are mixing literal keys, default values, and environment-specific overrides.

Common Pitfalls

The most common mistake is trying to access a key with slash or dot using regular dot notation. That works for simple keys, but it breaks as soon as the key stops looking like a normal identifier.

Another issue is overusing --set for complex maps. Once annotation keys include dots, slashes, and quoted strings, the command becomes fragile and hard to maintain.

Be careful not to duplicate entries by mixing manual annotation lines with toYaml rendering of the same map. Kubernetes keeps only one value per key, so duplicate output creates confusion.

Finally, quote string values consistently. YAML coercion can turn values into booleans or numbers if you are careless, which is especially annoying when the original value came from a chart variable.

Summary

  • Slashes inside values are usually not a Helm problem.
  • Slashes inside keys should be accessed with index.
  • Rendering the whole map with toYaml is often simpler than extracting each key manually.
  • CLI overrides become awkward for dotted annotation keys, so values files are often better.
  • Use helm lint and helm template to catch key and rendering mistakes before deployment.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.