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.
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.
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.
Template access:
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:
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:
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:
Then apply it with:
Validating the rendered manifest
Always render the chart before applying it to a cluster:
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
toYamlis often simpler than extracting each key manually. - CLI overrides become awkward for dotted annotation keys, so values files are often better.
- Use
helm lintandhelm templateto catch key and rendering mistakes before deployment.
Related reading
- How to verify cluster network policy configuration/support
- How to verify Kubernetes service account token JWT
- How to view logs of failed jobs with kubectl?
- How to view the permissions/roles associated with a specific service account in k8s?
- How to view all the services running on AWS?
- how to view aws log real time like tail -f
- How to write a chart for imagePullSecret from gcr
- How to write a kubernetes pod configuration to start two containers

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.