{"id":25830400,"url":"https://github.com/hrushi-d/cloud-native-webapp-deployment","last_synced_at":"2025-02-28T19:19:50.240Z","repository":{"id":279489010,"uuid":"938982820","full_name":"Hrushi-d/Cloud-Native-Webapp-Deployment","owner":"Hrushi-d","description":"A complete cloud-native web application deployment solution using Azure DevOps and Kubernetes. This repository contains everything needed to deploy and manage a containerized web application in Azure.","archived":false,"fork":false,"pushed_at":"2025-02-25T20:26:07.000Z","size":114,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T21:18:53.703Z","etag":null,"topics":["aks-kubernetes-cluster","azurecloud","azuredevops","bash-scripting","cicd","docker","git","kubernetes","terraform"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hrushi-d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-25T20:02:04.000Z","updated_at":"2025-02-25T20:26:11.000Z","dependencies_parsed_at":"2025-02-25T21:18:58.378Z","dependency_job_id":"0d2dd447-549c-4e00-a14d-66f10cc71085","html_url":"https://github.com/Hrushi-d/Cloud-Native-Webapp-Deployment","commit_stats":null,"previous_names":["hrushi-d/cloud-native-webapp-deployment"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hrushi-d%2FCloud-Native-Webapp-Deployment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hrushi-d%2FCloud-Native-Webapp-Deployment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hrushi-d%2FCloud-Native-Webapp-Deployment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hrushi-d%2FCloud-Native-Webapp-Deployment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hrushi-d","download_url":"https://codeload.github.com/Hrushi-d/Cloud-Native-Webapp-Deployment/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241210088,"owners_count":19927784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aks-kubernetes-cluster","azurecloud","azuredevops","bash-scripting","cicd","docker","git","kubernetes","terraform"],"created_at":"2025-02-28T19:19:49.383Z","updated_at":"2025-02-28T19:19:50.231Z","avatar_url":"https://github.com/Hrushi-d.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deploying a Web Application Using Azure DevOps\n\n## Introduction\n\nThis guide provides a comprehensive walkthrough for deploying a web application using Azure Free Tier. The project leverages cloud infrastructure, containerization, and CI/CD automation to create a production-ready deployment pipeline. Throughout this guide, you'll gain hands-on experience with:\n\n- Setting up Azure infrastructure using Terraform and Azure CLI\n- Containerizing applications with Docker\n- Orchestrating containers with Azure Kubernetes Service (AKS)\n- Implementing CI/CD pipelines with Azure DevOps\n- Monitoring Kubernetes workloads in Azure\n\nBy following this guide, you'll create a fully automated deployment pipeline for a web application, gaining practical experience with industry-standard DevOps practices.\n\n---\n\n## 1. Provisioning Infrastructure\n\n### Using Terraform\n\nInfrastructure as Code (IaC) allows you to define and provision your cloud resources in a consistent, repeatable manner. We'll use Terraform to create the following resources:\n\n```hcl\nprovider \"azurerm\" {\n  features {}\n}\n\nresource \"azurerm_resource_group\" \"rg\" {\n  name     = \"webapp-rg\"\n  location = \"East US\"\n}\n\nresource \"azurerm_virtual_network\" \"vnet\" {\n  name                = \"webapp-vnet\"\n  location            = azurerm_resource_group.rg.location\n  resource_group_name = azurerm_resource_group.rg.name\n  address_space       = [\"10.0.0.0/16\"]\n}\n\nresource \"azurerm_kubernetes_cluster\" \"aks\" {\n  name                = \"webapp-aks\"\n  location            = azurerm_resource_group.rg.location\n  resource_group_name = azurerm_resource_group.rg.name\n  dns_prefix          = \"webappaks\"\n  default_node_pool {\n    name       = \"default\"\n    node_count = 2\n    vm_size    = \"Standard_DS2_v2\"\n  }\n  identity {\n    type = \"SystemAssigned\"\n  }\n}\n```\n\n### Using Azure CLI\n\nAlternatively, you can provision infrastructure using Azure CLI. This involves:\n\n1. Creating a resource group\n2. Setting up a virtual network\n3. Configuring network security groups with proper inbound/outbound rules:\n   - PORT 80 for HTTP traffic\n   - PORT 22 for SSH access\n4. Creating public IPs and network interfaces for VMs\n5. Provisioning two virtual machines:\n   - **Dev VM** for application development and testing\n   - **Ops VM** for managing deployments and dependencies\n6. Creating an AKS cluster for production deployment\n\n### Implementation Steps\n\n1. **Using Terraform**:\n   - Install Terraform and configure Azure credentials\n   - Define infrastructure in Terraform configuration files\n   - Initialize with `terraform init`\n   - Apply the configuration using `terraform apply`\n   - Verify resources in Azure Portal\n\n2. **Using Azure CLI**:\n   - Log in to Azure Portal and open Cloud CLI\n   - Create resource group: `az group create --name webapp-rg --location eastus`\n   - Create virtual network and subnets\n   - Create network security groups with appropriate rules\n   - Provision VMs and necessary networking components\n   - Create AKS cluster: `az aks create --resource-group webapp-rg --name webapp-aks --node-count 2 --enable-addons monitoring --generate-ssh-keys`\n\n---\n\n## 2. Configuration Management\n\nOnce the infrastructure is provisioned, we need to configure our VMs with the necessary tools and services.\n\n### Using Azure VM Run Command\n\nWe'll use Azure CLI's `az vm run-command` to automate VM configurations without direct login:\n\n```bash\naz vm run-command invoke \\\n  --resource-group webapp-rg \\\n  --name dev-vm \\\n  --command-id RunShellScript \\\n  --scripts \"apt-get update \u0026\u0026 apt-get install -y docker.io \u0026\u0026 systemctl enable docker \u0026\u0026 systemctl start docker\"\n```\n\n### Configuration Steps\n\n1. Update package lists: `apt-get update`\n2. Install Docker: `apt-get install -y docker.io`\n3. Enable and start Docker service: `systemctl enable docker \u0026\u0026 systemctl start docker`\n4. Verify configurations on both VMs:\n   ```bash\n   docker --version\n   systemctl status docker\n   ```\n\nConfigure both the Dev VM and Ops VM following the same process to ensure consistency.\n\n---\n\n## 3. Deploying the Web Application\n\n### Manual Deployment Process\n\nBefore automating, it's valuable to understand the manual deployment process:\n\n1. **Development (Dev VM)**:\n   - Clone the GitHub repository containing the web application\n   - Create a Dockerfile to containerize the application:\n     ```dockerfile\n     FROM nginx:latest\n     COPY index.html /usr/share/nginx/html/index.html\n     COPY assets /usr/share/nginx/html/assets\n     COPY forms /usr/share/nginx/html/forms\n     COPY portfolio-details.html /usr/share/nginx/html/portfolio-details.html\n     EXPOSE 80\n     CMD [\"nginx\", \"-g\", \"daemon off;\"]\n     ```\n   - Build the Docker image: `docker build -t webapp:latest .`\n   - Test locally: `docker run -d -p 80:80 webapp:latest`\n   - Tag the image for Docker Hub: `docker tag webapp:latest username/webapp:latest`\n   - Push to Docker Hub: `docker push username/webapp:latest`\n\n2. **Deployment to AKS**:\n   - Connect to the AKS cluster: `az aks get-credentials --resource-group webapp-rg --name webapp-aks`\n   - Create a Kubernetes deployment:\n     ```yaml\n     apiVersion: apps/v1\n     kind: Deployment\n     metadata:\n       name: auto-nginx-portfolio\n       labels:\n         app: auto-nginx-portfolio\n     spec:\n       replicas: 3\n       selector:\n         matchLabels:\n           app: auto-nginx-portfolio\n       template:\n         metadata:\n           labels:\n             app: auto-nginx-portfolio\n         spec:\n           containers:\n           - name: auto-nginx-portfolio\n             image: hrush18/auto-nginx-portfolio:latest\n             ports:\n             - containerPort: 80\n     ```\n   - Apply the deployment: `kubectl apply -f deployment.yaml`\n   - Expose the deployment as a service:\n     ```yaml\n     apiVersion: v1\n     kind: Service\n     metadata:\n       name: auto-nginx-portfolio-service\n       labels:\n         app: auto-nginx-portfolio\n     spec:\n       type: LoadBalancer\n       selector:\n         app: auto-nginx-portfolio\n       ports:\n         - protocol: TCP\n           port: 80\n           targetPort: 80\n     ```\n   - Apply the service: `kubectl apply -f service.yaml`\n   - Verify the deployment: `kubectl get pods,svc`\n\n---\n\n## 4. Automating Deployment with Azure DevOps\n\nAzure DevOps provides powerful tools for implementing CI/CD pipelines. We'll set up continuous integration and continuous deployment to automate the entire process from code commit to production deployment.\n\n### 4.1 Setting Up Azure DevOps Project\n\n1. **Create an Azure DevOps Organization (if you don't have one)**:\n   - Go to [dev.azure.com](https://dev.azure.com)\n   - Sign in with your Microsoft account\n   - Create a new organization or use an existing one\n\n2. **Create a New Project**:\n   - Click on \"New project\"\n   - Enter a project name (e.g., \"WebApp-Deployment\")\n   - Select visibility (private or public)\n   - Click \"Create\"\n\n3. **Set Up Repositories**:\n   - Navigate to Repos in your project\n   - Create two repositories:\n     - **Project Repository**: `portfolio` (for application code)\n     - **Admin Repository**: `admin_portfolio` (for deployment configurations)\n   - Initialize both repositories with a README file\n\n4. **Clone Repositories**:\n   - Get the clone URL for each repository from Azure DevOps\n   - Clone to the respective VMs:\n     ```bash\n     # On Dev VM\n     git clone https://dev.azure.com/organization/project/_git/portfolio\n     \n     # On Ops VM\n     git clone https://dev.azure.com/organization/project/_git/admin_portfolio\n     ```\n\n### 4.2 Creating Service Connections\n\nService connections allow Azure DevOps to interact with external services like Docker Hub and Azure.\n\n1. **Create Docker Hub Service Connection**:\n   - Go to Project Settings \u003e Service connections\n   - Click \"New service connection\"\n   - Select \"Docker Registry\"\n   - Enter your Docker Hub credentials\n   - Name the connection (e.g., \"DockerHubConnection\")\n   - Click \"Save\"\n\n2. **Create Azure Resource Manager Service Connection**:\n   - Go to Project Settings \u003e Service connections\n   - Click \"New service connection\"\n   - Select \"Azure Resource Manager\"\n   - Follow the authentication steps\n   - Select your subscription and resource group\n   - Name the connection (e.g., \"AzureConnection\")\n   - Click \"Save\"\n\n### 4.3 Setting Up the CI Pipeline\n\nThe CI pipeline will automate the build and push of Docker images when code changes are detected.\n\n1. **Create a New Pipeline**:\n   - Go to Pipelines \u003e Pipelines\n   - Click \"Create Pipeline\"\n   - Select \"Azure Repos Git\" as the source\n   - Select the `portfolio` repository\n\n2. **Configure the Pipeline**:\n   - Select \"Starter pipeline\" or \"Empty job\"\n   - Replace the YAML content with the following:\n\n```yaml\ntrigger:\n- main  # Trigger on changes to main branch\n\npool:\n  vmImage: 'ubuntu-latest'  # Use Ubuntu-based agent\n\nvariables:\n  dockerHubUser: 'yourDockerHubUsername'\n  imageName: 'auto-nginx-portfolio'\n  imageTag: '$(Build.BuildId)'  # Use build ID as tag\n\nstages:\n- stage: Build\n  displayName: 'Build and Push Docker Image'\n  jobs:\n  - job: BuildAndPush\n    steps:\n    - checkout: self  # Check out the repository\n\n    - task: Docker@2\n      displayName: 'Build Docker Image'\n      inputs:\n        command: build\n        repository: $(dockerHubUser)/$(imageName)\n        dockerfile: '$(Build.SourcesDirectory)/Dockerfile'\n        tags: |\n          $(imageTag)\n          latest\n\n    - task: Docker@2\n      displayName: 'Push Docker Image'\n      inputs:\n        command: push\n        containerRegistry: 'DockerHubConnection'  # Use the service connection\n        repository: $(dockerHubUser)/$(imageName)\n        tags: |\n          $(imageTag)\n          latest\n\n    # Trigger the image tag update script\n    - task: Bash@3\n      displayName: 'Update Deployment Configuration'\n      inputs:\n        targetType: 'inline'\n        script: |\n          # Clone admin repository\n          git clone https://$(System.AccessToken)@dev.azure.com/organization/project/_git/admin_portfolio /tmp/admin_portfolio\n          cd /tmp/admin_portfolio\n          \n          # Update image tag in deployment.yaml\n          sed -i \"s|image: .*|image: $(dockerHubUser)/$(imageName):$(imageTag)|\" deployment.yaml\n          \n          # Configure Git\n          git config --global user.name \"Azure DevOps Pipeline\"\n          git config --global user.email \"pipeline@example.com\"\n          \n          # Commit and push changes\n          git add deployment.yaml\n          git commit -m \"Update image tag to $(imageTag)\"\n          git push\n```\n\n3. **Save and Run the Pipeline**:\n   - Click \"Save and run\"\n   - Commit the YAML file to your repository\n   - Watch the pipeline execution\n\n### 4.4 Setting Up the CD Pipeline\n\nThe CD pipeline will deploy the application to AKS when the deployment configuration changes.\n\n1. **Create a New Pipeline**:\n   - Go to Pipelines \u003e Pipelines\n   - Click \"Create Pipeline\"\n   - Select \"Azure Repos Git\" as the source\n   - Select the `admin_portfolio` repository\n\n2. **Configure the Pipeline**:\n   - Select \"Starter pipeline\" or \"Empty job\"\n   - Replace the YAML content with the following:\n\n```yaml\ntrigger:\n- main  # Trigger on changes to main branch\n\npool:\n  vmImage: 'ubuntu-latest'  # Use Ubuntu-based agent\n\nstages:\n- stage: Deploy\n  displayName: 'Deploy to AKS'\n  jobs:\n  - job: DeployToAKS\n    steps:\n    - checkout: self  # Check out the repository\n\n    # Install kubectl\n    - task: KubectlInstaller@0\n      displayName: 'Install kubectl'\n      inputs:\n        kubectlVersion: 'latest'\n\n    # Set Kubernetes context\n    - task: AzureCLI@2\n      displayName: 'Set Kubernetes Context'\n      inputs:\n        azureSubscription: 'AzureConnection'  # Use the service connection\n        scriptType: 'bash'\n        scriptLocation: 'inlineScript'\n        inlineScript: |\n          az aks get-credentials --resource-group webapp-rg --name webapp-aks --overwrite-existing\n\n    # Apply Kubernetes manifests\n    - task: Kubernetes@1\n      displayName: 'Apply Deployment'\n      inputs:\n        connectionType: 'None'\n        command: 'apply'\n        useConfigurationFile: true\n        configuration: '$(Build.SourcesDirectory)/deployment.yaml'\n\n    - task: Kubernetes@1\n      displayName: 'Apply Service'\n      inputs:\n        connectionType: 'None'\n        command: 'apply'\n        useConfigurationFile: true\n        configuration: '$(Build.SourcesDirectory)/service.yaml'\n\n    # Verify deployment\n    - task: Bash@3\n      displayName: 'Verify Deployment'\n      inputs:\n        targetType: 'inline'\n        script: |\n          # Wait for deployment to roll out\n          kubectl rollout status deployment/auto-nginx-portfolio\n          \n          # Get service info\n          echo \"Service details:\"\n          kubectl get service auto-nginx-portfolio-service -o wide\n          \n          # Get deployment info\n          echo \"Deployment details:\"\n          kubectl get deployment auto-nginx-portfolio -o wide\n```\n\n3. **Save and Run the Pipeline**:\n   - Click \"Save and run\"\n   - Commit the YAML file to your repository\n   - Watch the pipeline execution\n\n### 4.5 Setting Up Webhook Triggers\n\nTo fully automate the process, set up webhook triggers between repositories:\n\n1. **Configure CI Pipeline Trigger**:\n   - Ensure the CI pipeline triggers on changes to the main branch of the `portfolio` repository\n\n2. **Configure CD Pipeline Trigger**:\n   - Ensure the CD pipeline triggers on changes to the main branch of the `admin_portfolio` repository\n\n### 4.6 Custom Image Tagging Script (Advanced)\n\nFor more advanced scenarios, create a dedicated script for image tagging:\n\n```bash\n#!/bin/bash\n# File: docker_image_tag.sh\n\n# Ensure a BUILD_ID is provided\nif [ -z \"$1\" ]; then\n  echo \"Usage: $0 \u003cBUILD_ID\u003e\"\n  exit 1\nfi\nBUILD_ID=$1\n\n# Define repository variables\nADMIN_PORTFOLIO_REPO=\"https://username:token@dev.azure.com/username/project/_git/admin_portfolio\"\nDEPLOYMENT_FILE=\"deployment.yaml\"\n\n# Clone the admin_portfolio repository\ngit clone $ADMIN_PORTFOLIO_REPO /tmp/admin_portfolio\ncd /tmp/admin_portfolio\n\n# Pull the latest changes\ngit pull origin main\n\n# Update the image tag in the deployment.yaml file\nsed -i \"s|image: .*|image: hrush18/auto-nginx-portfolio:${BUILD_ID}|\" ${DEPLOYMENT_FILE}\n\n# Configure Git user\ngit config --global user.name \"username\"\ngit config --global user.email \"email@example.com\"\n\n# Commit and push changes\ngit add ${DEPLOYMENT_FILE}\ngit commit -m \"Update image tag to ${BUILD_ID}\"\ngit pull origin main --rebase\ngit push origin main\n\n# Clean up\ncd -\nrm -rf /tmp/admin_portfolio\n```\n\n### 4.7 Setting Up Pipeline Variables and Secrets\n\nSecure sensitive information using variables and secrets:\n\n1. **Create Variables**:\n   - Go to Pipelines \u003e Library\n   - Create a variable group (e.g., \"DeploymentVariables\")\n   - Add variables:\n     - `dockerHubUser`: Your Docker Hub username\n     - `imageName`: The name of your Docker image\n     - `resourceGroup`: Your Azure resource group name\n     - `aksClusterName`: Your AKS cluster name\n\n2. **Add Secrets**:\n   - Add sensitive variables as secrets:\n     - `dockerHubPassword`: Your Docker Hub password (mark as secret)\n     - `gitPAT`: Personal Access Token for Git operations (mark as secret)\n\n3. **Link Variables to Pipelines**:\n   - In each pipeline YAML, add:\n   ```yaml\n   variables:\n     - group: DeploymentVariables\n   ```\n\n### 4.8 Setting Up Environment Approvals and Gates\n\nFor production deployments, set up approval workflows:\n\n1. **Create an Environment**:\n   - Go to Pipelines \u003e Environments\n   - Create a new environment (e.g., \"Production\")\n   - Configure approval checks:\n     - Add approvers who must approve deployments\n     - Set timeout period for approvals\n\n2. **Update CD Pipeline to Use Environment**:\n   - Modify the CD pipeline YAML:\n   ```yaml\n   stages:\n   - stage: Deploy\n     displayName: 'Deploy to AKS'\n     jobs:\n     - deployment: DeployToAKS\n       environment: Production  # Use the environment with approvals\n       strategy:\n         runOnce:\n           deploy:\n             steps:\n             # Deployment steps...\n   ```\n\n### 4.9 Setting Up Pipeline Notifications\n\nConfigure notifications to keep the team informed:\n\n1. **Configure Notifications**:\n   - Go to Project Settings \u003e Notifications\n   - Add subscription for pipeline events:\n     - Pipeline run completed\n     - Pipeline run failed\n     - Deployment approval pending\n\n2. **Set Up Microsoft Teams/Slack Integration**:\n   - Add a webhook to your Teams/Slack channel\n   - Configure Azure DevOps to send notifications to the webhook\n\n### 4.10 Monitoring CI/CD Performance\n\nTrack pipeline performance metrics:\n\n1. **View Pipeline Analytics**:\n   - Go to Pipelines \u003e Analytics\n   - Monitor:\n     - Pipeline duration\n     - Success rate\n     - Failure points\n     - Wait time for approvals\n\n2. **Set Up Dashboards**:\n   - Create custom dashboards with pipeline widgets\n   - Add metrics for deployment frequency and success rates\n\n---\n\n## 5. Monitoring Kubernetes with Azure Portal\n\nAzure provides monitoring capabilities for Kubernetes workloads, even in the Free Tier.\n\n### Basic Monitoring Features\n\n1. **Resource Usage Metrics**:\n   - CPU and memory utilization\n   - Node status and health\n   - Pod status and health\n\n2. **Log Analytics**:\n   - Container logs\n   - Error monitoring\n   - Performance insights\n\n3. **Azure Dashboard**:\n   - Comprehensive overview of your Azure DevOps workflows\n   - Pipeline execution status\n   - Deployment status and history\n\n### Accessing Monitoring\n\n1. Navigate to your AKS cluster in the Azure Portal\n2. Select \"Insights\" or \"Metrics\" from the menu\n3. View real-time and historical data on cluster performance\n\n---\n\n## Conclusion\n\nThis project demonstrates a complete DevOps workflow for deploying web applications using Azure services. By following this guide, you've learned how to:\n\n- Provision infrastructure using Terraform or Azure CLI\n- Configure VMs with necessary tools and services\n- Containerize a web application using Docker\n- Deploy applications to Azure Kubernetes Service\n- Automate the entire deployment process using Azure DevOps CI/CD pipelines\n- Monitor Kubernetes workloads using Azure Portal\n\nThese skills provide a solid foundation for implementing DevOps practices in cloud environments, enabling more efficient and reliable software delivery.performance\n\n---\n\n## Contact Us 📧\n\nHave questions, feedback, or need assistance? Reach out to:\n- Email: [hrushikeshdagwar@gmail.com](mailto:hrushikeshdagwar@gmail.com)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrushi-d%2Fcloud-native-webapp-deployment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrushi-d%2Fcloud-native-webapp-deployment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrushi-d%2Fcloud-native-webapp-deployment/lists"}