在 Google Cloud Platform 中创建实例模板 [英] Creating an instance template in Google Cloud Platform

查看:31
本文介绍了在 Google Cloud Platform 中创建实例模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实例模板对于创建托管实例组至关重要.事实上,托管实例组对于在 GCP 中创建自动缩放组至关重要.

Instance template is essential for creating managed instance group. In fact, Managed instance group is essential for creating an autoscaling group in GCP.

此问题是另一个问题的答案的一部分,该问题的答案是关于构建自动缩放和负载平衡的后端.

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 create an instance template.

推荐答案

实例模板是 GCP 中的全局资源,即可以使用相同的模板在 GCP 的任何区域中创建托管实例组.但是,如果在模板中指定了区域,则该模板只能在该特定区域中使用.

Instance templates are global resources in GCP i.e the same template can be used to create managed instance groups in any regions in the GCP. However if a zone is specified in the template, then that template can be used only in that particular zone.

实例模板定义机器类型、图像、身份标签和其他实例属性.这样做是为了在托管实例组中维护相同的实例.稍后,此实例组可用于创建自动伸缩组,也可以进行负载均衡.

Instance templates define the machine type, image, identity tags and other instance properties. This is done to maintain the identical instances in the managed instance group. Later, this instance group can be used for creating an autoscaling group and can also be load-balanced.

实例模板可以在控制台中创建,也可以使用 gcloud 之类的这个:

Instance template can be created either in console or with gcloud like this:

gcloud compute instance-templates 
create sample-template 
--image CentOS 6 
--tags http 
--scopes=sql-admin,storage-ro,logging-write 
--metadata startup-script-url=
gs://<bucket-name>/<startup-script>.sh,
<other-variable>=<value>

上面的命令创建了一个基于 CentOS 6 镜像的实例模板,带有一个标签、一些作用域和一个启动脚本.

The above command creates an instance template based on CentOS 6 image, with a tag, some scopes and an startup script.

  • 计算引擎的默认服务帐户具有从同一项目读取存储桶并将日志写入堆栈驱动程序的权限(范围).当您覆盖范围时,请确保您还指定了默认范围,即 storage-ro 和 logging-write.
  • 启动脚本是配置实例的最佳方式,例如安装一些软件包、启动 docker 容器等.
  • 还可以指定其他元数据,这些数据可在计算引擎中用于其他目的.
  • 防火墙规则也可以以标签的形式指定.在上面的例子中,http 标签允许端口 80 上的入口流量.
  • 还可以在模板配置中指定其他自定义设置,例如设置网络、子网络、磁盘大小.
  • The compute engine's default service account has permissions(scope) for reading the buckets from the same project and writing logs to stackdriver. When you override the scope, make sure you also specify the default scopes namely storage-ro and logging-write.
  • Startup scripts are the best way to configure your instance like installing some packages, starting up a docker container and so on.
  • Other metadata can also be specified which can be used in the compute engine for some other purposes.
  • Firewall rules can also be specified in the form of tags. In the above eg, the http tag allows ingress traffic on port 80.
  • Other customisations like setting up the network, sub-network, disk sizes can also be specified in the template configuration.

最佳做法:在我看来,安装了所有软件的情况下创建自定义映像比使用启动脚本要好.因为在组中启动新实例所需的时间应尽可能短.这将提高您扩展网络应用的速度.

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 group should be as minimum as possible. This will increase the speed at which you scale your web app.

这是三部分系列第 1 部分,内容是关于构建一个自动缩放的负载-平衡后端.

This is part 1 of 3-part series about building an autoscaled, load-balanced backend.

这篇关于在 Google Cloud Platform 中创建实例模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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