集群扩容CA

背景

需要在集群业务高峰期的时候,进行集群自动扩容

步骤

准备policy

# 执行下面命令生成一个policy文件
cat > policy.json <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "autoscaling:DescribeAutoScalingGroups",
        "autoscaling:DescribeAutoScalingInstances",
        "autoscaling:DescribeLaunchConfigurations",
        "autoscaling:DescribeScalingActivities",
        "ec2:DescribeImages",
        "ec2:DescribeInstanceTypes",
        "ec2:DescribeLaunchTemplateVersions",
        "ec2:GetInstanceTypesFromInstanceRequirements",
        "eks:DescribeNodegroup"
      ],
      "Resource": ["*"]
    },
    {
      "Effect": "Allow",
      "Action": [
        "autoscaling:SetDesiredCapacity",
        "autoscaling:TerminateInstanceInAutoScalingGroup"
      ],
      "Resource": ["*"]
    }
  ]
}EOF

创建Policy

# 创建policy
aws iam create-policy --policy-name AmazonEKSClusterAutoscalerPolicy  --policy-document file://policy.json 

eksctl创建irsa

# 使用eksctl创建serviceaccount
eksctl create iamserviceaccount   --cluster raymond   --namespace kube-system   --name cluster-autoscaler   --attach-policy-arn arn:aws:iam::893420598334:policy/AmazonEKSClusterAutoscalerPolicy   --role-name asg-eks-role   --override-existing-serviceaccounts   --region us-east-1   --approve

部署CA插件

# 下载ca的yaml文件
wget https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml


# 修改文件(由于使用eksctl创建了sa,因此这边需要去掉sa的部分)
sed -i '1,10d' cluster-autoscaler-autodiscover.yaml

# 替换自己集群的名字. 后面这个raymond是集群的名字
 sed -i 's@<YOUR CLUSTER NAME>@raymond@g' cluster-autoscaler-autodiscover.yaml 

# 执行安装
kubectl apply -f  cluster-autoscaler-autodiscover.yaml  

CA日志查看

# 查看控制器日志(无error即可)
kubectl logs -f deploy/cluster-autoscaler -n kube-system


测试demo

cat > nginx-deploy.yaml <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3  # 设置副本数为3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: "1"     # 请求1个CPU
            memory: "1Gi"  # 请求1Gi内存
          limits:
            cpu: "1"
            memory: "1Gi"
EOF

# 执行yaml
kubectl apply -f nginx-deploy.yaml


触发条件

 1. Pod因为资源不足没办法掉度

 2. HPA扩容,达到了node最大运行的pod数量 

 3. 等待周期大概是3分钟即可触发,缩容时间大概是15分钟.会自动缩容.也会自动扩容,无需人员手动干预


自我判定

自我判定

#

判定描述

自我判定(是/否)

备注

1在各搜索引擎中是否能找到知识信息(包括但不限于Google、百度、Bing)

2

是否需要代码集成开发


3

是有有相关文章

EKS扩缩容实践之CA


  • No labels