资讯专栏INFORMATION COLUMN

资源编排工具-私有网络下批量部署多台云主机

ernest.wang / 555人阅读

摘要:私有网络下批量部署多台云主机本篇目录摘要摘要拓扑图拓扑图操作步骤操作步骤参考文献参考文献关键词摘要云主机是构建在云环境的弹性计算资源,是最为核心的服务。

私有网络下批量部署多台云主机

本篇目录

关键词UHostVPCSubnet

摘要

云主机是构建在云环境的弹性计算资源,是 UCloud 最为核心的服务。有些服务,如弹性 IP、镜像、云硬盘等必须与云主机结合后使用,另一些服务,如数据库、缓存、对象存储等可以和云主机结合共同构建 IT 环境。

此案例使用 Terraform 并行批量创建多台云主机,并在每一台云主机上绑定 VPC, Subnet 用于网络隔离。

UCloud 是国内最早采用 SDN 技术的云计算服务商,VPC 基于 SDN 技术构建,是属于用户的、逻辑隔离的网络环境。在私有网络中,可以创建指定网段的 VPC,并在 VPC 中创建子网、自主管理云资源,同时可通过网络 ACL 实现安全防护。

使用 Terraform 来创建云主机除了享有由基础设施既代码 (IaC) 带来的便利外,还可以利用并行资源编排带来的性能提升,当基础设施十分庞大和复杂时,已定义的资源会自动被抽象为有向无环图 (DAG), 寻找尽可能的并行编排路径,以达到较优的编排性能。

此案例需要一个可用的 UCloud 帐号,以及确保目标可用区有足够的权限和配额可以创建云主机,VPC 和防火墙。可以在下方操作步骤中拷贝使用,或克隆 官方仓库 以获取完整的 案例演示代码.

拓扑图

avatar

操作步骤

定义资源

首先创建基础设施代码文件,可从 官方样例 中获取全部源码文件。

一个 variables.tf 文件,用于定义输入参数,代码详情如下:

variable "region" {   default = "cn-bj2" } variable "zone" {   default = "cn-bj2-05" } variable "instance_password" {   default = "ucloud_2020" } variable "instance_count" {   default = 3 } variable "count_format" {   default = "%02d" }CopyErrorSuccess

一个 main.tf 文件,用于建立一个从云资源到代码的映射,代码详情如下:

# 指定 UCloud Provider 和配置信息 provider "ucloud" {   region = var.region } # 查询默认可用区中的主机镜像 data "ucloud_images" "default" {   availability_zone = var.zone   name_regex        = "^CentOS 7.[1-2] 64"   image_type        = "base" } # 创建 VPC resource "ucloud_vpc" "default" {   name = "tf-example-intranet-cluster"   tag  = "tf-example"   # vpc network   cidr_blocks = ["192.168.0.0/16"] } # 创建 Subnet 到 VPC 下 resource "ucloud_subnet" "default" {   name = "tf-example-intranet-cluster"   tag  = "tf-example"   # subnet's network must be contained by vpc network   # and a subnet must have least 8 ip addresses in it (netmask < 30).   cidr_block = "192.168.1.0/24"   vpc_id = ucloud_vpc.default.id } # 创建内网集群 resource "ucloud_instance" "intranet" {   count = "${var.instance_count}"   availability_zone = var.zone   image_id          = data.ucloud_images.default.images[0].id   instance_type     = "n-basic-2"   root_password     = var.instance_password   boot_disk_type    = "cloud_ssd"   # we will put all the instances into same vpc and subnet,   # so they can communicate with each other.   vpc_id = ucloud_vpc.default.id   subnet_id = ucloud_subnet.default.id   name = "tf-example-intranet-cluster-${format(var.count_format, count.index + 1)}"   tag  = "tf-example" }CopyErrorSuccess

生成执行计划

在当前目录下执行 terraform plan 命令,查看编排计划:

Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. data.ucloud_zones.default: Refreshing state... data.ucloud_images.default: Refreshing state... ------------------------------------------------------------------------ An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols:   + create Terraform will perform the following actions:   + ucloud_instance.intranet[0]       id:                     <computed>       auto_renew:             <computed>       availability_zone:      "cn-bj2-02"       boot_disk_size:         <computed>       boot_disk_type:         <computed>       charge_type:            "month"       cpu:                    <computed>       create_time:            <computed>       data_disk_size:         <computed>       data_disk_type:         <computed>       disk_set.#:             <computed>       expire_time:            <computed>       image_id:               "uimage-f1chxn"       instance_type:          "n-basic-2"       ip_set.#:               <computed>       memory:                 <computed>       name:                   "tf-example-intranet-cluster-01"       private_ip:             <computed>       remark:                 <computed>       root_password:          <sensitive>       security_group:         <computed>       status:                 <computed>       subnet_id:              "${ucloud_subnet.default.id}"       tag:                    "tf-example"       vpc_id:                 "${ucloud_vpc.default.id}"   + ucloud_instance.intranet[1]       id:                     <computed>       auto_renew:             <computed>       availability_zone:      "cn-bj2-02"       boot_disk_size:         <computed>       boot_disk_type:         <computed>       charge_type:            "month"       cpu:                    <computed>       create_time:            <computed>       data_disk_size:         <computed>       data_disk_type:         <computed>       disk_set.#:             <computed>       expire_time:            <computed>       image_id:               "uimage-f1chxn"       instance_type:          "n-basic-2"       ip_set.#:               <computed>       memory:                 <computed>       name:                   "tf-example-intranet-cluster-02"       private_ip:             <computed>       remark:                 <computed>       root_password:          <sensitive>       security_group:         <computed>       status:                 <computed>       subnet_id:              "${ucloud_subnet.default.id}"       tag:                    "tf-example"       vpc_id:                 "${ucloud_vpc.default.id}"   + ucloud_instance.intranet[2]       id:                     <computed>       auto_renew:             <computed>       availability_zone:      "cn-bj2-02"       boot_disk_size:         <computed>       boot_disk_type:         <computed>       charge_type:            "month"       cpu:                    <computed>       create_time:            <computed>       data_disk_size:         <computed>       data_disk_type:         <computed>       disk_set.#:             <computed>       expire_time:            <computed>       image_id:               "uimage-f1chxn"       instance_type:          "n-basic-2"       ip_set.#:               <computed>       memory:                 <computed>       name:                   "tf-example-intranet-cluster-03"       private_ip:             <computed>       remark:                 <computed>       root_password:          <sensitive>       security_group:         <computed>       status:                 <computed>       subnet_id:              "${ucloud_subnet.default.id}"       tag:                    "tf-example"       vpc_id:                 "${ucloud_vpc.default.id}"   + ucloud_subnet.default       id:                     <computed>       cidr_block:             "192.168.1.0/24"       create_time:            <computed>       name:                   "tf-example-intranet-cluster"       remark:                 <computed>       tag:                    "tf-example"       vpc_id:                 "${ucloud_vpc.default.id}"   + ucloud_vpc.default       id:                     <computed>       cidr_blocks.#:          "1"       cidr_blocks.3901788224: "192.168.0.0/16"       create_time:            <computed>       name:                   "tf-example-intranet-cluster"       network_info.#:         <computed>       remark:                 <computed>       tag:                    "tf-example"       update_time:            <computed> Plan: 5 to add, 0 to change, 0 to destroy. ------------------------------------------------------------------------ Note: You didn't specify an "-out" parameter to save this plan, so Terraform can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run.CopyErrorSuccess

可以看到即将创建三台云主机、一个 VPC,一个 Subnet。

执行编排

执行 terraform apply 命令并确认,执行编排计划:

Do you want to perform these actions?   Terraform will perform the actions described above.   Only 'yes' will be accepted to approve.   Enter a value: yesCopyErrorSuccess

可通过 控制台 确认资源已创建完成。


文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/126509.html

相关文章

  • Docker技术浅谈:私有部署的优势以及在顶象内部的应用实践

    摘要:本文主要和大家分享下容器技术和顶象风控系统私有化部署的优势以及容器技术在顶象内部的应用实践。容器技术在顶象内部的应用目前容器技术已在顶象内部大规模推行,所有应用均通过容器实现部署交付与更新。 顶象全景式业务安全风控体系基于新一代风控体系构建,并采用Docker技术进行私有云和公有云部署。本文主要和大家分享下Docker容器技术和顶象风控系统私有化部署的优势以及Docker容器技术在顶象...

    andong777 评论0 收藏0
  • 五阿哥钢铁电商平台Docker容器平台建设实践——你想知道的都在这里!

    摘要:容器云架构方案。容器云架构方案基于容器技术,运维技术团队开发了五阿哥网站的容器云平台。多云对接私有云和公有云进行统一托管,包含网络区域配置,实例开通及的环境初始化配置等。技术选型及实践镜像标准众所周知,的镜像是分层的。 前言 五阿哥钢铁电商平台(www.wuage.com)是由钢铁行业第一的中国五矿与互联网第一的阿里巴巴联手打造,并充分运用双方股东优势资源,即:阿里巴巴在大数据、电商运...

    jeffrey_up 评论0 收藏0
  • .Net大户的选择:Windows Container在携程的应用

    摘要:一些的技术细节最开始的时候携程用物理机部署应用,为了保证互不冲突,用户在一个物理机上只部署一个应用。目前支持的系统是,这个版本是去年月份正式发布的携程是国内比较早的一批拿到了他们的版本,支持两类,一类是,另一类是。 数人云上海&深圳两地容器之 Mesos/K8S/Swarm 三国演义的嘉宾精彩实录第四弹!小数已经被接连不断的干货搞晕了,沉浸技术的海洋好幸福~Windows contai...

    leo108 评论0 收藏0
  • 计算转型哪些地方会出错?

    摘要:盘点云计算的优势,较低的托管成本较低的基础架构复杂性较高的可扩展性这些都是实实在在的好处。好雨,让云落地,提供以应用为中心的云计算产品和服务。 盘点云计算的优势,较低的托管成本、较低的基础架构复杂性、较高的可扩展性……这些都是实实在在的好处。不过对于企业来说,选择云计算最关键的驱动在于产品速度,换句话说,利用适当的云计算产品和技术,我们可以在最短时间内把理念变成用户需要的实际产品。 过...

    KoreyLee 评论0 收藏0
  • 德国KubeCon直击:如何轻松且安心地将k8s用于生产?

    摘要:年正在柏林盛大举行,来自等多个开源云原生社区的领先技术专家正汇聚一堂,以进一步推动云原生计算的教育和发展。例如,你还需要诸如负载均衡器和的服务来运行应用程序。负载均衡器可以进行高级定制,以满足用户的各类需求。 想要在生产环境中成功部署容器,你需要的不仅仅是容器编排。 2017年CloudNativeCon+KubeCon Europe正在柏林盛大举行,来自Fluented、Kubern...

    Jensen 评论0 收藏0

发表评论

0条评论

ernest.wang

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<