September 21st, 2024

Kamal Proxy – A minimal HTTP proxy for zero-downtime deployments

Kamal Proxy is a minimal HTTP proxy that enables zero-downtime deployments, supports host-based routing, manages TLS certificates automatically, and allows configuration via environment variables for containerized environments.

Read original articleLink Icon
Kamal Proxy – A minimal HTTP proxy for zero-downtime deployments

Kamal Proxy is a minimal HTTP proxy designed to enable zero-downtime deployments for web applications. Its primary function is to facilitate the deployment of new application instances without interrupting ongoing traffic, making it particularly beneficial for developers and DevOps teams. Kamal Proxy can be integrated with the Kamal deployment framework or used independently. Key features include host-based routing, which allows multiple applications to run on a single server, and automatic TLS certificate management for secure connections. Users can configure the proxy using environment variables, which is advantageous in containerized environments. Basic commands for running the proxy, deploying instances, and enabling TLS are provided for ease of use. Additionally, Kamal Proxy can be built locally or within Docker containers, with a sample Docker Compose setup available for testing purposes.

- Kamal Proxy enables zero-downtime deployments for web applications.

- It supports host-based routing for multiple applications on a single server.

- Automatic TLS certificate management is included for secure connections.

- Configuration can be done using environment variables, suitable for containerized setups.

- Basic commands are provided for running and deploying applications easily.

Link Icon 19 comments
By @000ooo000 - 4 months
Strange choice of language for the actions:

>To route traffic through the proxy to a web application, you *deploy* instances of the application to the proxy. *Deploying* an instance makes it available to the proxy, and replaces the instance it was using before (if any).

>e.g. `kamal-proxy deploy service1 --target web-1:3000`

'Deploy' is a fairly overloaded term already. Fun conversations ahead. Is the app deployed? Yes? No I mean is it deployed to the proxy? Hmm our Kamal proxy script is gonna need some changes and a redeployment so that it deploys the deployed apps to the proxy correctly.

Unsure why they couldn't have picked something like 'bind', or 'intercept', or even just 'proxy'... why 'deploy'..

By @viraptor - 4 months
It's an interesting choice to make this a whole app, when the zero-downtime deployments can be achieved with other servers trivially these days. For example any app+web proxy which supports Unix sockets can do zero-downtime by moving the file. It's atomic and you can send the warm-up requests with curl. Building a whole system with registration feels like an overkill.
By @ksajadi - 4 months
This primarily exists to take care of a fundamental issue in Docker Swarm (Kamal's orchestrator of choice) where replacing containers of a service disrupts traffic. We had the same problem (when building JAMStack servers at Cloud 66) and used Caddy instead of writing our own proxy and also looked at Traefik which would have been just as suitable.

I don't know why Kamal chose Swarm over k8s or k3s (simplicity perhaps?) but then, complexity needs a home, you can push it around but cannot hide it, hence a home grown proxy.

I have not tried Kamal proxy to know, but I am highly skeptical of something like this, because I am pretty sure I will be chasing it for support for anything from WebSockets to SSE, to HTTP/3 to various types of compression and encryption.

By @blue_pants - 4 months
Can someone briefly explain how ZDD works in general?

I guess both versions of the app must be running simultaneously, with new traffic being routed to the new version of the app.

But what about DB migrations? Assuming the app uses a single database, and the new version of the app introduces changes to the DB schema, the new app version would modify the schema during startup via a migration script. However, the previous version of the app still expects the old schema. How is that handled?

By @shafyy - 4 months
Also exciting that Kamal 2 (currently RC https://github.com/basecamp/kamal/releases) will support auto-SSL and make it easy to run multiple apps on one server with Kamal.
By @kh_hk - 4 months
I don't understand how to use this, maybe I am missing something.

Following the example, it starts 4 replicas of a 'web' service. You can create a service by running a deploy to one of the replicas, let's say example-web-1. What does the other 3 replicas do?

Now, let's say I update 'web'. Let's assume I want to do a zero-downtime deployment. That means I should be able to run a build command on the 'web' service, start this service somehow (maybe by adding an extra replica), and then run a deploy against the new target?

If I run a `docker compose up --build --force-recreate web` this will bring down the old replica, turning everything moot.

Instructions unclear, can anyone chime in and help me understand?

By @simonw - 4 months
Does this implement the “traffic pausing” pattern?

That’s where you have a proxy which effectively pauses traffic for a few seconds - incoming requests appear to take a couple of seconds longer than usual, but are still completed after that short delay.

During those couple of seconds you can run a blocking infrastructure change - could be a small database migration, or could be something a little more complex as long as you can get it finished in less than about 5 seconds.

By @risyachka - 4 months
Did they mention anywhere why they decided to write their own proxy instead of using Traefik or something else battle tested?
By @mt42or - 4 months
NIH. Nothing else to add.
By @seized - 4 months
This seems like something HAProxy can do effortlessly.... Especially with it's hitless reload.
By @ianpurton - 4 months
DHH in the past has said "This setup helped us dodge the complexity of Kubernetes"

But this looks like somehow a re-invention of what Kubernetes provides.

Kubernetes has come a long way in terms of ease of deployment on bare metal.

By @moondev - 4 months
Does this handle a host reboot?
By @oDot - 4 months
DHH mentioned they built it to move from the cloud to bare metal. He glorifies the simplicity but I can't help thinking they are a special use case of predictable, non-huge load.

Uber, for example, moved to the cloud. I feel like in the span between them there are far more companies for which Kamal is not enough.

I hope I'm wrong, though. It'll be nice for many companies to be have the choice of exiting the cloud.

By @dilyevsky - 3 months
Everything can be made simple if you throw 90% of features out. Now we get to watch dhh and crew reinventing all the wheels that k8s had in 2018 over the next couple years
By @rohvitun - 4 months
Aya
By @0xblinq - 4 months
3 years from now they'll have invented their own AWS. NIH syndrome in full swing.