1.Terraform code in service.tf:
resource "kubernetes_horizontal_pod_autoscaler" "co-ec-hpa" {
for_each = var.service_parameters
metadata {
name = each.value.desc
}
spec {
max_replicas = each.value.service_hpa_max
min_replicas = each.value.service_hpa_min
target_cpu_utilization_percentage = 60 // TODO
scale_target_ref {
api_version = "extensions/v1beta1"
kind = "Deployment"
name = "${each.value.name}-${var.eks_cluster_name}"
}
}
}
2. Install Metrics Server
DOWNLOAD_URL=$(curl -Ls "https://api.github.com/repos/kubernetes-sigs/metrics-server/releases/latest" | jq -r .tarball_url)DOWNLOAD_VERSION=$(grep -o '[^/v]*$' <<< $DOWNLOAD_URL)curl -Ls $DOWNLOAD_URL -o metrics-server-$DOWNLOAD_VERSION.tar.gz
mkdir metrics-server-$DOWNLOAD_VERSION
tar -xzf metrics-server-$DOWNLOAD_VERSION.tar.gz --directory metrics-server-$DOWNLOAD_VERSION --strip-components 1kubectl apply -f metrics-server-$DOWNLOAD_VERSION/deploy/1.8+/
rm metrics-server-$DOWNLOAD_VERSION.tar.gz
rm -rf metrics-server-$DOWNLOAD_VERSION
3. Check the pod under 'kube-system' name space
kube-system metrics-server-7fcf9cc98b-eeeee 1/1 Running 0 47h
Reference
(For HPA based on external metrics, please contact me)
No comments:
Post a Comment