Skip to content

Latest commit

 

History

History
73 lines (52 loc) · 4.43 KB

File metadata and controls

73 lines (52 loc) · 4.43 KB

Running an instance group with autoscaling in Yandex Compute Cloud using Network Load Balancer

Using this Terraform configuration, you will deploy an instance group with an autoscaling policy to apply if the load limit is exceeded.

VM instances will be deployed in two availability zones, with the load distributed using Yandex Network Load Balancer.

For more information about the provider resources, see the documentation on the Terraform website or its mirror.

If you modify the configuration files, Terraform automatically detects which part of your configuration is already deployed and what should be added or removed.

For a detailed tutorial, see Running an instance group with autoscaling.

To set up scaling for your instance group using Terraform:

  1. Install Terraform and specify the source for installing the Yandex Cloud provider (see Configure a provider, Step 1).

  2. Prepare files with the infrastructure description:

    1. Clone the repository with Terraform configuration files:

      git clone https://github.com/yandex-cloud-examples/yc-vm-group-with-autoscale.git
    2. Go to the directory with the repository. Make sure it contains the following files:

      • vm-autoscale.tf: New infrastructure configuration.
      • declaration.yaml: Description of the Docker container with a web server that will run on the VM to simulate load on the service.
      • config.tpl: Description of VM user parameters.
      • vm-autoscale.auto.tfvars: User data.

    For more information about the parameters of resources used in Terraform, see the relevant provider documentation:

  3. In the vm-autoscale.auto.tfvars file, set the following user-defined properties:

    • folder_id: Folder ID.
    • vm_user: VM user name.
    • ssh_key: Contents of the file with a public SSH key to authenticate the user on the VM. For details, see Creating an SSH key pair.
  4. Create resources:

    1. In the terminal, navigate to the directory containing the downloaded repository.

    2. Make sure the configuration file is correct using this command:

      terraform validate

      If the configuration is correct, you will get this message:

      Success! The configuration is valid.
    3. Run this command:

      terraform plan

      The terminal will display a list of resources with parameters. No changes will be made at this step. If there are errors in the configuration, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
    5. Confirm the changes: type yes into the terminal and press Enter.

  5. Test your instance group and network load balancer.

  6. Test auto scaling.