Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/psimakov/gcp-mig-simple

Zero-Downtime Blue/Green VM Deployments with Managed Instance Groups, Cloud Build & Terraform -- a Google Cloud Platform Demo
https://github.com/psimakov/gcp-mig-simple

cloud-build google-cloud-platform managed-instance-groups terraform

Last synced: about 1 month ago
JSON representation

Zero-Downtime Blue/Green VM Deployments with Managed Instance Groups, Cloud Build & Terraform -- a Google Cloud Platform Demo

Awesome Lists containing this project

README

        

# Zero-Downtime Blue/Green VM Deployments with Managed Instance Groups, Cloud Build & Terraform
*a Google Cloud Platform Demo*

## Summary

This repository provides source code for zero-downtime blue/green VM deployments using Cloud Build and Terraform.

It configures multiple regional external HTTP(S) load balancers and deploys a demo application to Compute Engine VMs in managed instance groups (MIGs). It adds Cloud Build triggers to start deployment automatically when configuration file changes in Source Code Repository.

You can watch the video of this demo running and follow the code walkthrough. You can also run this demo in your own project.

## Video: Live Demo & Code Walkthrough

[](https://youtu.be/7-jO5OGPUxM)

## Do It Yourself

> **Warning**
>
> This project is for **advanced** Google Cloud Platform infrastructure developers and SRE. If you decide to clone and run any code from this repository, **you will be billed** for the real infrastructure it creates. We rely on unattended automation, which can make it difficult for you to manage your project manually. We use custom VPCs with public IP addresses, which can make your project **vulnerable to attacks**. If you are a novice GCP user and just want to learn -- watch the video above instead.

> **Note**
>
> Take a pause here if you are a developer in a large enterprise company that already uses Google Cloud Platform. Remember that all your projects are subject to foundational setup of your organization and its landing zones ([link](https://cloud.google.com/architecture/landing-zones)). There maybe org policy restrictions (for example: on using regions or external IP addresses) that will break this demo. Reach out to the team that manages GCP in your organization to discuss where and how you can run this demo following their policies.

Anyone can run this demo on their own. Here is how:

* create new Google Cloud Platform project
* enable billing, which is required
* install `gcloud` CLI ([link](https://cloud.google.com/sdk/docs/install)) or use your project Cloud Shell
* set SDK default project, by executing
```
gcloud config set project
```
* execute setup script
* run it directly from our GitHub repo:
```
bash <(curl https://raw.githubusercontent.com/psimakov/gcp-mig-simple/main/setup.sh)
```
* or, fetch, review, and then run it:
```
curl https://raw.githubusercontent.com/psimakov/gcp-mig-simple/main/setup.sh -o setup.sh
bash ./setup.sh
```
* follow on-screen instructions
* trigger deployment by committing configuration change
```
mkdir ~/work
cd ~/work
gcloud source repos clone copy-of-gcp-mig-simple
cd ./copy-of-gcp-mig-simple

nano infra/main.tfvars

git add .
git commit -m "Promote green"
git push
```
* visit Cloud Build History page to see progress of execution
* review Cloud Build apply pipeline logs for deployment IP addresses
* at the end, delete all created resources
```
bash <(curl https://raw.githubusercontent.com/psimakov/gcp-mig-simple/main/teardown.sh)
```

Good luck!

## Slides

### Technical Architecture

#### High level architecture of generic blue/green deployment

#### Detailed architecture of regional external HTTP(S) load balancer with managed instance group (MIG) backend ([link](https://cloud.google.com/load-balancing/docs/https/setting-up-reg-ext-https-lb))

#### Detailed architecture of DevOps workflow

### Bootstrapping

#### Setup shell script is executed by developer

#### Bootstrap Cloud Build is executed

#### Cloud Source Repository is created

#### Cloud Build triggers are created

### GitOps Deployment

#### Deployment is triggered when developer commits configuration change

#### Cloud Build applies Terraform plan

#### All application serving components including three load balancers, blue and green MIGs and their VMs are now live

#### Managed instance groups (MIGs) were created

#### Virtual machine instances (VMs) have started

#### External IP addresses were assigned

### Clean Up

#### Cloud Build destroys Terraform plan when developer triggers it manually

#### All resources managed by Terraform are destroyed, but Cloud Build execution history is preserved

#### Teardown shell script is executed by developer, deleting Cloud Source Repository and Cloud Build triggers