Azure DevOps RealTime Projects
Azure DevOps RealTime Projects
NET Core
Application Using Azure DevOps
1. Project Scope
This project focuses on setting up a Continuous Integration and Continuous Deployment (CI/CD)
pipeline for a .NET Core web application using Azure DevOps. The pipeline automates code
integration, testing, and deployment to Azure App Service. The goal is to ensure fast, reliable, and
automated software delivery with minimal manual intervention.
Key Features:
● Automated build and testing of the application
● Deployment to Azure App Service
● Versioning control and rollback mechanism
● Integration with Azure DevOps Repos and GitHub
2. Tools Used
● Azure DevOps – For managing repositories, pipelines, and releases
● Azure Repos or GitHub – Source code version control
● Azure Pipelines – CI/CD automation
● Azure App Service – Hosting the application
● MSTest / NUnit – For unit testing
● SonarCloud – Code quality and security analysis
● Azure Key Vault – Secure management of secrets
● Application Insights – Performance monitoring
3. Analysis Approach
Current Challenges Without CI/CD
● Manual deployments are time-consuming and error-prone
● Lack of automated testing can lead to undetected issues in production
● Security vulnerabilities due to hardcoded credentials
Proposed Solution
Implement a fully automated CI/CD pipeline to handle build, testing, security scanning, and
deployment seamlessly.
Pipeline Flow:
1. Developer commits code to Azure Repos/GitHub.
2. Azure Pipelines triggers build and runs tests.
3. SonarCloud performs static code analysis.
4. Security scanning using Azure Key Vault to fetch secrets.
5. If all tests pass, the build artifact is stored in Azure Artifacts.
6. Azure Pipelines deploys the application to Azure App Service.
7. Application Insights provides monitoring and logs.
4. Step-by-Step Implementation
Step 1: Set Up Azure DevOps Repository
1. Go to Azure DevOps and create a new project.
2. Navigate to Repos → Import Code or clone a new repository.
Use the following Git commands to push an existing .NET Core app:
git init
git remote add origin <repo-url>
git add .
git commit -m "Initial commit"
git push origin main
3.
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
- script: dotnet build --configuration Release
displayName: 'Build the project'
- script: dotnet test --logger trx
displayName: 'Run Unit Tests'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
2. Save and run the pipeline to build and test the application.
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'SonarCloud'
organization: '<your-org>'
projectKey: '<your-project-key>'
scannerMode: 'MSBuild'
- script: dotnet build
- task: SonarCloudAnalyze@1
- task: SonarCloudPublish@1
Step 4: Set Up CD Pipeline to Azure App Service
1. Go to Releases → New Release Pipeline.
2. Choose Azure App Service Deployment template.
3. Select Azure Subscription and the App Service name.
4. Choose the drop artifact from CI pipeline.
5. Configure deployment stages like Staging and Production.
6. Enable Approval Gates for manual approvals before production deployment.
7. Click Create Release and deploy.
- task: AzureKeyVault@1
inputs:
azureSubscription: 'MyAzureSubscription'
KeyVaultName: 'my-keyvault'
SecretsFilter: '*'
Modify appsettings.json:
"ApplicationInsights": {
"InstrumentationKey": "<your-instrumentation-key>"
}
2. Update the Azure DevOps release pipeline to enable monitoring logs.
5. Conclusion
This project successfully implemented an end-to-end CI/CD pipeline for a .NET Core web application
using Azure DevOps. Key benefits:
✅
Real-Time Example:
A software company developing a finance dashboard can use this pipeline to deploy new features
faster while ensuring security and stability.
Key Features:
● Fully automated resource provisioning using Terraform
● Integration with Azure DevOps Pipelines for continuous deployment
● State management with Azure Storage
● Role-based access control (RBAC) for secure deployments
● Infrastructure drift detection and remediation
2. Tools Used
● Azure DevOps – CI/CD pipeline for infrastructure deployment
● Terraform – Infrastructure as Code tool
● Azure CLI – To manage Azure resources
● Azure Key Vault – Secure storage for sensitive credentials
● Azure Storage Account – To store Terraform state files
● GitHub/Azure Repos – Source code management for Terraform scripts
3. Analysis Approach
Challenges Without IaC
● Manual provisioning of infrastructure is time-consuming and error-prone
● Inconsistent environments between development, testing, and production
● Difficult rollback process if an infrastructure change breaks the system
Proposed Solution
✅
By using Terraform with Azure DevOps, we can:
✅
✅
Maintain version-controlled infrastructure code
Improve reliability and repeatability
Easily scale and modify infrastructure as per business needs
Workflow:
1. Developers write Terraform scripts and push to Azure Repos/GitHub.
2. Azure DevOps Pipelines trigger Terraform execution.
3. Terraform plans and applies infrastructure changes.
4. Resources are deployed to Azure.
5. Terraform state is stored securely in an Azure Storage Account.
4. Step-by-Step Implementation
Step 1: Set Up Azure DevOps Repository
1. Go to Azure DevOps → Create a new project.
2. Navigate to Repos → Clone a new Git repository.
git init
git remote add origin <repo-url>
git add .
git commit -m "Initial Terraform commit"
git push origin main
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "rg" {
name = "my-resource-group"
location = "East US"
}
resource "azurerm_storage_account" "storage" {
name = "mystorageacct"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"
}
Initialize Terraform:
terraform init
terraform plan
Update backend.tf:
terraform {
backend "azurerm" {
resource_group_name = "my-resource-group"
storage_account_name = "mystoragestate"
container_name = "tfstate"
key = "terraform.tfstate"
}
}
Run:
terraform init
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: TerraformInstaller@0
inputs:
terraformVersion: 'latest'
- script: terraform init
displayName: 'Initialize Terraform'
- script: terraform plan -out=tfplan
displayName: 'Terraform Plan'
- script: terraform apply -auto-approve tfplan
displayName: 'Apply Terraform Changes'
- task: AzureKeyVault@1
inputs:
azureSubscription: 'MyAzureSubscription'
KeyVaultName: 'my-keyvault'
SecretsFilter: '*'
1. Commit and push the changes to trigger the pipeline and deploy the VM.
5. Conclusion
This project implemented Infrastructure as Code (IaC) using Terraform and Azure DevOps, enabling
automated, scalable, and version-controlled infrastructure provisioning.
Key Benefits:
✅
✅ Automated Infrastructure Deployment – No manual configuration
Real-Time Example:
A company migrating to Azure Cloud can use this approach to automate provisioning of Virtual
Machines, Storage, and Networking, ensuring consistency across all environments.
Project 3: Automating Application Deployment
with Azure DevOps CI/CD and Kubernetes
(AKS)
1. Project Scope
This project focuses on automating the deployment of a containerized application on Azure
Kubernetes Service (AKS) using Azure DevOps CI/CD pipelines.
Key Features:
✅
✅ Build and package the application using Docker
✅
✅
Push the container image to Azure Container Registry (ACR)
Deploy the application to AKS using Helm charts
2. Tools Used
● Azure DevOps – Continuous Integration & Continuous Deployment
● Azure Kubernetes Service (AKS) – Kubernetes cluster for container orchestration
● Docker – Containerization of applications
● Helm – Kubernetes package manager for deployment
● Azure Container Registry (ACR) – To store Docker images
● Kubernetes Manifest (YAML) – For AKS deployment
● Azure CLI & Kubectl – For managing the AKS cluster
3. Analysis Approach
Challenges Without CI/CD & Kubernetes
● Manual deployments lead to inconsistency and errors
● Difficult rollback process in case of failures
● Scaling applications manually is inefficient
Proposed Solution
✅
By using Azure DevOps CI/CD with AKS, we can:
Workflow:
1. Developers push code to Azure Repos (or GitHub).
2. Azure DevOps triggers a build pipeline, creating a Docker image.
3. The image is pushed to Azure Container Registry (ACR).
4. A release pipeline deploys the application to AKS using Helm.
4. Step-by-Step Implementation
Step 1: Set Up Azure Kubernetes Service (AKS)
Create a Resource Group in Azure:
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@2
inputs:
command: 'buildAndPush'
repository: 'myacr.azurecr.io/azure-vote'
dockerfile: 'Dockerfile'
containerRegistry: 'MyACR'
tags: 'v$(Build.BuildId)'
3. Save and run the pipeline. This builds and pushes the container image to ACR.
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote
spec:
replicas: 2
selector:
matchLabels:
app: azure-vote
template:
metadata:
labels:
app: azure-vote
spec:
containers:
- name: azure-vote
image: myacr.azurecr.io/azure-vote:v1
ports:
- containerPort: 80
- task: Kubernetes@1
inputs:
command: apply
connectionType: 'Azure Resource Manager'
azureSubscriptionEndpoint: 'MyAzureSubscription'
resourceGroupName: 'MyResourceGroup'
clusterName: 'MyAKSCluster'
namespace: 'default'
manifests: '$(System.DefaultWorkingDirectory)/deployment.yaml'
image: myacr.azurecr.io/azure-vote:v2
Push the changes → The pipeline automatically updates the app on AKS.
5. Conclusion
This project automated the end-to-end deployment of a containerized application using Azure
DevOps and AKS.
Key Benefits:
✅
✅ Seamless CI/CD integration – No manual deployments
Real-Time Example:
A DevOps team managing a microservices-based application can use this setup to automate
deployments, improve reliability, and enable rapid scaling.
Project 4: Infrastructure as Code (IaC) with
Terraform and Azure DevOps
1. Project Scope
This project focuses on using Terraform to provision and manage Azure infrastructure through
Azure DevOps CI/CD pipelines.
Key Features:
✅
✅ Automate the creation of Azure infrastructure (VMs, Networks, Storage)
✅
✅
Use Terraform for Infrastructure as Code (IaC)
Store Terraform state files in Azure Storage Account
2. Tools Used
● Azure DevOps – CI/CD for Infrastructure deployment
● Terraform – Infrastructure as Code tool
● Azure CLI – To manage Azure resources
● Azure Storage Account – For Terraform state management
● Azure Key Vault – To store sensitive credentials
● Azure Virtual Network (VNet), Virtual Machines, Storage Accounts
3. Analysis Approach
Challenges Without IaC & DevOps
● Manual infrastructure provisioning is error-prone and time-consuming
● Difficult to track changes made to cloud resources
● No version control for infrastructure changes
● Security risks due to hardcoded credentials
Proposed Solution
✅
By integrating Terraform with Azure DevOps, we can:
✅
✅
Enable version control for infrastructure
Improve security by managing credentials in Azure Key Vault
Enforce approval-based deployment for governance
Workflow:
1. Terraform code is stored in Azure Repos (or GitHub).
2. Azure DevOps CI Pipeline validates and formats Terraform code.
3. Terraform applies infrastructure changes in Azure.
4. Terraform state file is stored in an Azure Storage Account.
4. Step-by-Step Implementation
Step 1: Set Up Azure DevOps & Terraform Repository
1. Create a new repository in Azure DevOps (or GitHub)
terraform {
backend "azurerm" {
resource_group_name = "MyResourceGroup"
storage_account_name = "myterraformstate"
container_name = "terraform-state"
key = "terraform.tfstate"
}
}
provider "azurerm" {
features {}
}
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: TerraformInstaller@1
inputs:
terraformVersion: '1.2.0'
- script: |
terraform init
terraform validate
displayName: 'Terraform Init & Validate'
3. Save and run the pipeline. This validates Terraform code before deployment.
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- script: |
terraform init
terraform plan -out=tfplan
displayName: 'Terraform Plan'
- task: ManualValidation@0
inputs:
notifyUsers: '[email protected]'
instructions: 'Approve Terraform Apply'
displayName: 'Manual Approval for Apply'
- script: |
terraform apply -auto-approve tfplan
displayName: 'Terraform Apply'
5. Conclusion
This project automates infrastructure provisioning using Terraform and Azure DevOps.
Key Benefits:
✅
✅ Eliminates manual provisioning
Real-Time Example:
A cloud operations team managing a large-scale Azure environment can use this setup to automate
deployments, enforce governance, and improve security.
Project 5: CI/CD Pipeline for a .NET Core
Application Using Azure DevOps
1. Project Scope
In this project, we will build a Continuous Integration and Continuous Deployment (CI/CD) pipeline
in Azure DevOps for a .NET Core web application. The goal is to automate the build, testing, and
deployment of the application to Azure App Service.
Key Features:
✅
✅ Automate code build and testing using Azure DevOps pipelines
✅
✅
Deploy the application to Azure App Service
Implement branch policies to ensure code quality
2. Tools Used
● Azure DevOps – CI/CD automation
● Azure App Service – Hosting the .NET Core application
● GitHub/Azure Repos – Source code repository
● Azure Key Vault – Secrets management
● Azure CLI – To manage Azure resources
● YAML Pipelines – For defining the CI/CD workflow
3. Analysis Approach
Challenges Without CI/CD
● Manual deployment takes time and is error-prone
● Inconsistent environments between development, testing, and production
● No automated testing, leading to deployment failures
● Security risks due to hardcoded credentials
Proposed Solution
✅
By integrating Azure DevOps with .NET Core and Azure App Service, we can:
Workflow:
1. Developers push code to Azure Repos (or GitHub).
2. CI Pipeline builds and tests the application automatically.
3. CD Pipeline deploys the application to Azure App Service.
4. Azure Key Vault stores sensitive configuration data.
5. Rollback mechanism enables safe deployment.
4. Step-by-Step Implementation
Step 1: Set Up Azure DevOps & Repository
1. Create a new repository in Azure DevOps (or GitHub).
Clone the repository and create a sample .NET Core web app:
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
installationPath: $(Agent.ToolsDirectory)/dotnet
- script: |
dotnet restore
dotnet build --configuration Release
displayName: 'Build .NET Core Application'
- script: |
dotnet test --configuration Release
displayName: 'Run Unit Tests'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
displayName: 'Publish Build Artifacts'
4. Save and run the pipeline. This will build and test the .NET Core app automatically.
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
artifactName: 'drop'
targetPath: '$(Build.ArtifactStagingDirectory)'
- task: AzureWebApp@1
inputs:
azureSubscription: 'MyAzureServiceConnection'
appName: 'MyWebApp'
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
deploymentMethod: 'zipDeploy'
displayName: 'Deploy to Azure App Service'
Step 5: Secure Credentials Using Azure Key Vault
Create an Azure Key Vault:
- task: AzureKeyVault@1
inputs:
azureSubscription: 'MyAzureServiceConnection'
keyVaultName: 'MyKeyVault'
secretsFilter: '*'
runAsPreJob: true
- task: AzureWebApp@1
inputs:
azureSubscription: 'MyAzureServiceConnection'
appName: 'MyWebApp'
slotName: 'staging'
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
deploymentMethod: 'zipDeploy'
5. Conclusion
This project automates the CI/CD process for a .NET Core application using Azure DevOps.
Key Benefits:
✅
✅ Automated Build & Testing ensures code quality
Real-Time Example:
A software development team working on a .NET Core web application can use this pipeline to
automate deployments, reduce manual effort, and improve software quality.
Project 6: Implementing Infrastructure as
Code (IaC) Using Terraform and Azure DevOps
1. Project Scope
In this project, we will automate the provisioning of Azure cloud infrastructure using Terraform
within an Azure DevOps pipeline. The goal is to create a fully automated Infrastructure as Code
(IaC) solution that deploys a virtual network, subnets, a virtual machine, and storage accounts on
Azure.
Key Features:
✅
✅ Automate infrastructure provisioning using Terraform
✅
✅
Store Terraform state files securely in Azure Storage
Implement CI/CD pipeline for Terraform deployment
2. Tools Used
● Azure DevOps – CI/CD automation
● Terraform – Infrastructure as Code (IaC)
● Azure Storage Account – Terraform state management
● Azure Virtual Network (VNet) – Network provisioning
● Azure Virtual Machine (VM) – Compute resource
● Azure CLI – Command-line automation
3. Analysis Approach
Challenges Without Infrastructure as Code
● Manual infrastructure setup leads to inconsistencies
● Difficult to replicate environments (dev, staging, prod)
● Security risks due to improper state management
● No version control for infrastructure changes
Proposed Solution
By using Terraform with Azure DevOps, we can:
✅
Workflow:
1. Terraform scripts define infrastructure as code
2. Azure DevOps pipeline applies Terraform to Azure
3. Terraform state is stored in an Azure Storage Account
4. Changes are validated before deployment
5. Infrastructure is deployed/updated automatically
4. Step-by-Step Implementation
Step 1: Set Up Azure DevOps & Repository
1. Create a new repository in Azure DevOps (or GitHub).
terraform {
backend "azurerm" {
resource_group_name = "TerraformStateRG"
storage_account_name = "tfstateaccount"
container_name = "terraform-state"
key = "terraform.tfstate"
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "rg" {
name = "MyTerraformRG"
location = "East US"
}
resource "azurerm_virtual_network" "vnet" {
name = "MyVNet"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "subnet1" {
name = "MySubnet1"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.1.0/24"]
}
resource "azurerm_virtual_machine" "vm" {
name = "MyTerraformVM"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
network_interface_ids = [azurerm_network_interface.nic.id]
vm_size = "Standard_B2s"
storage_os_disk {
name = "myosdisk"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "MyVM"
admin_username = "azureuser"
admin_password = "MySecurePassword123!"
}
os_profile_linux_config {
disable_password_authentication = false
}
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
}
Step 4: Create Terraform CI/CD Pipeline in Azure DevOps
1. Go to Azure DevOps → Pipelines → New Pipeline
2. Select Azure Repos Git or GitHub as the source
3. Choose Starter Pipeline and modify the YAML:
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: TerraformInstaller@0
inputs:
terraformVersion: '1.0.0'
- script: |
terraform init
displayName: 'Initialize Terraform'
- script: |
terraform plan -out=tfplan
displayName: 'Plan Terraform Changes'
- script: |
terraform apply -auto-approve tfplan
displayName: 'Apply Terraform Configuration'
git add .
git commit -m "Added Terraform configuration"
git push origin main
5. Conclusion
This project automates infrastructure provisioning using Terraform with Azure DevOps.
Key Benefits:
✅
✅ Automated Infrastructure Deployment
Real-Time Example:
A DevOps team responsible for managing Azure infrastructure can use this approach to provision,
update, and scale cloud resources efficiently.
Project 7: Implementing Blue-Green
Deployment for an Azure Web App Using
Azure DevOps
1. Project Scope
This project focuses on implementing a Blue-Green deployment strategy for an Azure Web App
using Azure DevOps Pipelines. The goal is to reduce downtime and minimize risk when deploying
new application versions by maintaining two identical environments (Blue and Green).
Key Features:
✅
✅ Automate Blue-Green deployment using Azure DevOps
2. Tools Used
● Azure DevOps Pipelines – Automate CI/CD
● Azure App Service – Web application hosting
● App Service Deployment Slots – Blue-Green switch
● Azure Monitor – Track application performance
● Azure Traffic Manager – Route traffic between slots
● GitHub or Azure Repos – Store application source code
3. Analysis Approach
Challenges With Traditional Deployments
● Application downtime during deployment
● High risk of breaking production with new updates
● Rollback process is slow and manual
● Testing in production impacts users
✅
✅
Deploy and test the new version in the Green slot
Switch traffic to the Green slot only after successful validation
Keep Blue slot as a backup for instant rollback if needed
Workflow:
1. Blue Slot (Current Production) runs the existing app
2. Green Slot (Staging) is used for new deployments
3. Traffic is routed to Green slot after testing
4. If issues arise, rollback instantly by swapping slots
4. Step-by-Step Implementation
Step 1: Create an Azure Web App with Deployment Slots
1. Go to Azure Portal → App Services → Create a Web App
○ Name: myapp-bluegreen
○ Runtime: Node.js / .NET / Python / Java (as needed)
○ Plan: Standard or Premium (supports deployment slots)
2. Create a deployment slot:
○ In the Web App, go to Deployment Slots
○ Click + Add Slot
○ Name the slot green
○ Clone settings from the Blue slot
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration Release --output
$(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: AzureWebApp@1
inputs:
azureSubscription: 'MyAzureServiceConnection'
appType: 'webApp'
appName: 'myapp-bluegreen'
deployToSlotOrASE: true
resourceGroupName: 'MyResourceGroup'
slotName: 'green'
package: '$(Build.ArtifactStagingDirectory)/*.zip'
displayName: 'Deploy to Green Slot'
- script: echo "Swapping Blue and Green slots"
displayName: 'Swap Slots'
- task: AzureCLI@2
inputs:
azureSubscription: 'MyAzureServiceConnection'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp deployment slot swap --resource-group MyResourceGroup --name
myapp-bluegreen --slot green
displayName: 'Swap Slots Blue <-> Green'
azureSubscription: '$(AZURE_SERVICE_CONNECTION)'
git add .
git commit -m "Added Blue-Green deployment pipeline"
git push origin main
1. Azure DevOps Pipeline triggers the deployment to the Green slot
2. Manually verify the Green slot before switching traffic
3. Run slot swap command to make Green the new production
5. Conclusion
Key Benefits of Blue-Green Deployment:
✅
✅ Zero-Downtime Deployment – Users experience no service interruptions
Key Features:
✅
✅ Deploy a new version to a small percentage of traffic
2. Tools Used
● Azure Kubernetes Service (AKS) – Hosts the containerized application
● Azure DevOps Pipelines – Automates CI/CD
● Helm – Manages Kubernetes deployments
● Kustomize – Manages environment-specific configurations
● Prometheus + Grafana – Monitors deployment performance
● Nginx Ingress Controller – Manages Canary traffic routing
3. Analysis Approach
Challenges With Traditional Deployments
● Deploying to all users at once increases risk
● Difficult to test new features safely in production
● Rollback is complex if issues occur after full deployment
✅
✅
Monitor performance with Prometheus and Grafana
Gradually increase rollout percentage if no issues occur
Rollback immediately if failures are detected
Workflow:
1. Deploy the current stable version (V1) to 100% of users
2. Deploy new version (V2) to 10% of users (Canary)
3. Monitor logs, metrics, and user feedback
4. Gradually increase to 25%, 50%, then 100%
5. Rollback to V1 if failures occur
4. Step-by-Step Implementation
Step 1: Set Up Azure Kubernetes Service (AKS)
Create an AKS Cluster:
kubectl apply -f
https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/prov
ider/cloud/deploy.yaml
Step 2: Configure CI/CD Pipeline in Azure DevOps
1. Go to Azure DevOps → Pipelines → Create New Pipeline
2. Select Repository (Azure Repos or GitHub)
3. Choose Starter Pipeline and Update YAML
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Kubernetes@1
displayName: 'Deploy Canary Version'
inputs:
connectionType: 'Azure Resource Manager'
azureSubscription: 'MyAzureServiceConnection'
azureResourceGroup: 'MyResourceGroup'
kubernetesCluster: 'myAKSCluster'
namespace: 'default'
command: 'apply'
useConfigurationFile: true
configuration: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
version: canary
spec:
containers:
- name: myapp
image: myacr.azurecr.io/myapp:v2
ports:
- containerPort: 80
resources:
limits:
cpu: "500m"
memory: "256Mi"
requests:
cpu: "250m"
memory: "128Mi"
- script: echo "Applying Traffic Routing Rules"
displayName: 'Route 10% Traffic to Canary'
- task: Kubernetes@1
inputs:
connectionType: 'Azure Resource Manager'
azureSubscription: 'MyAzureServiceConnection'
kubernetesCluster: 'myAKSCluster'
namespace: 'default'
command: 'apply'
useConfigurationFile: true
configuration: |
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp-ingress
spec:
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myapp
port:
number: 80
canary:
weight: 10
5. Conclusion
Key Benefits of Canary Deployment:
✅
✅ Reduces Risk – Only a small % of users are affected if issues arise
Key Features:
✅
✅ Automate Azure infrastructure provisioning
2. Tools Used
● Azure DevOps Pipelines – Automates Terraform execution
● Terraform – Defines and deploys infrastructure
● Azure Resource Manager (ARM) – Manages Azure resources
● Azure Key Vault – Stores sensitive Terraform credentials
● Azure Storage Account – Stores Terraform state files
3. Analysis Approach
Challenges Without IaC:
❌
❌ Manual deployment is time-consuming and error-prone
4. Step-by-Step Implementation
Step 1: Install Terraform Locally
Download and install Terraform:
wget
https://releases.hashicorp.com/terraform/1.2.0/terraform_1.2.0_linux_amd64.zip
unzip terraform_1.2.0_linux_amd64.zip
sudo mv terraform /usr/local/bin/
terraform --version
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "rg" {
name = "my-devops-rg"
location = "East US"
}
resource "azurerm_virtual_network" "vnet" {
name = "my-vnet"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "subnet" {
name = "my-subnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["10.0.1.0/24"]
}
2. variables.tf (Defines Variables)
variable "location" {
default = "East US"
}
variable "resource_group_name" {
default = "my-devops-rg"
}
terraform {
backend "azurerm" {
resource_group_name = "terraform-rg"
storage_account_name = "terraformstorageacct"
container_name = "tfstate"
key = "terraform.tfstate"
}
}
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: TerraformInstaller@0
displayName: 'Install Terraform'
inputs:
terraformVersion: '1.2.0'
- script: |
terraform init
displayName: 'Initialize Terraform'
- script: |
terraform validate
displayName: 'Validate Terraform Configuration'
- script: |
terraform plan -out=tfplan
displayName: 'Terraform Plan'
- script: |
terraform apply -auto-approve tfplan
displayName: 'Apply Terraform Changes'
- task: AzureKeyVault@1
inputs:
azureSubscription: 'MyAzureSubscription'
keyVaultName: 'my-keyvault'
secretsFilter: '*'
Key Features:
✅
✅ Deploy new versions without downtime
2. Tools Used
● Azure DevOps Pipelines – Automates application deployment
● Azure App Services – Hosts web applications
● Azure Traffic Manager – Routes traffic between Blue & Green
● Azure Repos – Stores application source code
● Azure CLI & PowerShell – Manages deployments
3. Analysis Approach
Traditional Deployment Issues:
❌
❌ Downtime when updating production
4. Step-by-Step Implementation
Step 1: Create Two Azure App Service Instances
Create a Resource Group:
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
blueAppServiceName: 'blue-app'
greenAppServiceName: 'green-app'
azureSubscription: 'AzureServiceConnection'
stages:
- stage: DeployToGreen
jobs:
- job: Deploy
steps:
- task: AzureWebApp@1
displayName: 'Deploy to Green App'
inputs:
azureSubscription: $(azureSubscription)
appName: $(greenAppServiceName)
package: $(Build.ArtifactStagingDirectory)/app.zip
- stage: SwitchTraffic
dependsOn: DeployToGreen
jobs:
- job: TrafficManagerUpdate
steps:
- script: |
az network traffic-manager endpoint update --resource-group bluegreen-rg
--profile-name bluegreen-tm --name green-endpoint --weight 100
az network traffic-manager endpoint update --resource-group bluegreen-rg
--profile-name bluegreen-tm --name blue-endpoint --weight 0
displayName: 'Switch Traffic to Green'
- stage: Rollback
condition: failed()
dependsOn: SwitchTraffic
jobs:
- job: RevertTraffic
steps:
- script: |
az network traffic-manager endpoint update --resource-group bluegreen-rg
--profile-name bluegreen-tm --name blue-endpoint --weight 100
az network traffic-manager endpoint update --resource-group bluegreen-rg
--profile-name bluegreen-tm --name green-endpoint --weight 0
displayName: 'Rollback to Blue'
Step 4: Test and Verify the Deployment
1. Trigger the Azure DevOps pipeline
2. Verify Green environment updates correctly
3. Ensure traffic switches to Green smoothly
4. If rollback triggers, confirm traffic returns to Blue
5. Conclusion
Key Benefits of Blue-Green Deployment:
✅
✅ Zero downtime deployment