From 014e95692f35bf93e80087a32b5eb8da5c5fb445 Mon Sep 17 00:00:00 2001 From: Dirk Nilius Date: Tue, 29 Dec 2020 23:14:53 +0100 Subject: [PATCH 1/3] fix(eks): updated the eks launch template support topic in the docs fixes #12256 Clarified the usage of custom user data with default or custom AMI by adding another example and pointing out the differences. Also changed the launch template reference in the examples to use the latest version rather than the default. If you don't know the difference it would be unexpected for an user to change the user data without having it applied to the nodes after deploy. Make the sentence about defining instance type either in launch template or node group more understandable. --- packages/@aws-cdk/aws-eks/README.md | 44 +++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-eks/README.md b/packages/@aws-cdk/aws-eks/README.md index 0b92c183fb786..15adac82c4412 100644 --- a/packages/@aws-cdk/aws-eks/README.md +++ b/packages/@aws-cdk/aws-eks/README.md @@ -232,8 +232,42 @@ cluster.addNodegroupCapacity('extra-ng-spot', { #### Launch Template Support -You can specify a launch template that the node group will use. Note that when using a custom AMI, Amazon EKS doesn't merge any user data. -Rather, You are responsible for supplying the required bootstrap commands for nodes to join the cluster. +You can specify a launch template that the node group will use. For example, this can be useful if you want to use +a custom AMI or add custom user data. + +Since the custom user data is merged with the Amazon EKS user data, it must be encoded in the MIME multi-part +archive format. Visit the [Launch Template Docs](https://docs.aws.amazon.com/eks/latest/userguide/launch-templates.html#launch-template-user-data) +for insights. + +```ts +const userData = `MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="==MYBOUNDARY==" + +--==MYBOUNDARY== +Content-Type: text/x-shellscript; charset="us-ascii" + +#!/bin/bash +echo "Running custom user data script" + +--==MYBOUNDARY==--\\ +`; +const lt = new ec2.CfnLaunchTemplate(this, 'LaunchTemplate', { + launchTemplateData: { + instanceType: 't3.small', + userData: Fn.base64(userData), + }, +}); +cluster.addNodegroupCapacity('extra-ng', { + launchTemplateSpec: { + id: lt.ref, + version: lt.attrLatestVersionNumber, + }, +}); + +``` + +When using a custom AMI, Amazon EKS doesn't merge any user data. +Rather, you are responsible for supplying the required bootstrap commands for nodes to join the cluster. In the following example, `/ect/eks/bootstrap.sh` from the AMI will be used to bootstrap the node. ```ts @@ -245,19 +279,19 @@ userData.addCommands( const lt = new ec2.CfnLaunchTemplate(this, 'LaunchTemplate', { launchTemplateData: { imageId: 'some-ami-id', // custom AMI - instanceType: new ec2.InstanceType('t3.small').toString(), + instanceType: 't3.small', userData: Fn.base64(userData.render()), }, }); cluster.addNodegroupCapacity('extra-ng', { launchTemplateSpec: { id: lt.ref, - version: lt.attrDefaultVersionNumber, + version: lt.attrLatestVersionNumber, }, }); ``` -You may specify one or instance types in either the `instanceTypes` property of `NodeGroup` or in the launch template, **but not both**. +You may specify one `instanceType` in the launch template or multiple `instanceTypes` in the node group, **but not both**. > For more details visit [Launch Template Support](https://docs.aws.amazon.com/eks/latest/userguide/launch-templates.html). From 7b1da1008e55a71f616092991c1bba0759ed32fa Mon Sep 17 00:00:00 2001 From: Eli Polonsky Date: Fri, 15 Jan 2021 15:07:28 +0200 Subject: [PATCH 2/3] rephrasing --- packages/@aws-cdk/aws-eks/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-eks/README.md b/packages/@aws-cdk/aws-eks/README.md index 15adac82c4412..4dc71ff2ee725 100644 --- a/packages/@aws-cdk/aws-eks/README.md +++ b/packages/@aws-cdk/aws-eks/README.md @@ -235,9 +235,8 @@ cluster.addNodegroupCapacity('extra-ng-spot', { You can specify a launch template that the node group will use. For example, this can be useful if you want to use a custom AMI or add custom user data. -Since the custom user data is merged with the Amazon EKS user data, it must be encoded in the MIME multi-part -archive format. Visit the [Launch Template Docs](https://docs.aws.amazon.com/eks/latest/userguide/launch-templates.html#launch-template-user-data) -for insights. +When supplying a custom user data script, it must be encoded in the MIME multi-part archive format, since Amazon EKS merges with its own user data. Visit the [Launch Template Docs](https://docs.aws.amazon.com/eks/latest/userguide/launch-templates.html#launch-template-user-data) +for mode details. ```ts const userData = `MIME-Version: 1.0 From c306739e81e98ced8d68e45784c08d3ea5c19abf Mon Sep 17 00:00:00 2001 From: Eli Polonsky Date: Fri, 15 Jan 2021 15:07:34 +0200 Subject: [PATCH 3/3] rephrasing --- packages/@aws-cdk/aws-eks/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-eks/README.md b/packages/@aws-cdk/aws-eks/README.md index 4dc71ff2ee725..b8ec8b7a9ba76 100644 --- a/packages/@aws-cdk/aws-eks/README.md +++ b/packages/@aws-cdk/aws-eks/README.md @@ -265,8 +265,7 @@ cluster.addNodegroupCapacity('extra-ng', { ``` -When using a custom AMI, Amazon EKS doesn't merge any user data. -Rather, you are responsible for supplying the required bootstrap commands for nodes to join the cluster. +Note that when using a custom AMI, Amazon EKS doesn't merge any user data. Which means you do not need the multi-part encoding. and are responsible for supplying the required bootstrap commands for nodes to join the cluster. In the following example, `/ect/eks/bootstrap.sh` from the AMI will be used to bootstrap the node. ```ts