使用 Terraform 管理節點容量
本頁面說明如何使用端對端 (E2E) Terraform 自動化模組,在現有叢集中新增或刪除裸機 ESXi 節點,藉此擴充或縮減 Google Cloud VMware 解決方案的叢集容量。
擴充叢集容量
如要將現有叢集從 X 個節點擴充至 X + N 個節點,請使用在初始部署叢集時使用的相同 Terraform 工作區和狀態檔案 (terraform.tfstate)。
下列步驟說明如何將第五個節點 (vcf-mgmt-sample-node-5) 新增至四節點管理叢集 (根據 e2e-terraform/sample_management_cluster.tfvars 檔案中的範例設定):
更新變數定義檔案 (
management_cluster.tfvars): 按照下列方式更新management_cluster.tfvars檔案中的設定變數:- 將
deployment_mode變數設為"node_addition"。 - 將
number_of_nodes變數從4更新為5。 - 如果您在建立叢集時明確指定
node_names,請將"vcf-mgmt-sample-node-5"附加至node_names清單。如果一開始未指定node_names清單,請將其留空。 - 如果您在建立叢集時明確指定這些變數,請將新的 IPv4 位址附加至
mgmt_nic_ip_values、vsan_ip_values、vmotion_ip_values、nsx_tep_ip_values和additional_dynamic_nics清單。如果您為了自動分配而將這些清單留空,請勿更新。 - 如果您在建立叢集時明確指定這個變數,請更新
availability_domains清單 (例如[1, 2, 3, 4, 5])。如果留空,請勿更新。
deployment_mode = "node_addition" number_of_nodes = 5 node_names = [ "vcf-mgmt-sample-node-1", "vcf-mgmt-sample-node-2", "vcf-mgmt-sample-node-3", "vcf-mgmt-sample-node-4", "vcf-mgmt-sample-node-5" # New node ] mgmt_nic_ip_values = ["10.200.0.3", "10.200.0.4", "10.200.0.5", "10.200.0.6", "10.200.0.7"] vsan_ip_values = ["10.200.1.3", "10.200.1.4", "10.200.1.5", "10.200.1.6", "10.200.1.7"] vmotion_ip_values = ["10.200.2.3", "10.200.2.4", "10.200.2.5", "10.200.2.6", "10.200.2.7"] nsx_tep_ip_values = ["10.200.3.3", "10.200.3.4", "10.200.3.5", "10.200.3.6", "10.200.3.7"] additional_dynamic_nics = [ { name = "additional-nic-1" subnet_name = "vcf-mgmt-sample-additional-subnet-1" vlan_id = 210 ip_address_type = "reserved_custom" ip_values = ["10.200.4.3", "10.200.4.4", "10.200.4.5", "10.200.4.6", "10.200.4.7"] } ] availability_domains = [1, 2, 3, 4, 5]- 將
生成並套用 Terraform 執行計畫:
terraform plan -var-file='management_cluster.tfvars' -out=tfplan terraform apply tfplan將新節點附加至網路端點群組 (NEG):從
neg_attachment_commandsTerraform 輸出內容擷取並執行產生的gcloud compute network-endpoint-groups update指令,將新執行個體附加至管理和 NSX NEG:# View attachment commands from Terraform outputs terraform output neg_attachment_commands # Run the generated commands to attach the new instance to the Management and NSX NEGs gcloud compute network-endpoint-groups update vcf-mgmt-sample-neg \ --zone='ZONE' \ --project='PROJECT_ID' \ --add-endpoint='instance=vcf-mgmt-sample-node-5' gcloud compute network-endpoint-groups update vcf-mgmt-sample-nsx-neg \ --zone='ZONE' \ --project='PROJECT_ID' \ --add-endpoint='instance=vcf-mgmt-sample-node-5'
執行指令前,請先替換下列項目:
ZONE:叢集所在的 Google Cloud 可用區。PROJECT_ID:目標 Google Cloud 專案的 ID。
預期行為
套用 node_addition 設定時,Terraform 會執行下列不中斷作業:
- 僅佈建新的裸機 ESXi 執行個體 (
vcf-mgmt-sample-node-5),並保留相關聯的內部 IPv4 位址。 - 產生
neg_attachment_commands輸出內容,以便將新執行個體附加至現有的管理和 NSX 可用區 NEG。 - 為新節點註冊正向 (
A) 和反向 (PTR) Cloud DNS 記錄。 - 所有現有執行中的節點、負載平衡器和網路設定都不會中斷。
後續步驟
擴充叢集容量後,請完成下列步驟:
- 按照「使用工具包準備節點並部署 VCF」一文所述,執行工具包指令碼 (
python3 -m vcf_deployer.main --config config.json),重設每個新主機的初始 ESXiroot密碼,並初始化新的 ESXi 節點,以便新增叢集。省略config.json檔案中的vcf_deployment_config物件。 - 使用 VMware UI 或 API,將準備好的節點委託並新增至 VMware Cloud Foundation (VCF) 9.x 叢集。
降低叢集容量
如要將現有叢集從 X 個節點縮減為 X - N 個節點,請使用您在初始部署叢集時使用的相同 Terraform 工作區和狀態檔案 (terraform.tfstate)。
下列步驟說明如何從擴充叢集容量一節所述的五節點管理叢集中,刪除第三個節點 (vcf-mgmt-sample-node-3):
從 VCF 叢集移除節點:使用 VMware SDDC Manager,從 VCF 9.x 叢集移除目標 ESXi 主機,並將其停用。詳情請參閱 VMware Cloud Foundation 說明文件中的「Decommission hosts」(停用主機) 一節。
如適用,請停用節點的防刪除功能:Terraform 無法刪除已啟用防刪除功能的執行個體。如果未對要刪除的節點啟用防刪除功能,請略過這個步驟。否則,請在要刪除的每個節點上停用防刪除功能:
gcloud compute instances update vcf-mgmt-sample-node-3 \ --zone='ZONE' \ --project='PROJECT_ID' \ --no-deletion-protection
執行指令前,請先替換下列項目:
ZONE:叢集所在的 Google Cloud 可用區。PROJECT_ID:目標 Google Cloud 專案的 ID。
如要改用 Google Cloud 控制台停用防刪除功能,請參閱「停用及刪除節點」。
更新變數定義檔案 (
management_cluster.tfvars): 按照下列方式更新management_cluster.tfvars檔案中的設定變數:- 將
deployment_mode變數設為"node_deletion"。 - 將
number_of_nodes變數從5更新為4。 - 指定
node_names清單,其中包含其餘節點的名稱,並從清單中移除"vcf-mgmt-sample-node-3"。 - 如果您在建立叢集時明確指定這些變數,請從
mgmt_nic_ip_values、vsan_ip_values、vmotion_ip_values、nsx_tep_ip_values和additional_dynamic_nics清單中移除已刪除節點的 IPv4 位址。 - 指定
availability_domains清單,並列出每個剩餘節點的可用性網域 (例如[1, 2, 4, 5])。
在
node_deletion模式中,您一律必須明確指定node_names和availability_domains清單,即使您在建立叢集或先前對叢集執行 Terraform 作業時未指定這些清單 (例如節點名稱為自動產生) 也是如此。指定這些清單可確保 Terraform 只刪除預期的節點。請確認每個項目都與對應剩餘節點的名稱和可用性網域相符。deployment_mode = "node_deletion" number_of_nodes = 4 # Always required in node_deletion mode node_names = [ "vcf-mgmt-sample-node-1", "vcf-mgmt-sample-node-2", # "vcf-mgmt-sample-node-3" removed "vcf-mgmt-sample-node-4", "vcf-mgmt-sample-node-5" ] mgmt_nic_ip_values = ["10.200.0.3", "10.200.0.4", "10.200.0.6", "10.200.0.7"] vsan_ip_values = ["10.200.1.3", "10.200.1.4", "10.200.1.6", "10.200.1.7"] vmotion_ip_values = ["10.200.2.3", "10.200.2.4", "10.200.2.6", "10.200.2.7"] nsx_tep_ip_values = ["10.200.3.3", "10.200.3.4", "10.200.3.6", "10.200.3.7"] additional_dynamic_nics = [ { name = "additional-nic-1" subnet_name = "vcf-mgmt-sample-additional-subnet-1" vlan_id = 210 ip_address_type = "reserved_custom" ip_values = ["10.200.4.3", "10.200.4.4", "10.200.4.6", "10.200.4.7"] } ] # Always required in node_deletion mode availability_domains = [1, 2, 4, 5]- 將
產生並套用 Terraform 執行計畫:查看計畫輸出內容,確認 Terraform 只會刪除您要刪除的節點資源,然後套用計畫:
terraform plan -var-file='management_cluster.tfvars' -out=tfplan terraform apply tfplan
預期行為
套用 node_deletion 設定時,Terraform 會執行下列作業:
- 只刪除指定的裸機 ESXi 執行個體 (
vcf-mgmt-sample-node-3) 及其開機磁碟。 - 從管理和 NSX 區域 NEG 中移除已刪除的執行個體。
- 釋出已刪除節點的預留內部 IPv4 位址。
- 刪除已刪除節點的正向 (
A) 和反向 (PTR) Cloud DNS 記錄。 - 其餘所有節點、負載平衡器和網路設定都不會中斷。