Why "ReusePort" is Needed in Traefik?
devops·@simplestack·
0.000 HBDWhy "ReusePort" is Needed in Traefik?
<center>  </center> Imagine you have a bunch of different restaurants (these are like different programs or even different versions of the same program) all wanting to use the same front door (this is like a specific internet address and port number). Normally, only one restaurant can "own" that front door at a time. If another restaurant tries to use it, there would be a conflict! The ReusePort option is like getting permission to have multiple restaurants share the same front door. Here's how it works: - Sharing the Door: Instead of one restaurant exclusively owning the door, the kernel (the brain of your computer) allows multiple restaurants to listen at the same door. - Traffic Cop: The kernel also acts like a traffic cop. When a customer (internet traffic) comes to the front door, the kernel intelligently decides which restaurant to send them to. # Why is this useful? Think about upgrading a restaurant. Normally, you'd have to close the old one, open the new one, and there might be a period where no one can get in. With ReusePort, you can: - Canary Deployments: Open a new version of your restaurant (the "canary") alongside the old one using the same front door. The traffic cop can send a small percentage of customers to the new restaurant to see if everything is working correctly before fully switching over. If there are problems, you can easily direct all traffic back to the old restaurant without any downtime. - No Downtime Upgrades: You can upgrade your restaurant or change its menu (reload configuration) without having to close the doors completely. The traffic cop will just start sending new customers to the updated restaurant. - Better Performance: With multiple restaurants listening at the same door, the kernel can distribute the incoming customers more evenly, potentially leading to faster service overall. # Concrete Example Scenario: You want to upgrade your Traefik instance to a new version or reload its static configuration without interrupting the flow of incoming requests. ## Without ReusePort: 1. You would typically stop the running Traefik process. 2. During this brief period, Traefik is unavailable, and any incoming requests will fail, leading to service downtime. 3. You then start the new Traefik process with the updated configuration or binary. ## With ReusePort enabled: 1. You can start a new Traefik process (with the new version or configuration) alongside the existing, running Traefik process. Both processes are configured to listen on the same port (e.g., port 80 and 443 for HTTP/HTTPS) because ReusePort allows this. 2. The operating system kernel, acting as a load balancer due to SO_REUSEPORT, will begin distributing new incoming connections between both the old and the new Traefik processes. 3. By configuring Traefik's transport.lifeCycle settings (specifically graceTimeOut), you can ensure that the old Traefik process continues to handle any existing connections gracefully until they are closed. This prevents abrupt termination of ongoing requests. 4. Once all existing connections on the old process have finished, you can safely shut down the old Traefik process. 5. All new traffic is now being handled by the new Traefik process without any interruption in service for your users. ``` entryPoints: web: address: ":80" reusePort: true websecure: address: ":443" reusePort: true providers: docker: {} file: directory: /etc/traefik/dynamic ``` ## Upgrade Process: 1. Start a new Traefik instance with the new binary or modified traefik.yaml (ensuring reusePort is still enabled for the relevant entryPoints). This new instance will also listen on ports 80 and 443. 2. Traefik will start distributing new requests between the old and the new processes. 3. The old process continues to handle existing connections. 4. Once the graceTimeOut period (configured in transport.lifeCycle, though not shown in this simplified example) expires and all old connections are closed, you can stop the old Traefik process. # In essence ReusePort provides the underlying mechanism for allowing multiple Traefik instances to coexist on the same network ports, which, when combined with Traefik's lifecycle management, enables sophisticated deployment strategies like zero-downtime upgrades and canary deployments of Traefik itself. --- *If you liked this content I’d appreciate an upvote or a comment. That helps me improve the quality of my posts as well as getting to know more about you, my dear reader.* *Muchas gracias!* *Follow me for more content like this.* *[X](https://twitter.com/edca3911) | [PeakD](https://peakd.com/@simplestack) | [Rumble](https://rumble.com/user/simplestack) | [YouTube](https://www.youtube.com/@simple-stack-by-ed) | [Linked In](https://www.linkedin.com/in/edwardcasanova/) | [GitHub](https://github.com/ed3899) | [PayPal.me](https://paypal.me/edca3899?country.x=MX&locale.x=es_XC) | [Medium](https://medium.com/@ed.wacc1995/subscribe)* *Down below you can find other ways to tip my work.* ``` BankTransfer: "710969000019398639", // CLABE BAT: "0x33CD7770d3235F97e5A8a96D5F21766DbB08c875", ETH: "0x33CD7770d3235F97e5A8a96D5F21766DbB08c875", BTC: "33xxUWU5kjcPk1Kr9ucn9tQXd2DbQ1b9tE", ADA: "addr1q9l3y73e82hhwfr49eu0fkjw34w9s406wnln7rk9m4ky5fag8akgnwf3y4r2uzqf00rw0pvsucql0pqkzag5n450facq8vwr5e", DOT: "1rRDzfMLPi88RixTeVc2beA5h2Q3z1K1Uk3kqqyej7nWPNf", DOGE: "DRph8GEwGccvBWCe4wEQsWsTvQvsEH4QKH", DAI: "0x33CD7770d3235F97e5A8a96D5F21766DbB08c875" ```
👍 magic.byte, lolz.byte,