15
Docker Compose Alternatives for Kubernetes: Tilt
Many engineers developing apps that run in Kubernetes use Docker Compose for their local environment, but a lot of great alternatives are out there that make developing against a Kubernetes cluster fast and easy. Tilt is an open source tool for developer workflows with Kubernetes, created by the Tilt team. Other tools in the space include Skaffold, created by Google, and DevSpace, created by Loft Labs. I work at Loft Labs and developer productivity is a big interest of mine, so I thought I'd look at what Tilt has to offer.
Installation of Tilt depends on your platform. You can find the instructions here. I work on a Mac, and this curl command is the recommended way to install:
curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
I use Homebrew and the Tilt install is pretty slick. The installer added a Homebrew cask for Tilt and then installed the tilt command-line interface (CLI) from that. I looked at the install script and it detects if Homebrew is present, and if it's not, downloads a tarball and installs the binary that way. There are also installation instructions for Linux and Windows.
Tilt is configured using a file called a Tiltfile, which you place at the root of your project. The Tiltfile can be as simple as this (from the docs):
docker_build('example-html-image', '.')
k8s_yaml('kubernetes.yaml')
k8s_resource('example-html', port_forwards=8000)
Or it can be much more complex.
Tiltfiles are written in a language called Starlark, which has a syntax inspired by Python. If you've ever touched Bazel, Starlark is the configuration language that it uses. You can use built-in functions, like the examples in the Tiltfile above, and you can throw in some programming logic as well. There's a guide to the Tiltfile API here.
I used Tilt's example Go project to get started. Go is excellent for evaluating these tools since Go projects are portable and compiled.
Once you've created a Tiltfile and you're ready to develop, the first step is to run the CLI command:
tilt up
After running "tilt up" you press the spacebar to open the Tilt web UI.
The resources listed in the UI represent the things that Tilt is managing, including the Tiltfile. You can drill into a resource and see more details.
The live reloading feature, sometimes referred to as hot reloading by other tools, is the real magic of the projects in this space. Tilt watches the Tiltfile and other managed resources, and when it sees them change, it rebuilds and deploys the ones that need updating automatically. Tilt can do that by building and deploying new containers, but live reloading allows an app to be updated in an already running container instead. Live reloading is a lot faster than having to do a new container build/deploy each time, and it ensures that the latest version of your code is always running.
There's a great video from Ellen Korbes that explains Tilt's control loop if you'd like more details.
You can extend Tilt by writing custom extensions that you can include in your Tiltfiles or use extensions shared by people in the Tilt community. Extensions are also written in Starlark, and you can also write tests for them. You use extensions in your Tiltfile like the built-in functions, and there is a GitHub repo of extensions that people have contributed.
Extensions are a great way to integrate with tools you use in your CI process, and the community repo includes extensions for tools like Circle CI and Snyk.
Tilt is a very helpful workflow tool that helps people get instant feedback on their apps that run in Kubernetes clusters. The Tilt team has put a lot of thought into the UX, which I appreciate.
If you are building apps that run in Kubernetes clusters, you should look at the tools in this space and see which best fits your use case. I worked at Puppet years ago, and once I was talking to Nathen Harvey from Chef at a conference. Someone walked up and asked Nathen if they should use Chef, Puppet, or Ansible to manage their infrastructure. Nathen said, "Yes."
I think it's the same with this class of tools. Live reloading, or hot reloading, whatever you want to call it, is a total game-changer. It's great to see your apps update in real-time when you hit Save, and it should make you more productive.
I'll be writing more about other developer productivity tools for teams using Kubernetes so stay tuned.