|
| 1 | +# Compute Resources |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | +- [EKS Managed Node Groups](https://github.com/terraform-aws-module/terraform-aws-eks/blob/master/docs/node_groups.md#eks-managed-node-groups) |
| 6 | +- [Self Managed Node Groups](https://github.com/terraform-aws-module/terraform-aws-eks/blob/master/docs/node_groups.md#self-managed-node-groups) |
| 7 | +- [Fargate Profiles](https://github.com/terraform-aws-module/terraform-aws-eks/blob/master/docs/node_groups.md#fargate-profiles) |
| 8 | +- [Default Configurations](https://github.com/terraform-aws-module/terraform-aws-eks/blob/master/docs/node_groups.md#default-configurations) |
| 9 | + |
| 10 | +ℹ️ Only the pertinent attributes are shown below for brevity |
| 11 | + |
| 12 | +### EKS Managed Node Groups |
| 13 | + |
| 14 | +Refer to the [EKS Managed Node Group documentation](https://docs.aws.amazon.com/eks/latest/userguide/managed-node-groups.html) documentation for service related details. |
| 15 | + |
| 16 | +1. The module creates a custom launch template by default to ensure settings such as tags are propagated to instances. To use the default template provided by the AWS EKS managed node group service, disable the launch template creation and set the `launch_template_name` to an empty string: |
| 17 | + |
| 18 | +```hcl |
| 19 | + eks_managed_node_groups = { |
| 20 | + default = { |
| 21 | + create_launch_template = false |
| 22 | + launch_template_name = "" |
| 23 | + } |
| 24 | + } |
| 25 | +``` |
| 26 | + |
| 27 | +2. Native support for Bottlerocket OS is provided by providing the respective AMI type: |
| 28 | + |
| 29 | +```hcl |
| 30 | + eks_managed_node_groups = { |
| 31 | + bottlerocket_default = { |
| 32 | + create_launch_template = false |
| 33 | + launch_template_name = "" |
| 34 | +
|
| 35 | + ami_type = "BOTTLEROCKET_x86_64" |
| 36 | + platform = "bottlerocket" |
| 37 | + } |
| 38 | + } |
| 39 | +``` |
| 40 | + |
| 41 | +3. Users have limited support to extend the user data that is pre-pended to the user data provided by the AWS EKS Managed Node Group service: |
| 42 | + |
| 43 | +```hcl |
| 44 | + eks_managed_node_groups = { |
| 45 | + prepend_userdata = { |
| 46 | + # See issue https://github.com/awslabs/amazon-eks-ami/issues/844 |
| 47 | + pre_bootstrap_user_data = <<-EOT |
| 48 | + #!/bin/bash |
| 49 | + set -ex |
| 50 | + cat <<-EOF > /etc/profile.d/bootstrap.sh |
| 51 | + export CONTAINER_RUNTIME="containerd" |
| 52 | + export USE_MAX_PODS=false |
| 53 | + export KUBELET_EXTRA_ARGS="--max-pods=110" |
| 54 | + EOF |
| 55 | + # Source extra environment variables in bootstrap script |
| 56 | + sed -i '/^set -o errexit/a\\nsource /etc/profile.d/bootstrap.sh' /etc/eks/bootstrap.sh |
| 57 | + EOT |
| 58 | + } |
| 59 | + } |
| 60 | +``` |
| 61 | + |
| 62 | +4. Bottlerocket OS is supported in a similar manner. However, note that the user data for Bottlerocket OS uses the TOML format: |
| 63 | + |
| 64 | +```hcl |
| 65 | + eks_managed_node_groups = { |
| 66 | + bottlerocket_prepend_userdata = { |
| 67 | + ami_type = "BOTTLEROCKET_x86_64" |
| 68 | + platform = "bottlerocket" |
| 69 | +
|
| 70 | + bootstrap_extra_args = <<-EOT |
| 71 | + # extra args added |
| 72 | + [settings.kernel] |
| 73 | + lockdown = "integrity" |
| 74 | + EOT |
| 75 | + } |
| 76 | + } |
| 77 | +``` |
| 78 | + |
| 79 | +5. When using a custom AMI, the AWS EKS Managed Node Group service will NOT inject the necessary bootstrap script into the supplied user data. Users can elect to provide their own user data to bootstrap and connect or opt in to use the module provided user data: |
| 80 | + |
| 81 | +```hcl |
| 82 | + eks_managed_node_groups = { |
| 83 | + custom_ami = { |
| 84 | + ami_id = "ami-0caf35bc73450c396" |
| 85 | +
|
| 86 | + # By default, EKS managed node groups will not append bootstrap script; |
| 87 | + # this adds it back in using the default template provided by the module |
| 88 | + # Note: this assumes the AMI provided is an EKS optimized AMI derivative |
| 89 | + enable_bootstrap_user_data = true |
| 90 | +
|
| 91 | + bootstrap_extra_args = "--container-runtime containerd --kubelet-extra-args '--max-pods=20'" |
| 92 | +
|
| 93 | + pre_bootstrap_user_data = <<-EOT |
| 94 | + export CONTAINER_RUNTIME="containerd" |
| 95 | + export USE_MAX_PODS=false |
| 96 | + EOT |
| 97 | +
|
| 98 | + # Because we have full control over the user data supplied, we can also run additional |
| 99 | + # scripts/configuration changes after the bootstrap script has been run |
| 100 | + post_bootstrap_user_data = <<-EOT |
| 101 | + echo "you are free little kubelet!" |
| 102 | + EOT |
| 103 | + } |
| 104 | + } |
| 105 | +``` |
| 106 | + |
| 107 | +6. There is similar support for Bottlerocket OS: |
| 108 | + |
| 109 | +```hcl |
| 110 | + eks_managed_node_groups = { |
| 111 | + bottlerocket_custom_ami = { |
| 112 | + ami_id = "ami-0ff61e0bcfc81dc94" |
| 113 | + platform = "bottlerocket" |
| 114 | +
|
| 115 | + # use module user data template to bootstrap |
| 116 | + enable_bootstrap_user_data = true |
| 117 | + # this will get added to the template |
| 118 | + bootstrap_extra_args = <<-EOT |
| 119 | + # extra args added |
| 120 | + [settings.kernel] |
| 121 | + lockdown = "integrity" |
| 122 | +
|
| 123 | + [settings.kubernetes.node-labels] |
| 124 | + "label1" = "foo" |
| 125 | + "label2" = "bar" |
| 126 | +
|
| 127 | + [settings.kubernetes.node-taints] |
| 128 | + "dedicated" = "experimental:PreferNoSchedule" |
| 129 | + "special" = "true:NoSchedule" |
| 130 | + EOT |
| 131 | + } |
| 132 | + } |
| 133 | +``` |
| 134 | + |
| 135 | +See the [`examples/eks_managed_node_group/` example](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/eks_managed_node_group) for a working example of various configurations. |
| 136 | + |
| 137 | +### Self Managed Node Groups |
| 138 | + |
| 139 | +Refer to the [Self Managed Node Group documentation](https://docs.aws.amazon.com/eks/latest/userguide/worker.html) documentation for service related details. |
| 140 | + |
| 141 | +1. The `self-managed-node-group` uses the latest AWS EKS Optimized AMI (Linux) for the given Kubernetes version by default: |
| 142 | + |
| 143 | +```hcl |
| 144 | + cluster_version = "1.21" |
| 145 | +
|
| 146 | + # This self managed node group will use the latest AWS EKS Optimized AMI for Kubernetes 1.21 |
| 147 | + self_managed_node_groups = { |
| 148 | + default = {} |
| 149 | + } |
| 150 | +``` |
| 151 | + |
| 152 | +2. To use Bottlerocket, specify the `platform` as `bottlerocket` and supply a Bottlerocket OS AMI: |
| 153 | + |
| 154 | +```hcl |
| 155 | + cluster_version = "1.21" |
| 156 | +
|
| 157 | + self_managed_node_groups = { |
| 158 | + bottlerocket = { |
| 159 | + platform = "bottlerocket" |
| 160 | + ami_id = data.aws_ami.bottlerocket_ami.id |
| 161 | + } |
| 162 | + } |
| 163 | +``` |
| 164 | + |
| 165 | +See the [`examples/self_managed_node_group/` example](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/self_managed_node_group) for a working example of various configurations. |
| 166 | + |
| 167 | +### Fargate Profiles |
| 168 | + |
| 169 | +Fargate profiles are straightforward to use and therefore no further details are provided here. See the [`examples/fargate_profile/` example](https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/fargate_profile) for a working example of various configurations. |
| 170 | + |
| 171 | +### Default Configurations |
| 172 | + |
| 173 | +Each type of compute resource (EKS managed node group, self managed node group, or Fargate profile) provides the option for users to specify a default configuration. These default configurations can be overridden from within the compute resource's individual definition. The order of precedence for configurations (from highest to least precedence): |
| 174 | + |
| 175 | +- Compute resource individual configuration |
| 176 | + - Compute resource family default configuration (`eks_managed_node_group_defaults`, `self_managed_node_group_defaults`, `fargate_profile_defaults`) |
| 177 | + - Module default configuration (see `variables.tf` and `node_groups.tf`) |
| 178 | + |
| 179 | +For example, the following creates 4 AWS EKS Managed Node Groups: |
| 180 | + |
| 181 | +```hcl |
| 182 | + eks_managed_node_group_defaults = { |
| 183 | + ami_type = "AL2_x86_64" |
| 184 | + disk_size = 50 |
| 185 | + instance_types = ["m6i.large", "m5.large", "m5n.large", "m5zn.large"] |
| 186 | + } |
| 187 | +
|
| 188 | + eks_managed_node_groups = { |
| 189 | + # Uses module default configurations overridden by configuration above |
| 190 | + default = {} |
| 191 | +
|
| 192 | + # This further overrides the instance types used |
| 193 | + compute = { |
| 194 | + instance_types = ["c5.large", "c6i.large", "c6d.large"] |
| 195 | + } |
| 196 | +
|
| 197 | + # This further overrides the instance types and disk size used |
| 198 | + persistent = { |
| 199 | + disk_size = 1024 |
| 200 | + instance_types = ["r5.xlarge", "r6i.xlarge", "r5b.xlarge"] |
| 201 | + } |
| 202 | +
|
| 203 | + # This overrides the OS used |
| 204 | + bottlerocket = { |
| 205 | + ami_type = "BOTTLEROCKET_x86_64" |
| 206 | + platform = "bottlerocket" |
| 207 | + } |
| 208 | + } |
| 209 | +``` |
0 commit comments