如何在Google云端平台中配置受管实例组和自动缩放 [英] How do I configure managed instance group and autoscaling in Google Cloud Platform

查看:275
本文介绍了如何在Google云端平台中配置受管实例组和自动缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Autoscaling可帮助您根据负载自动添加或删除计算引擎。在GCP中自动缩放的先决条件是实例模板和受管实例组。



这个问题是另一个问题的答案,这是关于建立一个自动调整和负载平衡后端。



我写下了包含步骤在GCP中设置自动缩放。 自动缩放是GCP中受管实例组的一项功能。这有助于通过扩展实例来处理非常高的流量,同时在没有流量的情况下还可以减少实例,从而节省大量金钱。



要设置自动缩放,我们需要以下内容:
$ b


  • 实例模板

  • 托管实例组

  • 自动缩放策略

  • 运行状况检查



  • 实例模板是一个蓝图,用于定义将在自动调节的受管实例组中运行的同类实例的机器类型,映像,磁盘。我已经写下了设置实例模板的步骤。此处



    托管实例组有助于保留基于单个实例模板的一组同类实例。假设实例模板为 sample-template 。这可以通过在 gcloud 中运行以下命令来设置:

      gcloud compute instance-groups managed \ 
    create autoscale-managed-instance-group \
    - base-instance-name autoscaled-instance \
    --size 3 \
    - 模板示例模板\
    --region asia-northeast1


    $ b上面的命令基于样本模板创建一个托管实例组,其中包含位于亚洲 - 东北部1区域三个不同区域的3个计算引擎。



    • base-instance-name 是所有自动创建的实例的基本名称。除了基本名称之外,每个实例名称都将附加一个唯一生成的随机字符串。

    • size 表示组中所需的实例数量。截至目前,无论应用程序产生的通信量如何,都会一直运行3个实例。稍后,可以通过将策略应用于此组进行自动调整。

    • 区域(多区域)或单区域:可以设置托管实例组(多区域),即同质实例将均匀分布在给定区域的所有区域中,或者所有实例可以部署在区域内的同一区域中。它也可以作为跨区域1进行部署,当前为alpha。
    • autoscaler行为。自动调节程序汇总实例中的数据,并将其与策略中指定的所需容量进行比较,并确定要采取的操作。有许多自动扩展策略,例如:
      $ b

      • 平均CPU使用率


      • HTTP负载平衡服务能力(请求/秒)

      • Stackdriver标准和自定义指标

      • 还有更多




      现在,通过在 Autoscaling cloud.google.com/compute/docs/gcloud-compute/rel =nofollow noreferrer> gcloud

        gcloud compute instance-groups managed \ 
      set-autoscaling \
      autoscale-managed-instance-group \
      --max-num-replicas 6 \
      --min-num-replicas 2 \
      --target-cpu-utilization 0.60 \
      --cool-down-period 120 \
      --region asia-northeast1

      上述命令设置了一个汽车基于 CPU利用率的标尺,范围从 2 (如果没有流量)到 6 (在流量大的情况下)。




      • 冷静期标志指定在关联autoscaler开始运行之前实例启动后等待的秒数从中收集信息。

      • 自动调节程序可以关联到最多 5种不同策略。如果有多个策略,Autoscaler会推荐以最大实例数保留的策略。

      • 有趣的事实:当实例由autoscaler,它确保实例运行至少10分钟,而不考虑流量。这是因为GCP为计算引擎运行最少10分钟的运行时间。它还可以防止错误的启动和关闭实例。
      • 使用安装的所有软件创建自定义映像比使用启动脚本更好。由于在自动调节组中启动新实例所用的时间应尽可能最少。这会增加您扩展网络应用程序的速度。



        这是第2部分 .com / a / 41541921/3477322> 3部分系列,介绍如何构建自动调整后的负载平衡后端。


        Autoscaling helps you to automatically add or remove compute engines based on the load. The prerequisites to autoscaling in GCP are instance template and managed instance group.

        This question is a part of another question's answer, which is about building an autoscaled and load-balanced backend.

        I have written the below answer that contains the steps to set up autoscaling in GCP.

        解决方案

        Autoscaling is a feature of managed instance group in GCP. This helps to handle very high traffic by scaling up the instances and at the same time it also scales down the instances when there is no traffic, which saves a lot of money.

        To set up autoscaling, we need the following:

        • Instance template
        • Managed Instance group
        • Autoscaling policy
        • Health Check

        Instance template is a blueprint that defines the machine-type, image, disks of the homogeneous instances that will be running in the autoscaled, managed instance group. I have written the steps for setting up an instance template here.

        Managed instance group helps in keeping a group of homogeneous instances that is based on a single instance template. Assuming the the instance template as sample-template. This can be set up by running the following command in gcloud:

        gcloud compute instance-groups managed \
        create autoscale-managed-instance-group \
        --base-instance-name autoscaled-instance \
        --size 3 \
        --template sample-template \
        --region asia-northeast1
        

        The above command creates an managed instance group containing 3 compute engines located in three different zones in asia-northeast1 region, based on sample-template.

        • base-instance-name will be the base name for all the automatically created instances. In addition to the base name, every instance name will be appended by an uniquely generated random string.
        • size represents the desired number of instance in the group. As of now, 3 instances will be running all the time, irrespective of the amount of traffic generated by the application. Later, it can be autoscaled by applying a policy to this group.
        • region (multi-zone) or single-zone: Managed instance group can be either set up in a region (multi-zone) i.e the homogeneous instances will be evenly distributed across all the zones in a given region or all the instances can be deployed in the same zone within a region. It can also be deployed as cross region one, which is currently in alpha.

        Autoscaling policy determines the autoscaler behaviour. The autoscaler aggregates data from the instances and compares it with the desired capacity as specified in the policy and determines the action to be taken. There are many auto-scaling policies like:

        • Average CPU Utilization

        • HTTP load balancing serving capacity (requests / second)

        • Stackdriver standard and custom metrics

        • and many more

        Now, Introducing Autoscaling to this managed instance group by running the following command in gcloud:

        gcloud compute instance-groups managed \
        set-autoscaling \
        autoscale-managed-instance-group \
        --max-num-replicas 6 \
        --min-num-replicas 2 \
        --target-cpu-utilization 0.60 \
        --cool-down-period 120 \
        --region asia-northeast1
        

        The above command sets up an autoscaler based on CPU utilization ranging from 2 (in case of no traffic) to 6 (in case of heavy traffic).

        • cool-down-period flag specifies the number of seconds to wait after a instance has been started before the associated autoscaler starts to collect information from it.
        • An autoscaler can be associated to an maximum of 5 different policies. In case of more than one policy, Autoscaler recommends the policy that leaves with the maximum number of instances.
        • Interesting fact: when an instance is spun up by the autoscaler, it makes sure that the instance runs for atleast 10 minutes irrespective of the traffic. This is done because GCP bills for a minimum of ten minute running time for the compute engine. It also protects against erratic spinning up and shutting down of instances.

        Best Practices: From my perspective, it is better to create a custom image with all your software installed than to use a startup script. As the time taken to launch new instances in the autoscaling group should be as minimum as possible. This will increase the speed at which you scale your web app.

        This is part 2 of 3-part series about building an autoscaled and load-balanced backend.

        这篇关于如何在Google云端平台中配置受管实例组和自动缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆