Skip to content

Commit

Permalink
chore(eks): updated the eks launch template support topic in the docs (
Browse files Browse the repository at this point in the history
…aws#12272)

Closes aws#12256

Clarified the usage of custom user data with default or custom AMI by adding another example and pointing out the differences.

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 the user to change the user data without having it applied to the nodes after deploy.

Removed unnecessary wrapping of instance type string with typed version and calling toString.

Make the sentence about defining instance type either in launch template or node group more understandable.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
dirknilius authored and Mohan Rajendran committed Jan 24, 2021
1 parent b8e39b2 commit 33fc397
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions packages/@aws-cdk/aws-eks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,40 @@ 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.

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
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,
},
});

```

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
Expand All @@ -245,19 +277,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).
Expand Down

0 comments on commit 33fc397

Please sign in to comment.