In continuous deployment, how you roll out new versions of applications can be as important as the updates themselves. Among the most widely used deployment strategies are Rolling Update and Recreate. Each comes with its own set of advantages and trade-offs.
In this article, we’ll explore what sets them apart, when to use one over the other, and how to make the right choice for your project.
What are Deployment Strategies?
Deployment strategies define how new versions of your application are released. In containerized environments like Kubernetes, they help manage application availability, minimize downtime, and ensure a smooth user experience during updates.
There exists a range of deployment strategies in DevOps, with each one suitable for certain scenarios. The choice of strategy for an organization depends on factors such as the frequency of updates, risk tolerance, and the complexity of their application.
Rolling Update
Rolling Update, or rolling deployment, is a deployment strategy that involves updating the application gradually. It updates pods or containers one at a time (or in pre-specified batches), ensuring continuous service availability. This approach offers easy rollback and it’s less risky than the recreate method.
The downside to this method is that incremental updates can be difficult to manage. It demands routing a percentage of the traffic to the new application and ensuring the user experience is not disrupted.
How it works
New pods are started before old ones are terminated.
It’s designed for high availability, ensuring the users experience little to no disruption.
- You can configure how many pods are unavailable (maxUnavailable) and how many additional pods can be running (maxSurge) during the update.
maxSurge:
Specifies the maximum number (absolute) or percentage of additional pods that can be scheduled above the desired number of pods during a rolling update.
For example, if maxSurge is 25% for a Deployment with a desired replica count of 8, then up to 2 extra pods (25% of 8 = 2) can be created temporarily, allowing up to 10 pods total (8 desired + 2 extra) to be running during the update.
maxUnavailable:
Specifies the maximum number or percentage of pods that can be unavailable during the rolling update.
For example, if maxUnavailable is 25% for a Deployment with 8 desired replicas, up to 2 pods (25% of 8 = 2) can be unavailable during the update, meaning at least 6 pods must be available at any point in time.
When both maxSurge and maxUnavailable are specified, Kubernetes will:
- Create new pods (up to the maxSurge limit) while simultaneously terminating old pods.
- Ensure that at least the number of pods specified by maxUnavailable is always available.
Real-time Use Cases
Rolling deployment ensures the application remains available even during updates. This method is appropriate for scenarios where high availability is crucial. Also, it’s a suitable approach when you need to verify that the new version works correctly before making a complete switch.
Recreate Deployment
Recreate strategy involves terminating all the existing pods and replacing them with new ones. In this strategy, the old version of your application is completely shut down before the new version is started. As you can assume, the application experiences downtime when the old version goes down until a new deployment starts successfully. This approach provides a clean, predictable transition but the downtime is a significant drawback.
How it works
- Terminates all existing instances before spinning up new ones.
- Causes a brief period of downtime as the application is unavailable during the transition.
- Service resumes once the new version is fully up.
Real-time Use Cases
A recreate strategy is suitable for non-production environments, such as development, staging, and QA. It’s also a good option in situations where a short period of downtime is tolerable. If you are able to schedule planned maintenance during off times, then this method is appropriate.
Additionally, the recreate deployment strategy works well for batch processing. If you have background tasks or batch jobs that can be paused temporarily, you can explore this method.
How to Choose the Right Deployment Strategy
When choosing the right deployment strategy for your application, there are various factors to consider:
Downtime tolerance: The tolerance for downtime differs across applications. Critical applications require strategies like rolling updates to ensure zero downtime.
Size and complexity: Simpler applications with minimal dependencies may benefit from simpler strategies, while complex applications may require more sophisticated methods like rolling deployments to minimize risk. For simple applications or early-stage environments, the Recreate method might suffice.
There is no right or wrong answer when it comes to the right deployment strategy. Each comes with its own advantages and drawbacks. The right approach depends entirely on your objectives and the needs of the application.
Cost Implications
One important consideration with Rolling Update is the potential for temporary infrastructure cost spikes. You temporarily run additional pods, sometimes doubling your resource consumption if your app has a high maxSurge or gets stuck in rollout.
In cloud environments, where you're billed per resource usage, this can lead to increased costs. In contrast, Recreate doesn't involve overlapping pods, so you don’t incur additional costs during the deployment process.
PipeOps’ Approach to Deployment
PipeOps is a continuous integration and delivery (CI/CD) platform designed to simplify the deployment process for developers and development teams.
Choosing your deployment strategy on PipeOps is straightforward:
- Navigate to your project’s settings page.
- Under the General Settings tab, locate the Deployment Strategy section.
The default deployment strategy is Rolling Update. However, you can also select the Recreate method from the dropdown.
If you choose Rolling Update, configure Max Surge and Max Unavailable based on your tolerance.
This gives you fine-grained control over how your updates are rolled out, without needing to fiddle with Kubernetes YAML files.
Summary
Deployment strategies play a key role in the software delivery process. Whether you’re optimizing for uptime, speed, or simplicity, choosing the right approach can help you ship confidently and maintain a reliable experience for users.
With PipeOps, implementing these strategies is effortless. You don’t need to write complex configuration files or manage intricate policies. PipeOps provides a streamlined interface that lets you select and customize deployment strategies with just a few clicks. This simplifies your workflow and lets you focus on building great software instead of dealing with deployment mechanics.