如何使用 Amazon EKS 受管節點群組啟動 Spot 執行個體並對問題進行疑難排解?

2 分的閱讀內容
0

我想要為 Amazon Elastic Kubernetes Service (Amazon EKS) 叢集建立具有 Spot 容量的受管節點群組,並對問題進行疑難排解。

解決方案

1.    安裝 eksctl

重要事項:確定檢查所有 AWS Command Line Interface (AWS CLI) 命令後再使用,並用您的值取代範例字串的執行個體。例如,用您的叢集名稱取代 example-cluster

2.    透過執行下列命令,在現有叢集中建立具有 Spot 容量的受管節點群組:

#eksctl create nodegroup --cluster=<example_cluster> --spot --instance-types=<Comma-separated list of instance types> --region <EKS cluster AWS region. Defaults to the value set in your AWS config (~/.aws/config)>

範例:

#eksctl create nodegroup --cluster=demo --spot --instance-types=c3.large,c4.large,c5.large --region us-east-1

注意:您可以在建立 Spot 受管節點群組時設定其他旗標例如,--name--nodes--nodes-min--nodes-max。透過執行下列命令,取得所有可用旗標的完整清單:

#eksctl create nodegroup --help

3.    如果您為叢集維護 eksctl ClusterConfig 組態檔案,則還可以使用該檔案建立 Spot 受管節點群組。透過執行下列命令,使用具有 spot-cluster.yaml 組態檔案的受管節點群組建立 Spot 執行個體:

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: <example_cluster>
  region: <example_region>
managedNodeGroups:
- name: spot
  instanceTypes: ["c3.large","c4.large","c5.large","c5d.large","c5n.large","c5a.large"]
  spot: true

4.    透過執行下列命令,使用組態檔案建立節點群組:

# eksctl create nodegroup -f spot-cluster.yaml

對 Amazon EKS 中的 Spot 執行個體相關問題進行疑難排解

使用 eksctl 或 Amazon EKS 主控台檢查受管節點群組的運作狀態,如下所示:

$ eksctl utils nodegroup-health --name=<example_nodegroup> --cluster=<example_cluster>

由於使用的執行個體類型缺少 Spot 容量,Spot 受管節點群組的運作狀態可能會因錯誤而降級。請參閱以下範例錯誤:

AsgInstanceLaunchFailures Could not launch Spot Instances. UnfulfillableCapacity - Unable to fulfill capacity due to your request configuration. Please adjust your request and try again. Launching EC2 instance failed.

**注意:**如要成功採用 Spot 執行個體,最佳實務是實作 Spot 執行個體分散,來作為 Spot 受管節點群組組態的一部分。Spot 執行個體分散有助於從多個 Spot 執行個體集區取得容量。取得此容量適用於擴展和取代 Spot 執行個體,這可能會收到 Spot 執行個體終止通知。

如果叢集 Spot 節點群組必須使用符合 1 vCPU: 4 GB RAM 比率的執行個體類型進行佈建,則分散您的 Spot 執行個體集區。使用下列其中一種策略來分散執行個體集區:

  • 建立具有不同大小的多個節點群組。例如,大小為 4 個 vCPU 和 16 GB 記憶體的節點群組,以及另一個大小為 8 個 vCPU 和 32 GB 記憶體的節點群組。
  • 在節點群組中實作執行個體分散。做法是從符合相同 vCPU 和記憶體條件的不同 Spot 執行個體集區中選取執行個體類型和系列的混合。

透過執行下列命令,使用 amazon-ec2-instance-selector 來選取具有足夠數量的 vCPU 和 RAM 的相關執行個體類型和系列:

curl -Lo ec2-instance-selector https://github.com/aws/amazon-ec2-instance-selector/releases/download/v2.0.3/ec2-instance-selector-`uname | tr '[:upper:]' '[:lower:]'`-amd64 && chmod +x ec2-instance-selector
sudo mv ec2-instance-selector /usr/local/bin/
ec2-instance-selector --version

範例:

ec2-instance-selector --vcpus 4 --memory 16 --gpus 0 --current-generation -a x86_64 --deny-list '.*[ni].*'

上述命令會顯示類似下列項目的清單。將這些執行個體用作其中一個節點群組的一部分。

  • m4.xlarge
  • m5.xlarge
  • m5a.xlarge
  • m5ad.xlarge
  • m5d.xlarge
  • t2.xlarge
  • t3.xlarge
  • t3a.xlarge

注意:無法使用 Amazon EKS API 變更現有節點群組的執行個體類型。最佳實務是使用所需的執行個體類型,來建立新的 Spot 節點群組。在 eksctl create nodegroup 命令中輸入以下內容。請注意,新的 eksctl 旗標表示節點群組執行 Spot 執行個體:--spot

$eksctl create nodegroup --cluster=<example_cluster> --spot --instance-types m5.xlarge,m4.xlarge,m5a.xlarge,m5d.xlarge,m5n.xlarge,m5ad.xlarge --region <example_region>

AWS 官方
AWS 官方已更新 1 年前