├── .gitignore ├── LICENSE ├── README.md ├── outputs.tf ├── v17.tf └── v18.tf /.gitignore: -------------------------------------------------------------------------------- 1 | eks-admin-cluster-role-binding.yaml 2 | eks-admin-service-account.yaml 3 | config-map-aws-auth*.yaml 4 | kubeconfig_* 5 | .idea 6 | 7 | ################################################################# 8 | # Default .gitignore content for all terraform-aws-modules below 9 | ################################################################# 10 | 11 | .DS_Store 12 | 13 | # Local .terraform directories 14 | **/.terraform/* 15 | 16 | # Terraform lockfile 17 | .terraform.lock.hcl 18 | 19 | # .tfstate files 20 | *.tfstate 21 | *.tfstate.* 22 | *.tfplan 23 | 24 | # Crash log files 25 | crash.log 26 | 27 | # Exclude all .tfvars files, which are likely to contain sentitive data, such as 28 | # password, private keys, and other secrets. These should not be part of version 29 | # control as they are data points which are potentially sensitive and subject 30 | # to change depending on the environment. 31 | *.tfvars 32 | 33 | # Ignore override files as they are usually used to override resources locally and so 34 | # are not checked in 35 | override.tf 36 | override.tf.json 37 | *_override.tf 38 | *_override.tf.json 39 | 40 | # Ignore CLI configuration files 41 | .terraformrc 42 | terraform.rc 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Before You Begin 2 | 3 | The steps proposed here are merely that - one proposal to an upgrade path from v17 to v18. The steps below are setup to preserve the control plane and data plane, however, the existing data plane will be ejected from Terraform control to avoid any service disruption. Currently, there are no paths for upgrading the data plane in-place that do not pose a risk of potential downtime. Therefore, the steps outlined here are designed to avoid downtime by following a blue/green approach to upgrading the data plane. The existing (v17) data plane components are ejected from Terraform control which allows for new (v18) data plane components to be deployed alongside the previous version components. Once the new (v18) data plane components are provisioned, users can start to cordon and drain the previous (v17) data plane components, scale them down, and finally remove entirely from AWS. 4 | 5 | ## Control Plane Changes 6 | 7 | Execute the following after changing the module version and executing `terraform init -upgrade=true` 8 | 9 | ⚠️ If you run a `terraform plan` at this time it will fail! 10 | 11 | 1. Add the following settings to avoid disruption to control plane. These settings carry forward v17.x values to avoid disruptive replacement: 12 | 13 | ```hcl 14 | prefix_separator = "" 15 | iam_role_name = $CLUSTER_NAME 16 | cluster_security_group_name = $CLUSTER_NAME 17 | cluster_security_group_description = "EKS cluster security group." 18 | ``` 19 | 20 | ⚠️ If you run a `terraform plan` at this time it will fail! 21 | 22 | 2. Rename cluster IAM role resource using a Terraform state move 23 | 24 | ```sh 25 | terraform state mv 'module.eks.aws_iam_role.cluster[0]' 'module.eks.aws_iam_role.this[0]' 26 | ``` 27 | 28 | ✅ You now can run a plan! 29 | 30 | 3. Update control plane resources 31 | 32 | ```sh 33 | terraform apply -target 'module.eks.aws_iam_role.this[0]' 34 | terraform apply -target 'module.eks.aws_eks_cluster.this[0]' 35 | terraform apply -target 'module.eks.aws_eks_cluster.this[0]' -refresh-only 36 | ``` 37 | 38 | ## Data Plane Changes 39 | 40 | ### "Workers" 41 | 42 | The following commands will remove the shared "workers" IAM role and security group from Terraform control. Users will need to be clean up these resources manually after the migration has completed (once they are no longer utilized by any data plane resources). 43 | 44 | ```sh 45 | terraform state rm 'module.eks.aws_iam_role.workers[0]' 46 | terraform state rm 'module.eks.aws_iam_role_policy_attachment.workers_AmazonEKS_CNI_Policy[0]' 47 | terraform state rm 'module.eks.aws_iam_role_policy_attachment.workers_AmazonEKSWorkerNodePolicy[0]' 48 | terraform state rm 'module.eks.aws_iam_role_policy_attachment.workers_AmazonEC2ContainerRegistryReadOnly[0]' 49 | 50 | terraform state rm 'module.eks.aws_security_group.workers[0]' 51 | terraform state rm 'module.eks.aws_security_group_rule.workers_ingress_self[0]' 52 | terraform state rm 'module.eks.aws_security_group_rule.workers_ingress_cluster_https[0]' 53 | terraform state rm 'module.eks.aws_security_group_rule.workers_ingress_cluster[0]' 54 | terraform state rm 'module.eks.aws_security_group_rule.workers_egress_internet[0]' 55 | terraform state rm 'module.eks.aws_security_group_rule.cluster_https_worker_ingress[0]' 56 | terraform state rm 'module.eks.aws_security_group_rule.cluster_egress_internet[0]' 57 | ``` 58 | 59 | ### Fargate Profiles 60 | 61 | ```sh 62 | terraform state rm 'module.eks.module.fargate.aws_iam_role.eks_fargate_pod[0]' 63 | terraform state rm 'module.eks.module.fargate.aws_eks_fargate_profile.this["default"]' 64 | terraform state rm 'module.eks.module.fargate.aws_iam_role_policy_attachment.eks_fargate_pod[0]' 65 | ``` 66 | 67 | ### EKS Managed Node Groups 68 | 69 | ```sh 70 | terraform state rm 'module.eks.module.node_groups.aws_eks_node_group.workers["example"]' 71 | ``` 72 | 73 | ### Self Managed Node Groups 74 | 75 | ```sh 76 | terraform state rm 'module.eks.aws_launch_template.workers_launch_template[0]' 77 | terraform state rm 'module.eks.aws_autoscaling_group.workers_launch_template[0]' 78 | terraform state rm 'module.eks.aws_iam_instance_profile.workers_launch_template[0]' 79 | ``` 80 | 81 | ## Misc 82 | 83 | - `module.eks.local_file.kubeconfig[0]` will be destroyed, users are encouraged to use `aws eks update-kubeconfig --name ` in its place 84 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clowdhaus/eks-v17-v18-migrate/c3c715c3c673c39ccd3efbefa74a0b93d64b3e5c/outputs.tf -------------------------------------------------------------------------------- /v17.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | } 4 | 5 | provider "kubernetes" { 6 | host = module.eks.cluster_endpoint 7 | cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data) 8 | 9 | exec { 10 | api_version = "client.authentication.k8s.io/v1beta1" 11 | command = "aws" 12 | # This requires the awscli to be installed locally where Terraform is executed 13 | args = ["eks", "get-token", "--cluster-name", module.eks.cluster_id] 14 | } 15 | } 16 | 17 | locals { 18 | name = "migrate" 19 | cluster_version = "1.22" 20 | region = "us-east-1" 21 | } 22 | 23 | ################################################################################ 24 | # EKS Module 25 | ################################################################################ 26 | 27 | module "eks" { 28 | source = "terraform-aws-modules/eks/aws" 29 | version = "17.24.0" 30 | 31 | cluster_name = local.name 32 | cluster_version = local.cluster_version 33 | 34 | vpc_id = module.vpc.vpc_id 35 | subnets = [module.vpc.private_subnets[0], module.vpc.public_subnets[1]] 36 | fargate_subnets = [module.vpc.private_subnets[2]] 37 | 38 | cluster_endpoint_private_access = true 39 | cluster_endpoint_public_access = true 40 | 41 | worker_additional_security_group_ids = [aws_security_group.all_worker_mgmt.id] 42 | 43 | # Worker groups (using Launch Templates) 44 | worker_groups_launch_template = [ 45 | { 46 | name = "spot-1" 47 | override_instance_types = ["m5.large", "m5a.large", "m5d.large", "m5ad.large"] 48 | spot_instance_pools = 4 49 | asg_max_size = 5 50 | asg_desired_capacity = 5 51 | kubelet_extra_args = "--node-labels=node.kubernetes.io/lifecycle=spot" 52 | public_ip = true 53 | }, 54 | ] 55 | 56 | # Managed Node Groups 57 | node_groups_defaults = { 58 | ami_type = "AL2_x86_64" 59 | disk_size = 50 60 | } 61 | 62 | node_groups = { 63 | example = { 64 | desired_capacity = 1 65 | max_capacity = 10 66 | min_capacity = 1 67 | 68 | instance_types = ["t3.large"] 69 | capacity_type = "SPOT" 70 | k8s_labels = { 71 | Environment = "test" 72 | GithubRepo = "terraform-aws-eks" 73 | GithubOrg = "terraform-aws-modules" 74 | } 75 | additional_tags = { 76 | ExtraTag = "example" 77 | } 78 | taints = [ 79 | { 80 | key = "dedicated" 81 | value = "gpuGroup" 82 | effect = "NO_SCHEDULE" 83 | } 84 | ] 85 | update_config = { 86 | max_unavailable_percentage = 50 # or set `max_unavailable` 87 | } 88 | } 89 | } 90 | 91 | # Fargate 92 | fargate_profiles = { 93 | default = { 94 | name = "default" 95 | selectors = [ 96 | { 97 | namespace = "kube-system" 98 | labels = { 99 | k8s-app = "kube-dns" 100 | } 101 | }, 102 | { 103 | namespace = "default" 104 | } 105 | ] 106 | 107 | tags = { 108 | Owner = "test" 109 | } 110 | 111 | timeouts = { 112 | create = "20m" 113 | delete = "20m" 114 | } 115 | } 116 | } 117 | 118 | # AWS Auth (kubernetes_config_map) 119 | map_roles = [ 120 | { 121 | rolearn = "arn:aws:iam::66666666666:role/role1" 122 | username = "role1" 123 | groups = ["system:masters"] 124 | }, 125 | ] 126 | 127 | map_users = [ 128 | { 129 | userarn = "arn:aws:iam::66666666666:user/user1" 130 | username = "user1" 131 | groups = ["system:masters"] 132 | }, 133 | { 134 | userarn = "arn:aws:iam::66666666666:user/user2" 135 | username = "user2" 136 | groups = ["system:masters"] 137 | }, 138 | ] 139 | 140 | map_accounts = [ 141 | "777777777777", 142 | "888888888888", 143 | ] 144 | 145 | tags = { 146 | Example = local.name 147 | GithubRepo = "terraform-aws-eks" 148 | GithubOrg = "terraform-aws-modules" 149 | } 150 | } 151 | 152 | ################################################################################ 153 | # Additional security groups for workers 154 | ################################################################################ 155 | 156 | resource "aws_security_group" "worker_group_mgmt_one" { 157 | name_prefix = "worker_group_mgmt_one" 158 | vpc_id = module.vpc.vpc_id 159 | 160 | ingress { 161 | from_port = 22 162 | to_port = 22 163 | protocol = "tcp" 164 | 165 | cidr_blocks = [ 166 | "10.0.0.0/8", 167 | ] 168 | } 169 | } 170 | 171 | resource "aws_security_group" "worker_group_mgmt_two" { 172 | name_prefix = "worker_group_mgmt_two" 173 | vpc_id = module.vpc.vpc_id 174 | 175 | ingress { 176 | from_port = 22 177 | to_port = 22 178 | protocol = "tcp" 179 | 180 | cidr_blocks = [ 181 | "192.168.0.0/16", 182 | ] 183 | } 184 | } 185 | 186 | resource "aws_security_group" "all_worker_mgmt" { 187 | name_prefix = "all_worker_management" 188 | vpc_id = module.vpc.vpc_id 189 | 190 | ingress { 191 | from_port = 22 192 | to_port = 22 193 | protocol = "tcp" 194 | 195 | cidr_blocks = [ 196 | "10.0.0.0/8", 197 | "172.16.0.0/12", 198 | "192.168.0.0/16", 199 | ] 200 | } 201 | } 202 | 203 | ################################################################################ 204 | # Supporting resources 205 | ################################################################################ 206 | 207 | data "aws_availability_zones" "available" {} 208 | 209 | module "vpc" { 210 | source = "terraform-aws-modules/vpc/aws" 211 | version = "~> 3.0" 212 | 213 | name = local.name 214 | cidr = "10.0.0.0/16" 215 | 216 | azs = slice(data.aws_availability_zones.available.names, 0, 3) 217 | private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] 218 | public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"] 219 | 220 | enable_nat_gateway = true 221 | single_nat_gateway = true 222 | enable_dns_hostnames = true 223 | 224 | public_subnet_tags = { 225 | "kubernetes.io/cluster/${local.name}" = "shared" 226 | "kubernetes.io/role/elb" = "1" 227 | } 228 | 229 | private_subnet_tags = { 230 | "kubernetes.io/cluster/${local.name}" = "shared" 231 | "kubernetes.io/role/internal-elb" = "1" 232 | } 233 | 234 | tags = { 235 | Example = local.name 236 | GithubRepo = "terraform-aws-eks" 237 | GithubOrg = "terraform-aws-modules" 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /v18.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | } 4 | 5 | provider "kubernetes" { 6 | host = module.eks.cluster_endpoint 7 | cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data) 8 | 9 | exec { 10 | api_version = "client.authentication.k8s.io/v1beta1" 11 | command = "aws" 12 | # This requires the awscli to be installed locally where Terraform is executed 13 | args = ["eks", "get-token", "--cluster-name", module.eks.cluster_id] 14 | } 15 | } 16 | 17 | locals { 18 | name = "migrate" 19 | cluster_version = "1.22" 20 | region = "us-east-1" 21 | } 22 | 23 | ################################################################################ 24 | # EKS Module 25 | ################################################################################ 26 | 27 | module "eks" { 28 | source = "terraform-aws-modules/eks/aws" 29 | version = "18.28.0" 30 | 31 | cluster_name = local.name 32 | cluster_version = local.cluster_version 33 | 34 | vpc_id = module.vpc.vpc_id 35 | subnet_ids = [module.vpc.private_subnets[0], module.vpc.public_subnets[1]] 36 | 37 | cluster_endpoint_private_access = true 38 | cluster_endpoint_public_access = true 39 | 40 | # Add to maintain v17.x settings to avoid control plane replacement 41 | prefix_separator = "" 42 | iam_role_name = local.name 43 | cluster_security_group_name = local.name 44 | cluster_security_group_description = "EKS cluster security group." 45 | 46 | # Add to provide similar level of acces as v17.x 47 | node_security_group_additional_rules = { 48 | ingress_control_plane = { 49 | description = "Node to node all ports/protocols" 50 | protocol = "-1" 51 | from_port = 0 52 | to_port = 0 53 | type = "ingress" 54 | self = true 55 | } 56 | ingress_self_all = { 57 | description = "Control plane to nodes on ephemeral ports" 58 | protocol = "tcp" 59 | from_port = 1025 60 | to_port = 65535 61 | type = "ingress" 62 | source_cluster_security_group = true 63 | } 64 | egress_all = { 65 | description = "Node all egress" 66 | protocol = "-1" 67 | from_port = 0 68 | to_port = 0 69 | type = "egress" 70 | cidr_blocks = ["0.0.0.0/0"] 71 | } 72 | } 73 | 74 | # Worker groups (using Launch Templates) 75 | self_managed_node_group_defaults = { 76 | vpc_security_group_ids = [aws_security_group.all_worker_mgmt.id] 77 | 78 | # New in v18.x 79 | create_security_group = false 80 | } 81 | 82 | self_managed_node_groups = { 83 | spot1 = { 84 | use_mixed_instances_policy = true 85 | mixed_instances_policy = { 86 | instances_distribution = { 87 | on_demand_base_capacity = 0 88 | on_demand_percentage_above_base_capacity = 0 89 | spot_allocation_strategy = "lowest-price" 90 | } 91 | override = [ 92 | { instance_type = "m5.large" }, 93 | { instance_type = "m5a.large" }, 94 | { instance_type = "m5d.large" }, 95 | { instance_type = "m5ad.large" }, 96 | ] 97 | } 98 | 99 | max_size = 5 100 | desired_size = 5 101 | kubelet_extra_args = "--node-labels=node.kubernetes.io/lifecycle=spot" 102 | } 103 | } 104 | 105 | # Managed Node Groups 106 | eks_managed_node_group_defaults = { 107 | # New in v18.x 108 | create_security_group = false 109 | } 110 | 111 | eks_managed_node_groups = { 112 | example = { 113 | min_size = 1 114 | max_size = 10 115 | desired_size = 1 116 | 117 | instance_types = ["t3.large"] 118 | capacity_type = "SPOT" 119 | labels = { 120 | Environment = "test" 121 | GithubRepo = "terraform-aws-eks" 122 | GithubOrg = "terraform-aws-modules" 123 | } 124 | 125 | tags = { 126 | ExtraTag = "example" 127 | } 128 | 129 | taints = [ 130 | { 131 | key = "dedicated" 132 | value = "gpuGroup" 133 | effect = "NO_SCHEDULE" 134 | } 135 | ] 136 | 137 | update_config = { 138 | max_unavailable_percentage = 33 # or set `max_unavailable` 139 | } 140 | } 141 | } 142 | 143 | # Fargate 144 | fargate_profile_defaults = { 145 | subnet_ids = [module.vpc.private_subnets[2]] 146 | } 147 | 148 | fargate_profiles = { 149 | default = { 150 | name = "default2" 151 | selectors = [ 152 | { 153 | namespace = "kube-system" 154 | labels = { 155 | k8s-app = "kube-dns" 156 | } 157 | }, 158 | { 159 | namespace = "default" 160 | } 161 | ] 162 | 163 | tags = { 164 | Owner = "test" 165 | } 166 | 167 | timeouts = { 168 | create = "20m" 169 | delete = "20m" 170 | } 171 | } 172 | } 173 | 174 | # AWS Auth (kubernetes_config_map) 175 | create_aws_auth_configmap = true 176 | manage_aws_auth_configmap = true 177 | aws_auth_roles = [ 178 | { 179 | rolearn = "arn:aws:iam::66666666666:role/role1" 180 | username = "role1" 181 | groups = ["system:masters"] 182 | }, 183 | ] 184 | 185 | aws_auth_users = [ 186 | { 187 | userarn = "arn:aws:iam::66666666666:user/user1" 188 | username = "user1" 189 | groups = ["system:masters"] 190 | }, 191 | { 192 | userarn = "arn:aws:iam::66666666666:user/user2" 193 | username = "user2" 194 | groups = ["system:masters"] 195 | }, 196 | ] 197 | 198 | aws_auth_accounts = [ 199 | "777777777777", 200 | "888888888888", 201 | ] 202 | 203 | tags = { 204 | Example = local.name 205 | GithubRepo = "terraform-aws-eks" 206 | GithubOrg = "terraform-aws-modules" 207 | } 208 | } 209 | 210 | ################################################################################ 211 | # Additional security groups for workers 212 | ################################################################################ 213 | 214 | resource "aws_security_group" "worker_group_mgmt_one" { 215 | name_prefix = "worker_group_mgmt_one" 216 | vpc_id = module.vpc.vpc_id 217 | 218 | ingress { 219 | from_port = 22 220 | to_port = 22 221 | protocol = "tcp" 222 | 223 | cidr_blocks = [ 224 | "10.0.0.0/8", 225 | ] 226 | } 227 | } 228 | 229 | resource "aws_security_group" "worker_group_mgmt_two" { 230 | name_prefix = "worker_group_mgmt_two" 231 | vpc_id = module.vpc.vpc_id 232 | 233 | ingress { 234 | from_port = 22 235 | to_port = 22 236 | protocol = "tcp" 237 | 238 | cidr_blocks = [ 239 | "192.168.0.0/16", 240 | ] 241 | } 242 | } 243 | 244 | resource "aws_security_group" "all_worker_mgmt" { 245 | name_prefix = "all_worker_management" 246 | vpc_id = module.vpc.vpc_id 247 | 248 | ingress { 249 | from_port = 22 250 | to_port = 22 251 | protocol = "tcp" 252 | 253 | cidr_blocks = [ 254 | "10.0.0.0/8", 255 | "172.16.0.0/12", 256 | "192.168.0.0/16", 257 | ] 258 | } 259 | } 260 | 261 | ################################################################################ 262 | # Supporting resources 263 | ################################################################################ 264 | 265 | data "aws_availability_zones" "available" {} 266 | 267 | module "vpc" { 268 | source = "terraform-aws-modules/vpc/aws" 269 | version = "~> 3.0" 270 | 271 | name = local.name 272 | cidr = "10.0.0.0/16" 273 | 274 | azs = slice(data.aws_availability_zones.available.names, 0, 3) 275 | private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] 276 | public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"] 277 | 278 | enable_nat_gateway = true 279 | single_nat_gateway = true 280 | enable_dns_hostnames = true 281 | 282 | public_subnet_tags = { 283 | "kubernetes.io/cluster/${local.name}" = "shared" 284 | "kubernetes.io/role/elb" = "1" 285 | } 286 | 287 | private_subnet_tags = { 288 | "kubernetes.io/cluster/${local.name}" = "shared" 289 | "kubernetes.io/role/internal-elb" = "1" 290 | } 291 | 292 | tags = { 293 | Example = local.name 294 | GithubRepo = "terraform-aws-eks" 295 | GithubOrg = "terraform-aws-modules" 296 | } 297 | } 298 | --------------------------------------------------------------------------------