This repository contains an implementation of the Blue-Green Deployment strategy, which allows for seamless application updates with minimal downtime. This approach involves maintaining two identical environments: Blue (current live version) and Green (new version). This allows for quick switching between versions to ensure high availability and reliability.
- Seamless switching between Blue and Green environments
- Automated deployment and rollback capabilities
- Integration with CI/CD pipelines
- Monitoring and logging for both environments
![Architecture Diagram][architecture.png]
This diagram illustrates the architecture of the Blue-Green Deployment strategy implemented in this project.
-
Clone the repository:
git clone https://github.com/yourusername/blue-green-d.git cd blue-green-d
-
Build the Docker images:
docker build -t your-image-name:latest .
-
Deploy to Kubernetes:
kubectl apply -f k8s/deployment.yaml
To switch between Blue and Green environments, use the following commands:
-
To set the Green environment live:
kubectl apply -f k8s/green-service.yaml
-
To set the Blue environment live:
kubectl apply -f k8s/blue-service.yaml
The deployment process for the Blue-Green Deployment strategy is organized into several clear stages, integrated into a CI/CD pipeline. This ensures a smooth transition from the development phase to production. The stages are as follows:
The deployment process for the Blue-Green Deployment strategy is structured into several stages within the CI/CD pipeline, ensuring a seamless transition from development to production. The stages are as follows:
- Developers push code changes to the repository.
- The CI/CD pipeline is triggered, checking out the latest code:
git checkout main
- Perform static code analysis using SonarQube to ensure code quality and maintainability.
- Any issues are reported, and developers must address them before proceeding.
-
Docker Build:
- Build the Docker image from the updated code:
docker build -t your-image-name:latest .
- Build the Docker image from the updated code:
-
Docker Push:
- Push the newly built image to a container registry:
docker push your-image-name:latest
- Push the newly built image to a container registry:
- Trivy Scan:
- Scan the Docker image for vulnerabilities using Trivy:
trivy image your-image-name:latest
- Scan the Docker image for vulnerabilities using Trivy:
- Review scan results and address any critical vulnerabilities.
- MySQL Service Deployment:
- Deploy or update the MySQL service required by the application. Ensure the database schema is up to date.
- Deploy the application using Kubernetes manifests to the Green environment:
kubectl apply -f k8s/green-deployment.yaml
- Once deployed, switch the production traffic to the Green environment:
kubectl apply -f k8s/green-service.yaml
- Verify the deployment by conducting:
- Smoke Tests: Check basic functionality.
- End-to-End Tests: Ensure the entire application workflow functions correctly.
- Load Testing: Validate performance under expected load.
- Monitor the application using monitoring tools (e.g., Prometheus, Grafana) to track metrics and logs.
- Gather user feedback to identify any issues.
- If issues are detected, quickly rollback to the Blue environment:
kubectl apply -f k8s/blue-service.yaml
- After successful validation and stabilization of the Green environment, decommission the Blue environment or prepare it for the next deployment cycle.
This project is licensed under the MIT License - see the LICENSE file for details.
- Blue-Green Deployment - Martin Fowler
- Aditya
- Other resources and inspirations.