其他分享
首页 > 其他分享> > EKS 训练营-使用SPOT(9)

EKS 训练营-使用SPOT(9)

作者:互联网

# 介绍 为什么要使用Spot实例(有的地方也叫竞价实例),俩字:省钱。 如果想了解更多的内容,可以参考这篇 [博客](https://aws.amazon.com/blogs/compute/cost-optimization-and-resilience-eks-with-spot-instances/) 使用Spot实例的架构图 ![image-20210526140235769](https://imgs.wzlinux.com/blog/202105/26/140235-432206.png) # 添加Spot实例组 ## 1.先把原有的都标识了 标识现有的为按需实例组 ```bash kubectl label nodes --all 'lifecycle=OnDemand' ``` ## 2.创建新的 worker node 组 选择 Console 创建 nodegroup 吧,创建起来比较简单,capacityType 选择 SPOT,也可以选择给 node 打标签。 ![image-20210526162138844](https://imgs.wzlinux.com/blog/202105/26/162139-528085.png) ![image-20210526162259934](https://imgs.wzlinux.com/blog/202105/26/162300-433451.png) ## 3.确认新的节点已经 Ready 大概需要 5-8 分钟后即可查询到对应的内容 ```bash kubectl get nodes --sort-by=.metadata.creationTimestamp ``` # 配置 Spot 中断处理 如果 Spot 实例被回收,会提前 2 分钟通知,所以在 Spot 实例上部署一个 [AWS Node Termination Handler](https://github.com/aws/aws-node-termination-handler),用于处理中断,其流程如下 - 确认 Spot 实例被提醒(会被回收) - 利用这 2 分钟的时间间隔准备优雅的终止这个实例 - 不允许部署新的 pod 到这个节点上 - 驱逐已经运行在这个节点上的 pod - 通过 replication controller 在别的节点上替换新的 pod,以保持所需容器的数量 默认情况下,aws-node-termination-handler 会在所有的节点(包括按需节点和 Spot 节点)上应用这个策略,但是如果已经对 Spot 节点打了标签的话,则可以只让他在 Spot 实例上生效(在上面的步骤中,Spot 的标签为: `lifecycle=spot`),安装方式如下 ```bash helm repo add eks https://aws.github.io/eks-charts helm upgrade --install aws-node-termination-handler \ --namespace kube-system \ --set nodeSelector.lifecycle=spot \ eks/aws-node-termination-handler ``` 查看运行状态 ```bash kubectl --namespace=kube-system get daemonsets ``` ![image-20210526162800518](https://imgs.wzlinux.com/blog/202105/26/162801-724347.png) # 清理环境 清除 Spot 终端处理组件 ```bash helm uninstall aws-node-termination-handler --namespace=kube-system ``` 然后可以手动在 console 删除 nodegroup。 # 欢迎大家扫码关注,获取更多信息 ![](https://imgs.wzlinux.com/wechat/wechat-8.jpg)

标签:--,SPOT,训练营,aws,实例,com,https,EKS,Spot
来源: https://blog.51cto.com/wzlinux/2908546