Table of contents
- Overview
- Before and After Architecture Visuals
- Task 1: Creating Your Elastic Beanstalk Playaground
- Task 2: Rolling into the Future - A Seamless Deployment
- Task 3: Embracing the Future with Blue-Green Deployment
- Task 4: DNS Ballet - Switching Traffic with Grace
- Task 5: Tidying Up - Saying Farewell to the Old
- Conclusion
Hey Devops amigos! Today, we're diving into the world of faultless deployments, a crucial aspect of running a software company. Imagine a world where deploying code is smooth, with minimal risk and maximum availability. Well, guess what? I am making that a reality in this tasks.
Overview
Running a software company involves intricate systems and, during deployments, these systems dance delicately, juggling multiple moving parts. The risk is real, but fear not! Our lab today is here to equip you with the skills to navigate these complexities. We'll be deploying multiple version updates of an application in an environment that's load-balanced and auto-scaled.
Tasks Objectives
By the end of these tasks, you'll be a deployment maestro, capable of:
Building Elastic Beanstalk Applications and Environments:
- We'll start by understanding how to set up applications and environments using Elastic Beanstalk, a powerful service that makes deploying and managing applications a breeze.
Performing Rolling Deployments on EC2 Resources:
- Learn the art of the low-friction rolling deployment. We'll deploy the first update seamlessly, ensuring minimal impact on your underlying EC2 resources.
Executing Blue-Green Deployments with Elastic Beanstalk:
- Take your skills to the next level with blue-green deployments. We'll create a separate environment to run the new version of the application. A DNS cutover will gracefully switch incoming traffic to the new environment, ensuring zero-downtime updates.
Minimizing Costs through Cleanup:
- We'll be responsible cloud practitioners. Learn how to tidy up after blue-green deploys, minimizing costs and keeping your cloud environment pristine.
Before and After Architecture Visuals
Task 1: Creating Your Elastic Beanstalk Playaground
In this task, we will setup Elastic Beanstalk application and environment.
Configuring Environment
Open the AWS Management Console and enter "Beanstalk" in the search bar. Click on Elastic Beanstalk under Services.
Click on "Create Application" to kick off the setup.
- Fill in the application details.
Application Name: Enter "My App."
Platform: Select your preferred platform (e.g., Node.js).
Version label: Call it "my-app-v1."
Source code origin: Choose "Upload your code."
Source code origin: Select "Local file" and upload the "v1.zip"(I have my html, css, JS files under this zip) file you downloaded earlier.
Change the Presets to Custom configuration and click Next.
Set up service access.
Service role: Use an existing service role named "aws-elasticbeanstalk-service-role."
EC2 instance profile: Choose "aws-elasticbeanstalk-ec2-profile."
Configure networking, database, and tags.
VPC: Select the non-default VPC with a CIDR block of 10.0.0.0/16.
Instance subnets: Pick the private subnet with CIDR block 10.0.1.0/24.
Database subnets: Select the two private subnets with CIDR blocks 10.0.1.0/24 and 10.0.2.0/24.
Configure instance traffic and scaling.
EC2 security groups: Choose the default security group.
Environment type: Select "Load balanced."
Instance types: Pick only "t2.micro."
Load balancer subnets: Choose the two public subnets with CIDR blocks 10.0.100.0/24 and 10.0.101.0/24.
Configure updates, monitoring, and logging.
System: Choose "Enhanced" for real-time monitoring.
Deployment policy: Select "Rolling" with a batch size of 30.
Review the configurations and click "Submit." Now, watch the magic unfold as Elastic Beanstalk creates your environment. This might take a few minutes.
Once complete, click on the environment's URL to view the deployed application.
Task 2: Rolling into the Future - A Seamless Deployment
Head over to your Elastic Beanstalk environment and locate the magic button - "Upload and Deploy."
In the "Upload and Deploy" form, let's configure the settings for the grand reveal:
Upload application: Click "Choose File" and select the "v2.zip" file you modified to version 2.
Version label: Name it "my app v2."
Click "Deploy" to experience Elastic Beanstalk's rolling deployment, where instances take turns upgrading to a new version. Temporary unavailability may occur during the switch from v1 to v2, especially with a single instance, but more instances reduce the risk of outages.
Wait patiently until the deployment completes, and confirm that your environment reports v2 is running.
Here are some key takeaways:
No new instances are created; the new version gracefully replaces the old on existing instances.
The maximum available capacity for serving traffic is momentarily reduced during the upgrade, potentially causing brief service outages, especially with a single instance.
Keep in mind that during multi-batch upgrades, old and new versions might coexist momentarily.
Task 3: Embracing the Future with Blue-Green Deployment
Cloning the Environment
In Elastic Beanstalk, navigate to the environment view of your current environment (MyApp-env).
Click on "Actions" in the upper-right corner and select "Clone Environment" to create a new environment, our green paradise.
On the Clone environment form, name the new environment:
- Environment name: Myapp-env-1 (Leave other values as default)
Click "Clone" and wait patiently for the new environment to take shape. It might take up to 5 minutes. Ensure the Health status turns to Ok before moving forward.
Rolling Deployment to Green
In the "Upload and Deploy" form:
Upload application: Choose the v3.zip file you modified to version 3.
Version label: Name it "my app v3."
Click "Deploy" and watch as Elastic Beanstalk performs a seamless rolling deployment to our fresh, green environment. Since the environment is currently unused, no need to worry about availability and performance concerns.
Wait until the rolling deployment completes, and confirm that the Running Version is now "my app v3."
Task 4: DNS Ballet - Switching Traffic with Grace
It's time to perform a DNS swap, a graceful ballet of directing traffic seamlessly between environments.
Initiating the DNS Swap
In the Elastic Beanstalk environment console, select your green environment (MyApp-env-1).
Click on "Actions," then choose "Swap environment domain."
In the Swap environment domain form:
- Environment name: MyApp-env (Select the blue environment)
Click "Swap" and watch the magic unfold. The swap typically completes in under ten seconds. You'll see the Health status turn to Ok, and the most recent event will read "Completed swapping CNAMEs."
Verification:
- Verify that the browser loads version 3 of the app
Remember these key points:
The maximum number of instances during deployment is twice the target number, with both environments fully functional.
The minimum number of instances serving the application never falls below the target.
Rolling back to the old version is easy since the blue environment remains unaltered.
Old and new versions are never served simultaneously to new clients.
Task 5: Tidying Up - Saying Farewell to the Old
Terminate everything that you have to avoid costs!!!!!
Conclusion
In these tasks, you created a web application environment using AWS Elastic Beanstalk. The environment is configured for high availability and to perform rolling updates when new versions of the application are deployed.
If you like this blog, hit that like and follow buttons for more content like this.
Follow me on Linkedin.
Thank you for paying visit to my blog!!!