Edit on GitHub

Using Helm with Tilt

Tilt supports Helm out-of-the-box.

There are two ways you can use Helm charts with Tilt.

Basic Helm

If you have a local Helm chart and want to deploy it as-is, add a helm() call to your Tiltfile:

k8s_yaml(helm('path/to/chart/dir'))

The helm function runs helm template on a chart directory and returns the generated yaml.

When you make edits to the files in the chart directory, Tilt will automatically re-deploy the chart.

Advanced Helm

Helm can also do more advanced templating – like downloading remote charts and injecting run-time variables.

Fortunately, Tilt has a plugin API. You can tell it how to shell out to other build and deploy tools.

The plugin API has two important functions:

  • local() for running local shell commands

  • watch_file() for telling Tilt to reload its configuration when a file changes

Let’s take a look at some common recipes for using the plugin API with Helm.

Example Repo

If you prefer to play with a code sample, see

windmilleng/tilt-helm-demo

Re-implementing the helm() built-in

To start, let’s try implementing the helm() built-in ourselves.

k8s_yaml(local('helm template path/to/chart/dir'))
watch_file('path/to/chart/dir')

The real helm() built-in handles some extra optimizations and edge cases, but that’s basically all it does!

Passing a single variable

Now that we know how to shell out to helm, we can pass arbitrary flags. Let’s try using --set to set a variable.

k8s_yaml(local('helm template --set key1=val1,key2=val2 path/to/chart/dir'))
watch_file('path/to/chart/dir')

Passing a values file

If you’re passing a lot of variables, it’s usually better to put those in a values.yaml file.

k8s_yaml(local('helm template -f ./values.yaml path/to/chart/dir'))
watch_file('path/to/chart/dir')
watch_file('values.yaml')

Deploying a remote Helm chart

One of the advantages of Helm is that there’s a rich library of existing charts.

Suppose you want to ensure Redis is installed in your dev environment. You can add this line to your Tiltfile:

local("helm upgrade --install redis-dev stable/redis")

This fetches the remote Redis chart and deploys it to your cluster.

But maybe you want to tweak the existing chart a bit. Then you might use local() to call helm fetch:

fetch_script = "helm fetch stable/myProject --untar --untardir ./deploy/helm/"
template_script = "helm template ./deploy/helm/myProject --namespace {} --name {} -f ./deploy/helm/myProject/values.yaml".format(namespace, release_name)
k8s_yaml(local(fetch_script + " && " + template_script))

Other Helm tools

There are other helm tools like helmfile for working with Helm charts.

We can use the same plugin commands to implement those as well. In this example, we factor out helmfile into a helper function.

# Helper function to read K8s config YAML from helmfile.
#
# Currently `helmfile template` has a bug where it prints messages to stdout instead of stderr
# https://github.com/roboll/helmfile/issues/551
# So we use the workaround suggested there.
def helmfile(file):
  watch_file(file)
  return local("helmfile -f %s template | grep -v -e '^Decrypting .*' | grep -v -e '^Fetching .*' | grep -v 'as it is not a table.$'" % file)

# Tell Tilt to apply to k8s config generated by helmfile.
k8s_yaml(helmfile("k8s/staging/helmfile.yaml"))

You can try out this example yourself in this example repo.

Further customization

If you have a Helm use-case that’s not covered here, we’d love to hear about it!

You can file an issue on GitHub.

We’re also active on the Kubernetes slack in the #tilt channel. Get an invite at slack.k8s.io.