Chapter 9. Traffic Control

Traffic control is the ability to change where requests are routed. You already saw a glimpse of this when you tested health checking. When health checks failed, Consul configured the sidecar proxies to route to other instances. However, you didn’t have control over this routing; it happened automatically.

This chapter will teach you how to use Consul to control traffic explicitly. The most common use case for traffic control is implementing deployment strategies like blue/green and canary. However, traffic control is also helpful for migration, when you’re moving a service from one location to another, and for service refactoring, when you’re splitting up or moving functionality between services.

The key benefit of Consul’s traffic control features is that the underlying services don’t need modification. As far as they’re concerned, they’re using the same URLs they’ve always been using, while in reality, the actual requests leaving the sidecar proxies might be different.

This chapter starts with a look at deployments.

Deployment Strategies

A successful deployment gets a new version of your service into the hands of real users without any downtime. The deployment process consists of two discrete steps:

  1. Deploying the latest version

  2. Routing traffic to the latest version

Tip

The two steps are sometimes referred to as deploying and releasing.

Figure 9-1 shows how deployment and routing can be separated. In step 1, only the v1 version of the service ...

Get Consul: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.