AWS-EKS-08--升级集群与删除集群

摘要

升级集群

  • eks升级分为server端升级,工作节点升级,客户端kubectl升级

  • 可以通过aws控制台升级集群,页面上点点按钮就可以了,这里给出的是通过命令行升级集群的方式

  • 每次升级只能升级一个次要版本

1
2
3
4
5
6
7
# 每次升级只能升级一个次要版本,先查看当前版本,当前server端是1.25,client端是1.24,最好也升级一下本地的kubectl client
$ kubectl version --short

Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.24.2
Kustomize Version: v4.5.4
Server Version: v1.25.10-eks-c12679a
  • 将集群升级到1.26

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ eksctl upgrade cluster --name eks-lexing --profile eks-us-west-2 --version 1.26 --approve
2023-06-29 19:03:35 [ℹ] will upgrade cluster "eks-lexing" control plane from current version "1.25" to "1.26"
2023-06-29 19:11:27 [✔] cluster "eks-lexing" control plane has been upgraded to version "1.26"
2023-06-29 19:11:27 [ℹ] you will need to follow the upgrade procedure for all of nodegroups and add-ons
2023-06-29 19:11:29 [ℹ] re-building cluster stack "eksctl-eks-lexing-cluster"
2023-06-29 19:11:29 [✔] all resources in cluster stack "eksctl-eks-lexing-cluster" are up-to-date
2023-06-29 19:11:30 [ℹ] checking security group configuration for all nodegroups
2023-06-29 19:11:30 [ℹ] all nodegroups have up-to-date cloudformation templates

# 查看server版本
$ kubectl version --short
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.24.2
Kustomize Version: v4.5.4
Server Version: v1.26.6-eks-a5565ad
WARNING: version difference between client (1.24) and server (1.26) exceeds the supported minor version skew of +/-1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 进入到kubectl命令所在目录
$ cd /usr/local/bin
# 备份原命令
$ mv kubectl kubectl.back
# 下载指定版本
$ curl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.26.4/2023-05-11/bin/darwin/amd64/kubectl
# 授予执行权限
$ chmod +x kubectl
# 查看版本
$ k version --short
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.26.4-eks-0a21954
Kustomize Version: v4.5.7
Server Version: v1.26.6-eks-a5565ad
  • 升级work节点机版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 查看节点组信息,看到type为managed,表示被托管的节点组,这里要注意,托管和非托管升级方式是不一样的
$ eksctl get nodegroup --cluster eks-lexing --profile eks-us-west-2
CLUSTER NODEGROUP STATUS CREATED MIN SIZE MAX SIZE DESIRED CAPACITY INSTANCE TYPE IMAGE ID ASG NAME TYPE
eks-lexing ng-4d9024eb ACTIVE 2023-06-28T06:30:03Z 2 2 m5.large AL2_x86_64 eks-ng-4d9024eb-20c48058-e974-c6ec-786a-516c31131604 managed

# 查看节点组上的k8s版本信息,实际上节点组信息可以通过控制台查看--> EKS-集群--计算
$ aws eks describe-nodegroup --cluster-name eks-lexing --profile eks-us-west-2 --nodegroup-name ng-4d9024eb --query 'nodegroup.version' --output text
1.25

# 查看节点信息,这里也会显示k8s的版本,可以看到是v1.25.9
$ k get node -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
ip-192-168-25-29.us-west-2.compute.internal Ready <none> 28h v1.25.9-eks-0a21954 192.168.25.29 35.87.26.4 Amazon Linux 2 5.10.179-168.710.amzn2.x86_64 containerd://1.6.19
ip-192-168-47-168.us-west-2.compute.internal Ready <none> 28h v1.25.9-eks-0a21954 192.168.47.168 54.185.178.28 Amazon Linux 2 5.10.179-168.710.amzn2.x86_64 containerd://1.6.19

# 升级节点组,每次也只升级一个次要版本,2个node就用时20多分钟,还是比较慢的
$ eksctl upgrade nodegroup --name=ng-4d9024eb --cluster=eks-lexing --profile=eks-us-west-2 --kubernetes-version=1.26
2023-06-29 19:31:24 [ℹ] setting ForceUpdateEnabled value to false
2023-06-29 19:31:24 [ℹ] updating nodegroup stack
2023-06-29 19:31:26 [ℹ] waiting for CloudFormation changeset "eksctl-update-nodegroup-1688038284" for stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:31:57 [ℹ] waiting for CloudFormation changeset "eksctl-update-nodegroup-1688038284" for stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:31:58 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:32:29 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:32:30 [ℹ] upgrading nodegroup version
2023-06-29 19:32:30 [ℹ] updating nodegroup stack
2023-06-29 19:32:31 [ℹ] waiting for CloudFormation changeset "eksctl-update-nodegroup-1688038350" for stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:33:03 [ℹ] waiting for CloudFormation changeset "eksctl-update-nodegroup-1688038350" for stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:33:04 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:33:35 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:34:33 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:36:24 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:38:11 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:39:11 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:39:58 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:41:28 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:43:27 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:44:26 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:45:48 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:47:06 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:48:35 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:50:04 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:50:44 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:51:57 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:53:36 [ℹ] waiting for CloudFormation stack "eksctl-eks-lexing-nodegroup-ng-4d9024eb"
2023-06-29 19:53:36 [ℹ] nodegroup successfully upgraded

# 再次查看版本
$ aws eks describe-nodegroup --cluster-name eks-lexing --profile eks-us-west-2 --nodegroup-name ng-4d9024eb --query 'nodegroup.version' --output text
1.26

$ k get node -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
ip-192-168-48-14.us-west-2.compute.internal Ready <none> 20m v1.26.4-eks-0a21954 192.168.48.14 54.212.74.15 Amazon Linux 2 5.10.179-168.710.amzn2.x86_64 containerd://1.6.19
ip-192-168-69-81.us-west-2.compute.internal Ready <none> 21m v1.26.4-eks-0a21954 192.168.69.81 44.242.163.187 Amazon Linux 2 5.10.179-168.710.amzn2.x86_64 containerd://1.6.19
  • 升级之后可以登录aws控制台查看一下相关插件是否需要升级,如果需要直接在页面上点击升级即可。

删除集群

  • 官方文档中可以看到可以使用 eksctl、AWS Management Console 或 AWS CLI 删除集群,这里以eksctl为例说明。

  • 如果集群中具有与负载均衡器关联的有效服务,则必须先删除这些服务,然后再删除集群,以便正确删除负载均衡器。否则,VPC 中可能有阻止您删除 VPC 的孤立资源。

  • 列出集群中运行的所有服务

1
$ kubectl get svc --all-namespaces
  • 删除具有关联的 EXTERNAL-IP 值的任何服务。这些服务的前面配置了一个 Elastic Load Balancing 负载均衡器,您必须从 Kubernetes 中将其删除才能释放负载均衡器和关联资源

1
$ kubectl delete svc `service-name`
  • 删除集群

1
2
# 运行时间基于当前集群所使用的资源规模,超过10分钟
$ eksctl delete cluster --name eks-lexing --profile myProfile
  • 删除完成后检查一下对应的ec2,负载均衡器,目标群组,vpc,安全组,弹性ip,卷,net网关以及CloudFormation
    是否都已经删除,如果有遗漏需要手工删除。