跳至內容

如何檢查、擴展、清空或刪除 Amazon EKS 中的工作節點?

2 分的閱讀內容
0

我使用 eksctl 或 Amazon Elastic Kubernetes Service (Amazon EKS) 主控台來檢查、擴展、清空或刪除工作節點。

解決方法

檢查您的工作節點

若要列出您註冊到 Amazon EKS 控制平面的工作節點,請執行下列命令:

kubectl get nodes -o wide

在輸出中,您可以查看工作節點的名稱、Kubernetes 版本、作業系統 (OS) 和 IP 位址。

若要取得有關特定工作節點的其他資訊,請執行以下命令:

kubectl describe node/node_name

**注意:**將 node_name 替換為您工作節點的 Amazon Resource Name (ARN)。例如,ip-AA-BB-CC-DD.us-east-1.compute.internal

輸出會顯示有關工作節點的資訊,例如標籤、污點、系統資訊和狀態。

擴展工作節點

**注意:**如果您的節點群組出現在 Amazon EKS 主控台中,請使用受管節點群組來擴充您的工作節點。否則,請使用非受管節點群組。

使用以下其中一種方法來擴展您的工作節點。

使用 eksctl 擴充工作節點

若要使用 eksctl 擴充受管或非受管工作節點,請執行下列命令:

eksctl scale nodegroup --cluster=clusterName --nodes=desiredCount --name=nodegroupName

**注意:**將 clusterName 替換為您的叢集名稱,將 desiredCount 替換為要擴充的節點數,並將 nodegroupName 替換為節點群組名稱。

不使用 eksctl 擴展工作節點

若要在不使用 eksctl 的情況下擴充受管工作節點,請編輯節點群組組態

使用 CloudFormation 擴充工作節點

若要使用 AWS CloudFormation 擴充非受管工作節點,請使用 CloudFormation 範本啟動適用於 WindowsLinux 的工作節點。然後,修改 CloudFormation 堆疊中的 NodeAutoScalingGroupDesiredCapacityNodeAutoScalingGroupMinSizeNodeAutoScalingGroupMaxSize 參數。

清空您的工作節點

**重要:**清空動作會隔離工作節點,使 Kubernetes 不再於該節點上排程新的 Pod。Kubernetes 會移除並停止在目標節點上執行的 Pod 以清空節點。

您可以清空整個節點群組或單一工作節點。

清空整個節點群組

如果您使用 eksctl 啟動工作節點,請執行以下命令:

eksctl drain nodegroup --cluster=clusterName --name=nodegroupName

**注意:**將 clusterName 替換為您的叢集名稱,將 nodegroupName 替換為您的節點群組名稱。

若要取消封鎖已清空的節點群組,請執行下列命令:

eksctl drain nodegroup --cluster=clusterName --name=nodegroupName --undo

**注意:**將 clusterName 替換為您的叢集名稱,將 nodegroupName 替換為您的節點群組名稱。

如果您未使用 eksctl 啟動工作節點,請執行以下指令碼來清空特定 Kubernetes 版本的所有節點:

#!/bin/bash  K8S_VERSION=1.18.8-eks-7c9bda
nodes=$(kubectl get nodes -o jsonpath="{.items[?(@.status.nodeInfo.kubeletVersion==\"v$K8S_VERSION\")].metadata.name}")
for node in ${nodes[@]}
do
    echo "Draining $node"
    kubectl drain $node --ignore-daemonsets --delete-local-data
done

**注意:**將 1.18.8-eks-7c9bda 替換為您的 Kubernetes 版本。

若要取消封鎖已清空的節點,請執行下列指令碼:

#!/bin/bash  K8S_VERSION=1.18.8-eks-7c9bda
nodes=$(kubectl get nodes -o jsonpath="{.items[?(@.status.nodeInfo.kubeletVersion==\"v$K8S_VERSION\")].metadata.name}")
for node in ${nodes[@]}
do
    echo "Uncordon $node"
    kubectl uncordon $node
done

**注意:**將 1.18.8-eks-7c9bda 替換為您的 Kubernetes 版本。

若要取得工作節點版本號碼,請執行下列命令:

kubectl get nodesNAME

**注意:**將 nodesNAME 替換為您的節點名稱。

輸出範例:

$ kubectl get nodesNAME                                      STATUS   ROLES    AGE     VERSION  
ip-ABC-ACB-DE-ABC.ec2.internal            Ready    <none>   6d4h    v1.18.8-eks-7c9bda
ip-ABC-ABC-DE-ABC.ec2.internal            Ready    <none>   6d4h    v1.18.8-eks-7c9bda

版本號碼會顯示在 VERSION (版本) 欄位中。

清空單一工作節點

如果您未使用 eksctl 來啟動工作節點或清空特定節點,那麼請安全地隔離工作節點。執行以下命令:

kubectl drain node_name --ignore-daemonsets

**注意:**將 node_name 替換為您的節點名稱。

若要復原隔離,請執行以下命令:

kubectl uncordon node_name

**注意:**將 node_name 替換為您的節點名稱。

您也可以將現有應用程式遷移到新的工作節點群組

刪除您的工作節點

**重要:**您無法復原刪除操作。

如果您使用 eksctl,請執行以下命令:

eksctl delete nodegroup --cluster=clusterName --name=nodegroupName

**注意:**將 clusterName 替換為您的叢集名稱,將 nodegroupName 替換為您的節點群組名稱。

如果您有受管節點群組,請參閱從叢集中刪除受管節點群組

如果您有一個非受管節點群組,並且您使用 CloudFormation 範本啟動工作節點,請刪除該節點群組的堆疊

如果您有一個非受管節點群組,但未使用 CloudFormation 範本,請刪除 Amazon Elastic Compute Cloud (Amazon EC2) Auto Scaling 群組。如果您未使用 Amazon EC2 Auto Scaling 群組,請終止該執行個體

AWS 官方已更新 1 年前