cluster-autoscaler¶
link¶
blog¶
install¶
eksdemo¶
echo ${CLUSTER_NAME}
echo ${AWS_DEFAULT_REGION}
eksdemo install autoscaling cluster-autoscaler -c ${CLUSTER_NAME} -n kube-system
manual¶
https://docs.aws.amazon.com/zh_cn/eks/latest/userguide/autoscaling.html
create service account¶
CLUSTER_NAME=ekscluster1
AWS_REGION=us-east-2
cat > cluster-autoscaler-policy.json <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/k8s.io/cluster-autoscaler/<my-cluster>": "owned"
}
}
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeAutoScalingGroups",
"ec2:DescribeLaunchTemplateVersions",
"autoscaling:DescribeTags",
"autoscaling:DescribeLaunchConfigurations"
],
"Resource": "*"
}
]
}
EOF
ARN=$(aws iam create-policy \
--policy-name AmazonEKSClusterAutoscalerPolicy-$RANDOM \
--policy-document file://cluster-autoscaler-policy.json |jq -r '.Policy.Arn')
eksctl create iamserviceaccount \
--cluster=${CLUSTER_NAME} \
--namespace=kube-system \
--name=cluster-autoscaler \
--attach-policy-arn=${ARN} \
--override-existing-serviceaccounts \
--approve
install from yaml¶
curl -o cluster-autoscaler-autodiscover.yaml https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
sed -i "s/.YOUR CLUSTER NAME./${CLUSTER_NAME}/" cluster-autoscaler-autodiscover.yaml
kubectl apply -f cluster-autoscaler-autodiscover.yaml
kubectl patch deployment cluster-autoscaler \
-n kube-system \
-p '{"spec":{"template":{"metadata":{"annotations":{"cluster-autoscaler.kubernetes.io/safe-to-evict": "false"}}}}}'
get newest version for your cluster, for example 1.21.3 / 1.22.3
VER=1.21.3
kubectl set image deployment cluster-autoscaler \
-n kube-system \
cluster-autoscaler=k8s.gcr.io/autoscaling/cluster-autoscaler:v${VER}
helm¶
https://github.com/kubernetes/autoscaler/blob/master/charts/cluster-autoscaler/README.md
- create service account in previous chapter
-
install from helm
helm repo add autoscaler https://kubernetes.github.io/autoscaler helm install myca-release autoscaler/cluster-autoscaler \ -n kube-system \ --set autoDiscovery.clusterName=${CLUSTER_NAME} \ --set awsRegion=${AWS_REGION} \ --set rbac.serviceAccount.create=false \ --set rbac.serviceAccount.name=cluster-autoscaler # refer values # wget -O myca-values.yaml https://github.com/kubernetes/autoscaler/raw/master/charts/cluster-autoscaler/values.yaml
-
check version
compatibility and upgrade¶
https://github.com/kubernetes-sigs/metrics-server#compatibility-matrix