A few months ago we began a piece of work on my last project, setting out to accomplish two things:

1. Improve the speed of our release process

2. Allow us to run multiple versions of the application concurrently

These were two limitations of our initial deployment and release design and so in sharing this blog I am hoping the lessons learnt will be able to help you avoid the same issues.

Before jumping into the solution, I’ll quickly describe our starting point.

Please Note: This is a simplified view of the infrastructure, we’ll only describe elements relevant to the Zero Downtime aspect of the solution.

Configuration — Before

Design Decisions

— Separate Namespaces for Web Tier (App-Publishing) & Application Tier (Blue & Green)

— Application Namespaces (Blue/Green) would be immutable and therefore would only ever contain a single release

— Application deployed via single Helm chart

— Use the Nginx Ingress Controller to manage Kubernetes Ingress Resources

Issues with this Configuration

1. Ingress Controller Reloads cause 1 Second of Dropped Traffic

The redirection mechanism, illustrated in red in the above diagram, which redirected live traffic between the “Blue” and “Green” Namespaces meant an update to the Ingress Resource in App Publishing to point to the cold Blue/Green Redirector Service Resource, as shown below.

Updating the Ingress resource to point at a new service means the Ingress Controller would need to perform a reload of the Nginx configuration, which incurred on average one second of dropped connection, resulting in a 500 error. (This and other causes of reloads can be found here).

This meant, in order to perform Zero Downtime releases, we had to remove Region1 from Traffic Manager, update it while offline, add it back into Traffic Manager & repeat for Region2. This led to the next issue with this setup.

2. Unable to support multiple versions

The application needs to be able to route user traffic in two scenarios:

New users landing on the homepage should be routed to the latest stable version of the application. Existing user sessions requesting version specific assets should be routed to the requested version.

In the current design, we have no way of routing based on requested version and only have one ingress flow for both scenarios of traffic.

This meant during the time in which Region1 was updated and re-introduced to Traffic Manager, and Region2 was being drained (typically between 5–10 minutes), existing user sessions on Region2 would have no route to the version specific assets on Region1, resulting in a 404.

3. Slow Release Process

The last issue with this set up was the amount of time it took to perform a release. Although the only manual step in the release process as mentioned above was the removing/re-adding of regions from Traffic Manager, waiting for connections to drain before performing the switch to the new version drastically slowed down our release process, which meant redirecting to a new, already tested release, could take up to 20 minutes.

The Fix

The plan for resolving this was quite simple and can be summarised by three key points.

1.Remove the need for Nginx Ingress Controller reloads during redirection.

The root of our redirection issues is the need for Nginx Ingress Controller reloads, and the 1 second of downtime this incurs. We therefore need to ensure all Ingress resources remain static, meaning their downstream config can not change after initial configuration. In doing this, we need to find another way to redirect traffic. This is where Label Selectors come in.

Label Selectors allow us to route traffic to target Pods within a single Namespace without incurring a connection drop. This was the key to unlocking Zero Downtime deployments without Traffic Manager manipulation.

In order to facilitate this we had to move away from Blue/Green Namespaces to a single Production Namespace, meaning our immutable component of release was no longer the entire Namespace and was instead the Helm Release.

2.New Default Ingress & Service Resources

We would introduce a new “Default” Ingress flow to handle new user traffic. The Ingress Resources within this flow would remain Static and we would instead utilise Label Selectors for Zero Downtime redirection.

3.Restructure Ingress Resources

To facilitate the second use case of traffic routing, we would utilise URL Path Based Routing to introduce new version specific Ingress flows for existing user sessions.

Configuration — After

Key Points:

— Dual Region & Traffic Manager still exist, not shown above as now irrelevant to Zero Downtime.

— Single Production Namespace

— Simplified design, no Services referencing Resources in different Namespaces

— Default Ingress flow (left) handles first use case of routing traffic landing on the services homepage.

— Version specific Ingress handles second use case of routing traffic that is requesting version specific assets based on the URL Path.

— Ingress resources remain Static and no longer update during redirection

— Redirection (in red) is now a Label Selector change using the kubectl patch command, via a CI job (shown below)

The Result

1. Manual step in redirection process has been removed

2. Redirecting to a new version now takes under 1 second with no connection drop. (The CI Job which runs this takes under 5 seconds)

3. New versions can be deployed to Production Namespace at anytime and tested offline before any live traffic is directed to them.

4. We are able to support an unlimited number of concurrent versions