Giter Club home page Giter Club logo

gcp-mig--lb's Introduction

Managed Instance Group and Load Balancer on GCP with Packer and Terraform.

Scripts to create a an instance template from a Packer built image followed by the creation of a Managed Instance Group with a minimum of 3 Apache Server (no public IP) with a burst to 5 instances running. It also opens port 80 and 443 in firewall rules for default network and is fronted by a Global Load Balancer.

Scripts uses a GCP service account and a JSON file with your account token and VARS defined in variables.tf

Prep

  1. Create a service account and get the JSON file.
  • Follow step 2 and 3 from my previous blog post
  • Make sure you have the following roles (Compute Admin, Service Account User, Storage Admin)
  1. Clone this repo
  2. Update the apache.json and variables.tf files with your GCP account information
  3. Install Packer and Terraform in the gcp-mig-lb folder to make things simple.

Steps

  1. packer validate apache.json
  2. packer build apache.json
  3. terraform init
  4. terraform plan
  5. terraform apply
  6. Wait or a bit (few minutes) and open a Browser with the IP of your GCP Load Balancer
  • The IP of your GCP Load Balancer can be found in: Network Services / Load balancing
  • Click on http-lb-url-map and look in the Frontend section, protocol HTTP. You'll see your Public IP there.
  • Open your browser http://frontend_public_ip
  • Hit refresh and you'll see that you are going randomly to your Apache servers

What does the Terraform script do?

From the custom image, a template will be created and from that, we can create a managed instance group. This will deploy 3 identical instances based on our baked image. It will also inject metadata that will create a static web page that contains the server’s name, internal and external IP. Create a Firewall rule that will allow HTTP traffic to come to that group. This is useful if we want it all to reach our servers. Create a front-end and back-end service fronted by a load balancer and forwarding rules.

Testing Auto-Healing

You can easily see this in action by going into (Compute Engine / Instance groups / apache-rmig ) and select one of the instance and delete it. You'll see a new one taking its place automatically.

Testing Auto-Scaling

The stress tool as been installed in the golden image we've baked. To stress an instance and trigger auto-scaling, go into (Compute Engine / Instance groups / apache-rmig ) and click SSH under the Connect option of the instance of your chosing to go in. Once you are inside the instance, just run (stress -c 4) and CPU utilization will spike to 100% on that instance and will trigger auto-scaling after a minute. When you terminate the stress tool, the scale-down process can take up to 10 minutes.

Cleanup

  1. terraform destroy
  2. In Compute Engine / Images
  • Delete your custom image

gcp-mig--lb's People

Contributors

sveronneau 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.