Share:
Twitter
LinkedIn
Facebook
Reddit
Whatsapp
Follow by Email
Reading Time: 3 minutes

Helm is a powerful tool for managing Kubernetes resources, simplifying the deployment and configuration of complex applications. When deploying or updating a Helm chart, commands like helm install and helm upgrade --install allow you to install or upgrade releases effortlessly. The --set command adds a layer of flexibility, enabling you to override default values in the values.yaml file directly through the command line.

This article breaks down how to use the --set flag effectively, its limitations, and when it’s better to opt for a values.yaml file. Whether you’re a Helm beginner or looking to sharpen your skills, you’ll find actionable insights and tips here.

What Is the --set Command?

The --set flag in Helm is a handy way to pass custom configuration values at runtime without editing the Helm chart’s values.yaml file. This can be especially useful for quick, one-off changes or environment-specific customizations.

Syntax Overview

Here’s the basic syntax for using the --set flag:

Similarly, you can use it with helm upgrade --install:

Example Usage

Let’s say you’re deploying a Helm chart for an application. Here’s a real-world example:

  • replicaCount is overridden to 3.
  • image.tag is set to 1.2.3.

This approach works well for straightforward, small-scale overrides. But how do you figure out which keys to override? Let’s dive in.

How to Identify Keys for the --set Command

The --set flag relies on knowing the structure of the values.yaml file in the Helm chart. This file acts as a blueprint for the chart’s default configuration.

1. Examine the values.yaml File

The values.yaml file is typically located in the root directory of the Helm chart. It defines the default configuration, including values like replica counts, resource limits, and container images.

For example, a simple values.yaml file might look like this:

If you want to override replicaCount, you can use:

To change the tag under image, use:

2. Use helm show values

If you don’t have direct access to the Helm chart, you can view its default configuration using the helm show values command:

This command outputs the structure and default values of the chart’s values.yaml file, giving you a reference for creating overrides.

3. Understand Nested Keys

Nested keys in the values.yaml file are represented using dot notation. For instance:

To override tag, you’d use:

This dot notation is crucial for targeting specific values.

Challenges and Limitations of the --set Command

While the --set command is convenient, it has some limitations and quirks. Understanding these will help you avoid common pitfalls.

Escaping Special Characters

If your values contain special characters like commas or periods, you need to escape them. For example:

Alternatively, use the --set-string flag to treat the value as a literal string:

Overriding Arrays

Arrays in the values.yaml file require careful handling. For instance:

To override the first array element:

Unfortunately, you cannot partially override arrays; you must supply the entire array.

Complex Nested Structures

Deeply nested configurations can become cumbersome to manage with --set. For example:

For such cases, creating a custom values.yaml file is often simpler and more maintainable.

Best Practices for Using --set

To maximize the efficiency of the --set command, consider these best practices:

Use --set for Simple Overrides

Stick to small, straightforward changes like:

  • Updating an image tag.
  • Changing a replica count.
  • Enabling or disabling a feature.

Opt for a Custom values.yaml File for Complex Configurations

For larger or more intricate changes, create a custom values.yaml file. Reference it with the -f flag:

This approach keeps your commands clean and configurations organized.

Combine Approaches

You can mix both methods. Use --set for temporary tweaks and a values.yaml file for stable configurations:

Version Control Your Configurations

Track your values.yaml files in version control. This enables better collaboration and ensures reproducibility across environments.

Should You Use --set or a values.yaml File?

The choice between --set and a values.yaml file depends on your use case. Here’s a quick comparison:

Criteria--setvalues.yaml
Best ForQuick, small changesLarge, reusable configurations
ReadabilityHard to read with many overridesClear and structured
Version ControlNot version-controlledEasy to version and share
Nested/Complex ValuesDifficult to manageSimplifies handling complex structures

Recommendation: Use --set for temporary, environment-specific changes. For anything reusable or complex, stick with a values.yaml file. This ensures better clarity, maintainability, and collaboration.

Conclusion

The --set command is a versatile tool in the Helm ecosystem, perfect for quick overrides and environment-specific tweaks. However, its limitations make it unsuitable for complex configurations. By understanding when and how to use --set alongside values.yaml files, you can streamline your workflows, reduce errors, and maintain a clean deployment process. Embrace the best of both worlds to unlock the full potential of Helm!

Share:
Twitter
LinkedIn
Facebook
Reddit
Whatsapp
Follow by Email
Categories: Kubernetes

Pixel Robots.

I’m Richard Hooper aka Pixel Robots. I started this blog in 2016 for a couple reasons. The first reason was basically just a place for me to store my step by step guides, troubleshooting guides and just plain ideas about being a sysadmin. The second reason was to share what I have learned and found out with other people like me. Hopefully, you can find something useful on the site.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *