跳至內容

如何為現有 Amazon EKS 叢集新增子網路?

2 分的閱讀內容
0

我想為 Amazon Elastic Kubernetes Service (Amazon EKS) 叢集控制平面新增新的子網路。

簡短描述

如果您在新的可用區域新增子網路或從現有可用區域中移除子網路,則可能會收到類似以下內容的錯誤訊息:

「An error occurred (InvalidParameterException) when calling the UpdateClusterConfig operation: Provided subnets belong to the AZs 'us-west-2a,us-west-2c,us-west-2d'.But they should belong to the exact set of AZs 'us-west-2a,us-west-2c' in which subnets were provided during cluster creation.」

您的子網路必須位於您建立叢集時,AWS 為您選擇的相同可用區域中。子網路也必須位於您建立叢集時,AWS 提供的相同 Amazon Virtual Private Cloud (Amazon VPC) 中。VPC 必須具有足夠的可用 IP 位址供叢集使用。如需詳細資訊,請參閱建立子網路和 VPC 要求和注意事項。

解決方法

若要修改 Amazon EKS 叢集子網路,您可以使用 Amazon EKS 主控台、AWS CLI 或 eksctl CLI。

使用 Amazon EKS 主控台

請完成下列步驟:

  1. 開啟 Amazon EKS 主控台。
  2. 在導覽窗格中,選擇 Cluster (叢集)。
  3. 選擇 Network (網路),然後選擇 Manage VPC resources (管理 VPC 資源)。
  4. 在 Subnets (子網路) 功能表上,選取要新增的子網路。
  5. 選擇 Save (儲存)。
  6. 在 Network (網路) 區段,確認已新增子網路。

使用 AWS CLI

**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。

AWS CLI 命令會將現有的叢集子網路替換為您在命令中包含的子網路。若要新增子網路,請指定現有子網路和附加子網路。

  1. 執行 describe-subnets 命令來識別您為 EKS 叢集設定的可用區域:

    aws ec2 describe-subnets --subnet-ids $(aws eks describe-cluster --name your-cluster-name --query 'cluster.resourcesVpcConfig.subnetIds' --output text) --query 'Subnets[*].AvailabilityZone'

    **注意:**將 your-cluster-name 替換為您的叢集名稱,並將範例子網路 ID 替換為您的子網路 ID。
    輸出範例:

    [
        "us-west-2c",
        "us-west-2d",
        "us-west-2a"
    ]
  2. 執行 update-cluster-config 命令來更新叢集控制平面子網路:

    aws eks update-cluster-config --name your-cluster-name \
    --resources-vpc-config subnetIds=subnet-1234,subnet-5678,subnet-9101

    **注意:**將 your-cluster-name 替換為您的叢集名稱,並將範例子網路 ID 替換為您的子網路 ID。新增子網路時,請確保原始集合中的每個可用區域至少有一個對應的子網路。若要保留可用區域的現有子網路,請在命令中包含該子網路。
    以下範例會取得 EKS 叢集的目前可用區域,並將新子網路新增至現有區域。update-cluster-config 命令包含原始子網路和新子網路,以維護叢集的可用區域組態,並擴展每個區域中的子網路:

    aws eks describe-cluster --name gpusharing-demo --query 'cluster.resourcesVpcConfig.subnetIds'
    [
        "subnet-03d59dfc8d9380b4c",
        "subnet-0c4f51f27d109fa32",
        "subnet-037b42db1a08da5ae"
    ]
    
    aws eks update-cluster-config --name gpusharing-demo --resources-vpc-config subnetIds=subnet-xxxxxxx80b4c,subnet-xxxxxxx8da5ae,subnet-xxxxxxx9fa32,subnet-xxxxxxee3bb,subnet-xxxxxxa761ac,subnet-xxxxxxde8b8
    {
    "update": {
    "id": "e7ed1fbf-01ab-3472-8204-149cdc3337be",
    "status": "InProgress",
    "type": "VpcConfigUpdate",
    "params": [
    {
    "type": "Subnets",
    "value": "[subnet-xxxxxxx80b4c, subnet-xxxxxxx8da5ae, subnet-xxxxxxxx9fa32, subnet-xxxxxxxee3bb, subnet-xxxxxxxxa761ac, subnet-xxxxxxde8b8]"
    }
    ],
    "createdAt": "2024-09-09T18:06:16.493000+00:00",
    "errors": []
    }
    }

使用 eksctl CLI

eksctl CLI 命令會將現有的叢集子網路替換為您在命令中包含的子網路。若要新增子網路,請指定現有子網路和附加子網路。

執行以下 eksctl 命令來更新叢集控制平面子網路:

eksctl utils update-cluster-vpc-config --cluster=your-cluster-name \
--control-plane-subnet-ids=subnet-1234,subnet-5678 --approve

以下範例輸出顯示叢集已更新為每個可用區域對應一個子網路:

eksctl utils update-cluster-vpc-config --cluster=gpusharing-demo  --control-plane-subnet-ids=subnet-03d59dfc8d9380b4c,subnet-0c4f51f27d109fa32,subnet-037b42db1a08da5ae --approve
2024-09-09 18:23:54 [ℹ]  using region us-west-2
2024-09-09 18:23:54 [ℹ]  will update control plane subnet IDs for cluster "gpusharing-demo" in "us-west-2" to: [subnet-xxxxxxx80b4c subnet-xxxxxxx9fa32 subnet-xxxxxx8da5ae]
2024-09-09 18:32:07 [✔]  control plane subnets and security groups for cluster "gpusharing-demo" in "us-west-2" have been updated to: controlPlaneSubnetIDs=[subnet-xxxxxxx80b4c subnet-xxxxxxxx9fa32 subnet-xxxxxxxx8da5ae], controlPlaneSecurityGroupIDs=[sg-xxxxx31d2]

若要使用 config.yaml 檔案更新子網路,請執行下列命令:

eksctl utils update-cluster-vpc-config -f config.yaml

輸出範例:

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: cluster
  region: us-west-2

vpc:
  controlPlaneSubnetIDs: [subnet-1234, subnet-5678, subnet-9101]
  controlPlaneSecurityGroupIDs: [sg-1234, sg-5678]

相關資訊:

增強的 VPC 彈性:在 Amazon EKS 中修改子網路和安全群組

在 eksctl 網站上更新控制平面子網路和安全群組

AWS 官方已更新 1 年前