Discover how the custom reverse proxy enhances Kamal’s deployment strategy with seamless traffic routing, zero-downtime updates, and automated security measures for containerized application.

Introduction to Kamal-Proxy

Kamal, a straightforward deployment tool built around Docker containers, has introduced its custom proxy called Kamal-Proxy. This new component aims to simplify the deployment process, particularly for newcomers or those less familiar with complex technological setups. In this post, we'll explore what Kamal-Proxy is and why it's an essential part of Kamal's deployment strategy.

What is Kamal-Proxy?

Kamal-Proxy is a custom-built reverse proxy designed specifically for Kamal's deployment needs. It serves as a critical component in managing traffic to deployed applications, handling multiple services, and ensuring smooth, zero-downtime deployments. Unlike its predecessor Traefik, Kamal-Proxy is tailored to work seamlessly with Kamal's imperative approach to deployments.

Why does Kamal need a proxy like Kamal-Proxy?

Kamal-Proxy addresses these gaps by offering key features:

  • Simplicity in Service Deployment: Kamal-Proxy maintains Kamal’s ease-of-use, allowing users to deploy services by specifying the service type and target without the need for complex configurations.
  • Zero-Downtime Deployments: While Kamal's basic approach doesn’t include automatic container replacement, Kamal-Proxy ensures zero-downtime updates by intelligently routing traffic during deployments, minimizing service disruption.
  • Traffic Management and Multi-Service Support: Kamal-Proxy intelligently routes incoming requests to the appropriate containers, even when hosting multiple applications on the same server. It eliminates port conflicts by using hostnames for routing.
  • Health Monitoring: To ensure reliable service, Kamal-Proxy continuously monitors container health, directing traffic only to healthy instances.
  • Automatic TLS Certificates: Security is enhanced with automatic issuance and management of TLS certificates, ensuring encrypted communication without manual intervention by utilizing Let’s Encrypt.

Kamal-Proxy Functionalities

Kamal-Proxy integrates seamlessly with Kamal's deployment process:

  1. Traffic Interception: It intercepts incoming client requests.
  2. Intelligent Routing: Based on predefined criteria (like hostnames), it routes requests to the appropriate containers.
  3. Update Management: During deployments, it gradually shifts traffic from old to new containers, ensuring continuous service.
  4. Health-Based Routing: By monitoring container health, it automatically adjusts routing to maintain service reliability.

Imperative vs. Declarative?

Declarative (Traefik):

  • Specifies the desired end state (expected result), and the system figures out how to achieve that state.
# You declare what you want, not how to achieve it

http:
  routers:
    my-router:
      rule: "Host(`example.com`)"
      service: my-service
services:
  my-service:
    loadBalancer:
      servers:
        - url: "http://localhost:8080"

Imperative (Kamal-Proxy):

  • Provide step-by-step instructions to achieve the desired outcome.

  • You have more direct control over each action.

# You explicitly state each action to take

kamal proxy:add-route example.com --target localhost:8080
kamal proxy:enable-ssl example.com

Removal of Host-Level Complexities

Kamal-Proxy eliminates the need for "special cord files" that Traefik required:

  • The Problem: Traefik, being declarative, needed a way to understand the health status of containers.

  • The Workaround: Kamal had to create special files (referred to as "cord files") on the host system.

    • These files acted as a bridge between Kamal's understanding of container health and Traefik's configuration.
    • Example: A file might be created or removed to signal whether a container is healthy or not.
  • The Drawback: This solution was seen as inelegant and added complexity to the host system.

This change simplifies the system architecture and makes deployments more straightforward, benefiting both new and experienced users.

Conclusion

Kamal-Proxy represents a significant advancement in Kamal's deployment toolkit. By providing a custom-built proxy solution that aligns perfectly with Kamal's philosophy of simplicity and direct control, it enhances the deployment experience for users of all expertise levels. From simplifying service management to ensuring zero-downtime updates and automatic security measures, Kamal-Proxy embodies Kamal's commitment to making container deployment accessible and efficient.

Understanding Kamal-Proxy is key to leveraging the full potential of Kamal for your deployment needs, offering a streamlined, secure, and user-friendly approach to managing containerized applications in today's dynamic digital landscape.