Last active
August 23, 2019 07:10
-
-
Save so0k/b31b767c126a40a6ded6cd49d8837911 to your computer and use it in GitHub Desktop.
Swatmobile - AWS EKS gists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/amazon-eks-nodegroup-with-mixed-instances.yml b/amazon-eks-nodegroup-with-mixed-instances-custom.yml | |
index a0a3c99..512c50f 100644 | |
--- a/amazon-eks-nodegroup-with-mixed-instances.yml | |
+++ b/amazon-eks-nodegroup-with-mixed-instances-custom.yml | |
@@ -27,6 +27,7 @@ Metadata: | |
- NodeAutoScalingGroupMinSize | |
- NodeAutoScalingGroupDesiredSize | |
- NodeAutoScalingGroupMaxSize | |
+ - ClusterAutoscalerStatus | |
- NodeInstanceType | |
- ASGAutoAssignPublicIp | |
- OnDemandBaseCapacity | |
@@ -168,6 +169,14 @@ Parameters: | |
- "no" | |
Default: "yes" | |
+ ClusterAutoscalerStatus: | |
+ Type: String | |
+ Description: "cluster-autoscaler status" | |
+ AllowedValues: | |
+ - "enabled" | |
+ - "disabled" | |
+ Default: "enabled" | |
+ | |
OnDemandBaseCapacity: | |
Type: Number | |
Description: "on-demand base capacity" | |
@@ -354,6 +363,15 @@ Resources: | |
- Key: !Sub 'kubernetes.io/cluster/${ClusterName}' | |
Value: 'owned' | |
PropagateAtLaunch: 'true' | |
+ - Key: Namespace | |
+ Value: swat | |
+ PropagateAtLaunch: 'true' | |
+ - Key: Stage | |
+ Value: stage | |
+ PropagateAtLaunch: 'true' | |
+ - Key: !Sub 'k8s.io/cluster-autoscaler/${ClusterAutoscalerStatus}' | |
+ Value: 'true' | |
+ PropagateAtLaunch: 'true' | |
UpdatePolicy: | |
AutoScalingRollingUpdate: | |
MinInstancesInService: !Ref NodeAutoScalingGroupDesiredSize | |
@@ -389,6 +407,12 @@ Resources: | |
Value: !Ref ClusterName | |
- Key: !Sub 'kubernetes.io/cluster/${ClusterName}' | |
Value: 'owned' | |
+ - Key: Namespace | |
+ Value: swat | |
+ - Key: Stage | |
+ Value: stage | |
+ - Key: !Sub 'k8s.io/cluster-autoscaler/${ClusterAutoscalerStatus}' | |
+ Value: 'true' | |
UserData: | |
Fn::Base64: | |
!Sub | | |
@@ -427,3 +451,9 @@ Resources: | |
- !Split [ ",", !Ref ExistingNodeSecurityGroups ] | |
ImageId: !Ref NodeImageId | |
InstanceType: !Ref NodeInstanceType | |
+ | |
+Outputs: | |
+ | |
+ NodeGroup: | |
+ Description: The node instance group | |
+ Value: !Ref NodeGroup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# workers cfn stack templates | |
locals { | |
templates_bucket = "${module.cluster_label.id}-templates" | |
mixed_instances_template = "amazon-eks-nodegroup-with-mixed-instances.yml" | |
} | |
resource "aws_s3_bucket" "templates" { | |
acl = "private" | |
region = "${var.aws_region}" | |
bucket = "${local.templates_bucket}" | |
tags = "${module.cluster_label.tags}" | |
force_destroy = "true" | |
} | |
resource "aws_s3_bucket_object" "mixed_instances_template" { | |
bucket = "${aws_s3_bucket.templates.id}" | |
key = "${local.mixed_instances_template}" | |
source = "templates/${local.mixed_instances_template}" | |
etag = "${filemd5("templates/${local.mixed_instances_template}")}" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/compute-workers-cfn-1.tf b/compute-workers-cfn-2.tf | |
index 4cc4ad2..ed45e07 100644 | |
--- a/compute-workers-cfn-1.tf | |
+++ b/compute-workers-cfn-2.tf | |
@@ -17,6 +17,7 @@ resource "aws_cloudformation_stack" "workers" { | |
NodeAutoScalingGroupMinSize = "1" | |
NodeAutoScalingGroupDesiredSize = "3" | |
NodeAutoScalingGroupMaxSize = "9" | |
+ ClusterAutoscalerStatus = "enabled" | |
NodeInstanceType = "c5.2xlarge" | |
ASGAutoAssignPublicIp = "no" | |
OnDemandBaseCapacity = "1" | |
@@ -28,7 +29,7 @@ resource "aws_cloudformation_stack" "workers" { | |
BootstrapArgumentsForOnDemand = "--kubelet-extra-args '--node-labels=lifecycle=OnDemand,node-role.kubernetes.io/worker=true'" | |
} | |
- template_url = "https://s3.amazonaws.com/eksworkshop.com/templates/master/amazon-eks-nodegroup-with-mixed-instances.yml" | |
+ template_url = "https://${aws_s3_bucket.templates.bucket_regional_domain_name}/${local.mixed_instances_template}" | |
lifecycle { | |
ignore_changes = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cluster name bohr | |
resource "aws_cloudformation_stack" "workers" { | |
name = "${module.cluster_label.id}-compute-workers" | |
parameters = { | |
NodeGroupName = "${module.cluster_label.id}-compute-workers" # Unique identifier for the Node Group. | |
ClusterName = "${module.cluster_label.id}" | |
ClusterControlPlaneSecurityGroup = "${aws_security_group.masters.id}" | |
NodeImageId = "${data.aws_ami.worker.id}" | |
NodeInstanceProfile = "${aws_iam_instance_profile.workers.arn}" | |
UseExistingNodeSecurityGroups = "yes" | |
ExistingNodeSecurityGroups = "${aws_security_group.workers.id}" | |
VpcId = "${data.terraform_remote_state.shared.swat_staging_vpc_id}" | |
KeyName = "${data.terraform_remote_state.staging.ec2_key_name}" | |
Subnets = "${join(",",values(data.terraform_remote_state.staging.private_subnets_bohr))}" | |
NodeAutoScalingGroupMinSize = "1" | |
NodeAutoScalingGroupDesiredSize = "3" | |
NodeAutoScalingGroupMaxSize = "9" | |
NodeInstanceType = "c5.2xlarge" | |
ASGAutoAssignPublicIp = "no" | |
OnDemandBaseCapacity = "1" | |
OnDemandPercentageAboveBaseCapacity = "0" # (0-100) | |
SpotInstancePools = "3" # (1-20) | |
InstanceTypesOverride = "c5.2xlarge,m5.2xlarge,c4.2xlarge" # multiple spot instances to override (seperated by comma) | |
BootstrapArgumentsForSpotFleet = "--kubelet-extra-args '--node-labels=lifecycle=Ec2Spot,node-role.kubernetes.io/spot-worker=true --register-with-taints=spotInstance=true:PreferNoSchedule'" | |
BootstrapArgumentsForOnDemand = "--kubelet-extra-args '--node-labels=lifecycle=OnDemand,node-role.kubernetes.io/worker=true'" | |
} | |
template_url = "https://s3.amazonaws.com/eksworkshop.com/templates/master/amazon-eks-nodegroup-with-mixed-instances.yml" | |
lifecycle { | |
ignore_changes = [ | |
"parameters.NodeAutoScalingGroupDesiredSize", | |
"parameters.OnDemandBaseCapacity", | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cluster name bohr | |
resource "aws_cloudformation_stack" "workers" { | |
name = "${module.cluster_label.id}-compute-workers" | |
parameters = { | |
NodeGroupName = "${module.cluster_label.id}-compute-workers" # Unique identifier for the Node Group. | |
ClusterName = "${module.cluster_label.id}" | |
ClusterControlPlaneSecurityGroup = "${aws_security_group.masters.id}" | |
NodeImageId = "${data.aws_ami.worker.id}" | |
NodeInstanceProfile = "${aws_iam_instance_profile.workers.arn}" | |
UseExistingNodeSecurityGroups = "yes" | |
ExistingNodeSecurityGroups = "${aws_security_group.workers.id}" | |
VpcId = "${data.terraform_remote_state.shared.swat_staging_vpc_id}" | |
KeyName = "${data.terraform_remote_state.staging.ec2_key_name}" | |
Subnets = "${join(",",values(data.terraform_remote_state.staging.private_subnets_bohr))}" | |
NodeAutoScalingGroupMinSize = "1" | |
NodeAutoScalingGroupDesiredSize = "3" | |
NodeAutoScalingGroupMaxSize = "9" | |
ClusterAutoscalerStatus = "enabled" | |
NodeInstanceType = "c5.2xlarge" | |
ASGAutoAssignPublicIp = "no" | |
OnDemandBaseCapacity = "1" | |
OnDemandPercentageAboveBaseCapacity = "0" # (0-100) | |
SpotInstancePools = "3" # (1-20) | |
InstanceTypesOverride = "c5.2xlarge,m5.2xlarge,c4.2xlarge" # multiple spot instances to override (seperated by comma) | |
BootstrapArgumentsForSpotFleet = "--kubelet-extra-args '--node-labels=lifecycle=Ec2Spot,node-role.kubernetes.io/spot-worker=true --register-with-taints=spotInstance=true:PreferNoSchedule'" | |
BootstrapArgumentsForOnDemand = "--kubelet-extra-args '--node-labels=lifecycle=OnDemand,node-role.kubernetes.io/worker=true'" | |
} | |
template_url = "https://${aws_s3_bucket.templates.bucket_regional_domain_name}/${local.mixed_instances_template}" | |
lifecycle { | |
ignore_changes = [ | |
"parameters.NodeAutoScalingGroupDesiredSize", | |
"parameters.OnDemandBaseCapacity", | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment