Code Monkey home page Code Monkey logo

gcp-mig-simple's Introduction

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

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). 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) or use your project Cloud Shell
  • set SDK default project, by executing
    gcloud config set project <YOUR_PROJECT_ID>
    
  • 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)

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

gcp-mig-simple's People

Contributors

psimakov avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.