Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Vidyasagar SC Machupalli
Vidyasagar SC Machupalli

Posted on • Originally published atMedium on

Auto-scale instance on VPC using Terraform

Learn how to provision and auto scale VSI on VPC using Terraform scripts and explore auto scale scenarios like SSL termination (offloading) and end-to-end encryption.

WithAuto Scale for VPC, you can create an instance group to scale according to your requirements. Based on the target utilization metrics that you define, the instance group can dynamically add or remove instances to achieve your specified instance availability.

Let’s start with a quick one, like an introduction to VPC.

What is a VPC?

Avirtual private cloud (VPC) is a public cloud offering that lets an enterprise establish its own private cloud-like computing environment on sharedpublic cloud infrastructure. The following video gives more information on VPCs:

Auto scaling on VPC

WithAuto Scale for VPC, you can improve performance and costs by dynamically creating virtual server instances (VSIs) to meet the demands of your environment. You set scaling policies that define your desired average utilization for metrics like CPU, memory, and network usage. You can create an instance group in yourIBM Cloud VPC to auto scale according to your requirements by using the IBM Cloud console. Based on the target utilization metrics that you define, the instance group can dynamically add or remove instances to achieve your specified instance availability.

What’s the outcome?

Following the instructions and executing theTerraform scripts, you will provision the following:

  • A VPC
  • Two subnets — one in each zone (zone 1 and zone 2) — Configure in main.tf file
  • One VSI in subnet-zone-1 (to start with)
  • Load balancer (backend pool and frontend listener)
  • Instance group using an instance template
  • Instance group manager with a scaling policy (CPU utilization) attached to the instance group

Pre-requisites

  • IBM Cloud IAM API key (refer to theIAM documentation)
  • SSH key (refer to theVPC SSH documentation)
  • If you want to enableSSH offloading (termination) orend-to-end encryption , you need to create a Certificate manager service, order a certificate, and pass that to load balancer HTTPS listener. Follow theinstructions here to learn the certificate ordering process.

Step-by-step instructions

  1. Clone thevpc-tutorials GitHub repository and move to thevpc-autoscale directory:
git clone [https://github.com/IBM-Cloud/vpc-tutorials.git](https://github.com/IBM-Cloud/vpc-tutorials.git)cd vpc-autoscale
Enter fullscreen modeExit fullscreen mode
  1. Copy the Terraform variables template:
cp terraform.tfvars.template terraform.tfvars
Enter fullscreen modeExit fullscreen mode
  1. Update the values in theterraform.tfvars file based on your requirement and save the file. To understand the variables, refer to thevariables.tf file.

  2. Initialize the Terraform providers by running the following:

  3. Execute the Terraform plan:terraform plan

  4. Apply the Terraform plan:terraform apply

The max_membership_count to scale is set to 5, the aggregation_window is set to 90 secs, and cooldown is set to 120 secs. You can change these values in themain.tf file. Refer to theInstance-group-manager Terraform provider documentation.

SSL offloading (termination)

For all incoming HTTPS connections, the load balancer service terminates the SSL connection and establishes a plain-text HTTP communication with the backend server. CPU-intensive SSL handshakes and encryption/decryption tasks are shifted away from the backend servers, allowing them to use all their CPU cycles for processing application traffic.

End-to-end encryption

In this section, you will enable end-to-end encryption by creating a self-signed certificate in the VSI. You will use the SSL installation script — install-software-ssl.sh.

Clean-up

Run the following command to delete the resources you created. The action is irreversible:

terraform destroy
Enter fullscreen modeExit fullscreen mode

Terraform-as-a-Service

WithIBM Cloud Schematics, you can simplify the above Terraform experience. Schematics delivers Terraform-as-a-Service so that you can use a high-level scripting language to model the resources that you want in your IBM Cloud environment and enableInfrastructure as Code (IaC).

Refer tothis post to understand how Schematics works with an example.

What’s next?

How about automatically assigning a floating IP to a newly created VSI by monitoring Activity Tracker events and using Cloud Functions to interact with the VPC API? Yes, you can achieve this by following the instructions in this post: “Extend VPC Resources with Cloud Functions, Activity Tracker with LogDNA, andSchematics.

Explore other VPC scenarios

There are additional scripts in thevpc-tutorialsrepo that are used to set-up scenarios forVPC tutorials and to clean up VPC resources:

Questions and feedback

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter@VidyasagarMSC or use the feedback button on the tutorial to report a problem on its content. You can also openissues.

The tutorials section has a feedback form on the side where you can comment on the content. If you have suggestions on the existing tutorials or ideas for future additions, please submit your feedback.

Originally published athttps://www.ibm.comon October 21, 2020.


Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

A little bit of everything in this journey called LIFE
  • Location
    Austin, TX
  • Work
    Polyglot programmer
  • Joined

More fromVidyasagar SC Machupalli

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp