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

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

问题描述

实例模板对于创建受管实例组是必不可少的。事实上,托管实例组对于在GCP中创建自动缩放组是必不可少的。



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



我写了下面的答案,包含创建实例模板的步骤。

解决方案

实例模板在GCP中是全局资源模板可用于在GCP中的任何区域创建受管实例组。但是,如果在模板中指定了区域,则该模板只能用于该特定区域。



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



实例模板可以在控制台中创建,也可以使用 gcloud 像这样:

  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> /<启动脚本> .sh,\
<其他变量> =<值>

以上命令创建一个基于CentOS 6映像的实例模板,包含一个标签,一些范围和一个启动脚本。
$ b


  • 计算引擎的默认服务帐户具有读取相同桶的权限(范围)项目和写入日志给stackdriver。重写范围时,请确保您还指定了默认范围,即 storage-ro和logging-write 是配置实例的最佳方式,比如安装一些包,启动Docker容器等。

  • 还可以指定其他元数据,可以使用在计算引擎中用于其他目的。 防火墙规则也可以标记的形式指定。在上面的例子中,http标签允许端口80上的入口流量。

  • 其他自定义设置网络,子网络,磁盘大小也可以在模板配置中指定。



最佳实践:从我的角度来看,最好创建一个自定义安装了所有软件而不是使用启动脚本的图像。因为在组中启动新实例所需的时间应尽可能少。这将增加您扩展您的网络应用程序的速度。



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


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.

解决方案

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.

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>

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

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

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

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

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