Skip to content

Instantly share code, notes, and snippets.

@esys
Last active September 4, 2020 13:29
Show Gist options
  • Save esys/099a0007f5770e123959491a02e4138d to your computer and use it in GitHub Desktop.
Save esys/099a0007f5770e123959491a02e4138d to your computer and use it in GitHub Desktop.
enableAutoscaling(cluster: eks.Cluster, ng: eks.Nodegroup, version: string = "v1.17.3") {
const autoscalerStmt = new iam.PolicyStatement();
autoscalerStmt.addResources("*");
autoscalerStmt.addActions(
"autoscaling:DescribeAutoScalingGroups",
"autoscaling:DescribeAutoScalingInstances",
"autoscaling:DescribeLaunchConfigurations",
"autoscaling:DescribeTags",
"autoscaling:SetDesiredCapacity",
"autoscaling:TerminateInstanceInAutoScalingGroup",
"ec2:DescribeLaunchTemplateVersions"
);
const autoscalerPolicy = new iam.Policy(this, "cluster-autoscaler-policy", {
policyName: "ClusterAutoscalerPolicy",
statements: [autoscalerStmt],
});
autoscalerPolicy.attachToRole(ng.role);
const clusterName = new CfnJson(this, "clusterName", {
value: cluster.clusterName,
});
cdk.Tag.add(ng, `k8s.io/cluster-autoscaler/${clusterName}`, "owned", { applyToLaunchedInstances: true });
cdk.Tag.add(ng, "k8s.io/cluster-autoscaler/enabled", "true", { applyToLaunchedInstances: true });
new eks.KubernetesManifest(this, "cluster-autoscaler", {
cluster,
manifest: [ {
apiVersion: "v1",
kind: "ServiceAccount",
... }], // full code is available here: https://gist.github.com/esys/bb7bbeb44565f85f48b3112a8d73a092
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment