eksctl方式部署
1. EKS简介
AWS EKS是一项无Master托管服务。对我们来说,AWS帮助我们托管了Master,并做了集群高可用;
PS:可以创建Fargate类型的集群,此集群类似serverless模式,任何节点不需要自己管理,仅需要部署服务,价格相对贵一些,但是避免了资源浪费,具体需要那种,自己选择;
2. 准备
2.1安装aws命令工具,并进行配置(linux版)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
$ aws configure
AWS Access Key ID [None]: xxxx
AWS Secret Access Key [None]: xxxxx
Default region name [None]: us-west-2
Default output format [None]: json
#PS: 你的 Access Key ID和Access Key需要在控制台先创建出来
执行条命令查看是否授权成功
aws s3 ls
2.2 安装eksctl命令工具(linux版)
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
#查看版本确定是否安装成功
eksctl version
3. 命令行创建
3.1 基于yaml文件的方式创建
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: test-cluster
region: us-west-2
nodeGroups: #非托管节点组
- name: Global #节点组名
privateNetworking: true #私有IP,不带公网
instanceType: c5.2xlarge #实例类型,多种实力类型:["c3.xlarge", "c4.xlarge"]
volumeSize: 100 #磁盘大小
desiredCapacity: 2 #需要的实例数
ssh:
publicKeyName: eks #选择的现有的密钥对名称
managedNodeGroups: #托管节点组
- name: managedworkers
labels: { role: workers }
instanceType: m5.xlarge
minSize: 5
desiredCapacity: 10
maxSize: 20
volumeSize: 80
privateNetworking: true
ssh:
publicKeyName: eks
#创建过程中可以去CloudFormation查看创建进度
3.2 托管节点组和非托管节点组的区别
- 托管节点组可以在AWS 集群控制台显示,而非托管节点组不可以
- 托管节点组可以调整最大、最小、期望节点数,labels、taints、tags等其他配置。而非托管节点组,配置基本不支持变更(除了节点数量)
3.3 非托管节点组迁移到托管节点组
- 创建托管节点组
dev-cluster.yaml
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: test-cluster
region: us-west-2
managedNodeGroups: #托管节点组
- name: dev-managed-workers
labels: { role: workers }
instanceType: m5.xlarge
minSize: 5
desiredCapacity: 10
maxSize: 20
volumeSize: 80
privateNetworking: true
ssh:
publicKeyName: eks
eksctl create nodegroup --config-file=./dev-cluster.yaml
#如果yaml配置文件中有多个节点组,可通过--include=${GROUP_NAME} --exclude=${GROUP_NAME} ,例如
eksctl create nodegroup --config-file=<path> --include='ng-prod-*-??' --exclude='ng-test-1-ml-a,ng-test-2-?'
- 驱逐工作负载到托管节点组
查看工作负载运行在非托管节点上
kubectl get pod -n $NAMESPACE_NAME -o wide
kubectl get nodes
进行驱逐
eksctl drain nodegroup --cluster=$EKS_CLUSTER_NAME --name=$EKS_UNMANAGED_NODEGROUP_NAME
查看工作负载的情况
kubectl get pod -n $NAMESPACE_NAME -o wide 或 kubectl get pod --all-namespaces |grep -v kube-system
删除非托管节点组
eksctl delete nodegroup --cluster $EKS_CLUSTER_NAME --name $EKS_UNMANAGED_NODEGROUP_NAME
实时查看节点删除情况
kubectl get nodes -w
3.4 节点组node扩缩容
Scaling a single nodegroup¶
A nodegroup can be scaled by using the eksctl scale nodegroup command:
eksctl scale nodegroup --cluster=<clusterName> --nodes=<desiredCount> --name=<nodegroupName> [ --nodes-min=<minSize> ] [ --nodes-max=<maxSize> ]
For example, to scale nodegroup ng-a345f4e1 in cluster-1 to 5 nodes, run:
eksctl scale nodegroup --cluster=cluster-1 --nodes=5 ng-a345f4e1
A nodegroup can also be scaled by using a config file passed to --config-file and specifying the name of the nodegroup that should be scaled with --name. Eksctl will search the config file and discover that nodegroup as well as its scaling configuration values.
If the desired number of nodes is NOT within the range of current minimum and current maximum nodes, one specific error will be shown. Kindly note that these values can also be passed with flags --nodes-min and --nodes-max respectively.
Scaling a nodegroup works by modifying the nodegroup CloudFormation stack via a ChangeSet.