日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

使用Terraform創(chuàng)建ACK專有集群

本文介紹如何使用Terraform創(chuàng)建ACK專有集群

重要

ACK專有集群已限制新建。請(qǐng)提交工單申請(qǐng)開(kāi)通。

前提條件

  • 已安裝Terraform

    說(shuō)明

    請(qǐng)確保版本不低于v0.12.28。如需檢查現(xiàn)有版本,請(qǐng)運(yùn)行terraform --version命令。

    安裝配置方式如下:

    • 使用Cloud Shell,其環(huán)境已默認(rèn)安裝配置了Terraform和阿里云賬號(hào)信息,無(wú)需任何額外配置。關(guān)于如何使用Cloud Shell,請(qǐng)參見(jiàn)在Cloud Shell中使用Terraform

    • 如需在本地使用Terraform,請(qǐng)參見(jiàn)在本地安裝和配置Terraform

  • 配置阿里云賬號(hào)信息。

    執(zhí)行如下命令,創(chuàng)建環(huán)境變量,用于存放身份認(rèn)證信息。

    阿里云賬號(hào)(主賬號(hào))對(duì)賬號(hào)中的資源具有完全管理權(quán)限,一旦泄露風(fēng)險(xiǎn)極大。推薦您創(chuàng)建一個(gè)名為Terraform的RAM用戶,并為該RAM用戶創(chuàng)建AccessKey和授權(quán)。具體操作,請(qǐng)參見(jiàn)創(chuàng)建RAM用戶為RAM用戶授權(quán)

    Linux環(huán)境

    export ALICLOUD_ACCESS_KEY="************"   # 替換為阿里云賬號(hào)的AK信息。
    export ALICLOUD_SECRET_KEY="************"   # 替換為阿里云賬號(hào)的SK信息。
    export ALICLOUD_REGION="cn-beijing"         # 替換為您集群所在的地域。

    Windows環(huán)境

    set ALICLOUD_ACCESS_KEY="************"   # 替換為阿里云賬號(hào)的AK信息。
    set ALICLOUD_SECRET_KEY="************"   # 替換為阿里云賬號(hào)的SK信息。
    set ALICLOUD_REGION="cn-beijing"         # 替換為您集群所在的地域。
  • 已開(kāi)通容器服務(wù) Kubernetes 版ACK。若需要使用Terraform開(kāi)通,請(qǐng)參見(jiàn)首次開(kāi)通ACK并授權(quán)角色

  • 創(chuàng)建工作目錄,并在工作目錄中創(chuàng)建variable.tf配置文件。

    在Terraform中,variable.tf可以定義輸入變量,用于參數(shù)化資源,以便在不同配置中重復(fù)使用。這些變量隨后將在main.tf文件中用于具體的資源配置。

    下面是一個(gè)variable.tf文件的示例:

    • 創(chuàng)建1個(gè)新的VPC,并創(chuàng)建3個(gè)該VPC下的vSwitch、3個(gè)Pod vSwitch。

    • 在創(chuàng)建ACK集群中,默認(rèn)安裝的組件有:Terway(網(wǎng)絡(luò)組件)、csi-plugin(存儲(chǔ)組件)、csi-provisioner(存儲(chǔ)組件)、logtail-ds(日志組件)、Nginx Ingress Controller、ack-arms-prometheus(監(jiān)控組件)。

  • 展開(kāi)查看示例variable.tf文件

    variable "name" {      # 定義資源的名稱或標(biāo)簽。
      default = "tf-example"
    }
    
    # leave it to empty would create a new one
    variable "vpc_id" {    # 指定現(xiàn)有的vpc_id。如果為空,則表示創(chuàng)建一個(gè)新的VPC。
      description = "Existing vpc id used to create several vswitches and other resources."
      default     = ""
    }
    
    variable "vpc_cidr" {  # 當(dāng)沒(méi)有指定vpc_id時(shí),定義了新VPC的CIDR地址,即IP地址范圍。
      description = "The cidr block used to launch a new vpc when 'vpc_id' is not specified."
      default     = "10.0.0.0/8"
    }
    
    # leave it to empty then terraform will create several vswitches
    variable "vswitch_ids" { # 指定現(xiàn)有的vSwitch(虛擬交換機(jī))ID。如果列表為空,默認(rèn)會(huì)根據(jù)填寫的vswitch_cidrs創(chuàng)建新的vSwitch。
      description = "List of existing vswitch id."
      type        = list(string)
      default     = []
    }
    
    
    variable "vswitch_cidrs" { # 創(chuàng)建新的vSwitch,需要填寫三個(gè)且不重疊的CIDR地址塊。
      description = "List of cidr blocks used to create several new vswitches when 'vswitch_ids' is not specified."
      type        = list(string)
      default     = ["10.1.0.0/16", "10.2.0.0/16", "10.3.0.0/16"]
    }
    
    variable "terway_vswitch_ids" {  # 指定網(wǎng)絡(luò)組件Terway配置。如果為空,默認(rèn)會(huì)根據(jù)terway_vswitch_cidrs的創(chuàng)建新的terway vSwitch。
      description = "List of existing vswitch ids for terway."
      type        = list(string)
      default     = []
    }
    
    variable "terway_vswitch_cidrs" { # 當(dāng)沒(méi)有指定terway_vswitch_ids時(shí),用于創(chuàng)建Terway使用的vSwitch的CIDR地址塊。
      description = "List of cidr blocks used to create several new vswitches when 'terway_vswitch_cidrs' is not specified."
      type        = list(string)
      default     = ["10.4.0.0/16", "10.5.0.0/16", "10.6.0.0/16"]
    }
    
    variable "cluster_addons" { # 指定ACK集群安裝的組件。聲明每個(gè)組件的名稱和對(duì)應(yīng)配置。
      type = list(object({
        name   = string
        config = string
      }))
    
      default = [
        {
          "name"   = "terway-eniip",
          "config" = "",
        },
        {
          "name"   = "csi-plugin",
          "config" = "",
        },
        {
          "name"   = "csi-provisioner",
          "config" = "",
        },
        {
          "name"   = "logtail-ds",
          "config" = "{\"IngressDashboardEnabled\":\"true\"}",
        },
        {
          "name"   = "nginx-ingress-controller",
          "config" = "{\"IngressSlbNetworkType\":\"internet\"}",
        },
        {
          "name"   = "arms-prometheus",
          "config" = "",
        },
        {
          "name"   = "ack-node-problem-detector",
          "config" = "{\"sls_project_name\":\"\"}",
        }
      ]
    }
    說(shuō)明

    variable.tf配置中的地域請(qǐng)與下文main.tf配置文件保持一致。

使用Terraform創(chuàng)建ACK專有集群

本小節(jié)以創(chuàng)建一個(gè)使用Terway網(wǎng)絡(luò)組件的ACK專有集群為例。

  1. 前提條件中創(chuàng)建的工作目錄中創(chuàng)建名為main.tf的配置文件。

    說(shuō)明

    main.tf用來(lái)在阿里云上創(chuàng)建和配置ACK集群資源。執(zhí)行創(chuàng)建過(guò)程中,main.tf文件會(huì)引用variables.tf文件中聲明的變量。

    main.tf文件描述了以下Terraform資源配置:

    • 創(chuàng)建1個(gè)新的VPC,并創(chuàng)建3個(gè)該VPC下的vSwitch、3個(gè)Pod vSwitch。

    • 創(chuàng)建1個(gè)ACK專有集群

    • 創(chuàng)建1個(gè)包含2個(gè)節(jié)點(diǎn)的節(jié)點(diǎn)池。

    • 創(chuàng)建1個(gè)自動(dòng)伸縮節(jié)點(diǎn)池。

    展開(kāi)查看main.tf示例文件

    data "alicloud_enhanced_nat_available_zones" "enhanced" {} # 查詢用于獲取支持增強(qiáng)型網(wǎng)關(guān)NAT的區(qū)域。
    
    # If there is not specifying vpc_id, the module will launch a new vpc
    resource "alicloud_vpc" "vpc" {  # 當(dāng)沒(méi)有提供vpc_id變量時(shí),這個(gè)資源將創(chuàng)建一個(gè)新的專有網(wǎng)絡(luò),其CIDR塊由vpc_cidr變量指定。
      count      = var.vpc_id == "" ? 1 : 0
      cidr_block = var.vpc_cidr
    }
    
    # According to the vswitch cidr blocks to launch several vswitches
    resource "alicloud_vswitch" "vswitches" { # 查詢VPC vSwitch資源。
      count      = length(var.vswitch_ids) > 0 ? 0 : length(var.vswitch_cidrs)
      vpc_id     = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id
      cidr_block = element(var.vswitch_cidrs, count.index)
      zone_id    = data.alicloud_enhanced_nat_available_zones.enhanced.zones[count.index].zone_id
    }
    
    # According to the vswitch cidr blocks to launch several vswitches
    resource "alicloud_vswitch" "terway_vswitches" { # 查詢當(dāng)前阿里云用戶的資源組。
      count      = length(var.terway_vswitch_ids) > 0 ? 0 : length(var.terway_vswitch_cidrs)
      vpc_id     = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id
      cidr_block = element(var.terway_vswitch_cidrs, count.index)
      zone_id    = data.alicloud_enhanced_nat_available_zones.enhanced.zones[count.index].zone_id
    }
    
    data "alicloud_resource_manager_resource_groups" "default" { 
      status = "OK"
    }
    
    data "alicloud_instance_types" "default" { # 查詢阿里云的ECS實(shí)例類型。
      count                = 3
      availability_zone    = data.alicloud_enhanced_nat_available_zones.enhanced.zones[0].zone_id
      cpu_core_count       = 4
      memory_size          = 8
    }
    
    resource "alicloud_cs_kubernetes" "default" {  # 創(chuàng)建ACK專有集群,配置包括控制面虛擬交換機(jī)、Pod虛擬交換機(jī)、實(shí)例類型、磁盤、密碼、Service網(wǎng)絡(luò)地址段等。
      master_vswitch_ids    = length(var.vswitch_ids) > 0 ? split(",", join(",", var.vswitch_ids)) : length(var.vswitch_cidrs) < 1 ? [] : split(",", join(",", alicloud_vswitch.vswitches.*.id)) # 查詢支持增強(qiáng)型NAT的可用區(qū)列表。
      pod_vswitch_ids       = length(var.terway_vswitch_ids) > 0 ? split(",", join(",", var.terway_vswitch_ids)) : length(var.terway_vswitch_cidrs) < 1 ? [] : split(",", join(",", alicloud_vswitch.terway_vswitches.*.id)) # 使用Terway時(shí)pod網(wǎng)絡(luò)的vswitch地址段。
      master_instance_types = [data.alicloud_instance_types.default.0.instance_types.0.id, data.alicloud_instance_types.default.1.instance_types.0.id, data.alicloud_instance_types.default.2.instance_types.0.id] # 控制面節(jié)點(diǎn)的實(shí)例類型。
      master_disk_category  = "cloud_ssd"            # 控制面節(jié)點(diǎn)系統(tǒng)盤類型。
      password              = "Yourpassword1234"     # SSH登錄密碼。
      service_cidr          = "172.18.0.0/16"        # Service網(wǎng)絡(luò)地址段。
      load_balancer_spec    = "slb.s1.small"         # 負(fù)載均衡規(guī)格。
      install_cloud_monitor = "true"                 # 安裝云監(jiān)控服務(wù)。
      resource_group_id     = data.alicloud_resource_manager_resource_groups.default.groups.0.id # 集群所屬資源組ID,實(shí)現(xiàn)不同資源的隔離。
      deletion_protection   = "false"                # 集群刪除保護(hù),防止通過(guò)控制臺(tái)或API誤刪除集群。
      timezone              = "Asia/Shanghai"        # 集群使用的時(shí)區(qū)。
      os_type               = "Linux"                # 操作系統(tǒng)平臺(tái)類型。
      platform              = "AliyunLinux3"         # 操作系統(tǒng)發(fā)行版。
      cluster_domain        = "cluster.local"        # 集群本地域名。
      proxy_mode            = "ipvs"                 # kube-proxy代理模式。
      custom_san            = "www.terraform.io"     # 自定義證書SAN。
      new_nat_gateway       = "true"                 # 創(chuàng)建一個(gè)新的NAT網(wǎng)關(guān)。
      dynamic "addons" {
        for_each = var.cluster_addons
        content {
          name   = lookup(addons.value, "name", var.cluster_addons)
          config = lookup(addons.value, "config", var.cluster_addons)
        }
      }
    }

    關(guān)于更多的創(chuàng)建ACK專有集群配置參數(shù)信息,請(qǐng)參見(jiàn)alicloud_cs_kubernetes

  2. 執(zhí)行以下命令,初始化Terraform運(yùn)行環(huán)境。

    terraform init

    返回信息如下,Terraform初始化成功。

    Initializing the backend...
    
    Initializing provider plugins...
    - Checking for available provider plugins...
    - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.90.1...
    ...
    
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  3. 執(zhí)行以下命令,生成資源規(guī)劃。

    terraform plan

    返回信息如下,資源規(guī)劃生成成功。

    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.
    ...
    Plan: 7 to add, 0 to change, 0 to destroy.
    ...
  4. 執(zhí)行以下命令,創(chuàng)建集群。

    terraform apply

    返回信息如下,輸入yes,按Enter鍵,集群創(chuàng)建成功。

    ...
    Do you want to perform these actions?
      Terraform will perform the actions described above.
      Only 'yes' will be accepted to approve.
    
      Enter a value: yes
    ...
    alicloud_cs_managed_kubernetes.default: Creation complete after 8m26s [id=************]
    
    Apply complete! Resources: 7 added, 0 changed, 1 destroyed.

使用Terraform刪除ACK專有集群

您可以執(zhí)行以下命令,刪除通過(guò)Terraform創(chuàng)建的集群。

terraform destroy

返回信息如下,輸入yes,按Enter鍵,集群刪除成功。

...
Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes
...
Destroy complete! Resources: 7 destroyed.

相關(guān)文檔