[aws-eks] Unexpected node replacement due to using SSM for AMIs
#4156 introduced retrieving AMI id for EKS worker nodes from SSM by using AWS::SSM::Parameter resource in CF template. It's a great feature when it comes to new deployments but it causes troubles when updating currently deployed stacks with EKS worker nodes. Value of the parameter changes when AWS releases new version of the AMI. For example yesterday there was a change from amazon-eks-node-1.14-v20200312 to amazon-eks-node-1.14-v20200406. The main problem is that this change is not shown in cdk diff. But if we change anything else in the stack, even something irrelevant then Cloudformation implicitly updates all Launch Configurations used by AutoScalingGroups of EKS worker nodes. That results in replacement of every EC2 ( EKS worked node ) of every ASG without any notification before deployment. Its really frustrating because we don't know what will be updated during the deployment and replacing every node is big thing that we should be noticed of before the deployment starts. Can we at least detect the change in cdk diff?
Reproduction Steps
- Deploy stack with EKS cluster. Do no use managed node groups but just add new ASGs usting addCapacity()
- Wait for AWS changes recommended AMI image id in SSM Parameter store.
- Try to deploy stack and notice no changes are detected.
- Change something in stack. ( i.e. max capacity of ASG )
- Deploy stack and notice CF is updating launch configurations with new AMI id.
Error Log
2020-04-09 09:41:00 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CLaunchConfigD2E4A6CF | UPDATE_IN_PROGRESS | Requested update requires the creation of a new physical resource; hence creating one.
2020-04-09 09:41:00 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BLaunchConfig5CCFDD66 | UPDATE_IN_PROGRESS | Requested update requires the creation of a new physical resource; hence creating one.
2020-04-09 09:41:01 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1ALaunchConfigC286DD69 | UPDATE_IN_PROGRESS | Requested update requires the creation of a new physical resource; hence creating one.
2020-04-09 09:41:01 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CLaunchConfigD2E4A6CF | UPDATE_IN_PROGRESS | Resource creation Initiated
2020-04-09 09:41:01 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BLaunchConfig5CCFDD66 | UPDATE_IN_PROGRESS | Resource creation Initiated
2020-04-09 09:41:02 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1ALaunchConfigC286DD69 | UPDATE_COMPLETE | -
2020-04-09 09:41:02 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CLaunchConfigD2E4A6CF | UPDATE_COMPLETE | -
2020-04-09 09:41:02 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1ALaunchConfigC286DD69 | UPDATE_IN_PROGRESS | Resource creation Initiated
2020-04-09 09:41:02 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BLaunchConfig5CCFDD66 | UPDATE_COMPLETE | -
2020-04-09 09:41:09 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | -
2020-04-09 09:41:10 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CASG93B5A949 | UPDATE_IN_PROGRESS | -
2020-04-09 09:41:10 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | -
2020-04-09 09:41:14 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CASG93B5A949 | UPDATE_IN_PROGRESS | Rolling update initiated. Terminating 2 obsolete instance(s) in batches of 1.
2020-04-09 09:41:14 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | Rolling update initiated. Terminating 3 obsolete instance(s) in batches of 1.
2020-04-09 09:41:14 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | Temporarily setting autoscaling group MinSize and DesiredCapacity to 3.
2020-04-09 09:41:14 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | Rolling update initiated. Terminating 3 obsolete instance(s) in batches of 1.
2020-04-09 09:41:15 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | Terminating instance(s) [i-xxxx]; replacing with 1 new instance(s).
2020-04-09 09:41:15 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CASG93B5A949 | UPDATE_IN_PROGRESS | Temporarily setting autoscaling group MinSize and DesiredCapacity to 2.
2020-04-09 09:41:15 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | Temporarily setting autoscaling group MinSize and DesiredCapacity to 3.
2020-04-09 09:41:16 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CASG93B5A949 | UPDATE_IN_PROGRESS | Terminating instance(s) [i-xxxx]; replacing with 1 new instance(s).
2020-04-09 09:41:16 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | Terminating instance(s) [i-xxxx]; replacing with 1 new instance(s).
2020-04-09 09:42:09 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CASG93B5A949 | UPDATE_IN_PROGRESS | Terminating instance(s) [i-xxxx]; replacing with 1 new instance(s).
2020-04-09 09:42:09 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CASG93B5A949 | UPDATE_IN_PROGRESS | Successfully terminated instance(s) [i-xxxx] (Progress 50%).
2020-04-09 09:42:33 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | Terminating instance(s) [i-xxxx]; replacing with 1 new instance(s).
2020-04-09 09:42:33 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | Successfully terminated instance(s) [i-xxxx] (Progress 33%).
2020-04-09 09:42:34 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | Successfully terminated instance(s) [i-xxxx] (Progress 33%).
2020-04-09 09:42:35 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | Terminating instance(s) [i-xxxx]; replacing with 1 new instance(s).
2020-04-09 09:43:02 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CASG93B5A949 | UPDATE_IN_PROGRESS | Successfully terminated instance(s) [i-xxxx] (Progress 100%).
2020-04-09 09:43:05 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1CASG93B5A949 | UPDATE_COMPLETE | -
2020-04-09 09:43:26 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | Terminating instance(s) [i-xxxx]; replacing with 1 new instance(s).
2020-04-09 09:43:26 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | Successfully terminated instance(s) [i-xxxx] (Progress 67%).
2020-04-09 09:43:28 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | Terminating instance(s) [i-xxxx]; replacing with 1 new instance(s).
2020-04-09 09:43:28 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | Successfully terminated instance(s) [i-xxxx] (Progress 67%).
2020-04-09 09:44:22 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_IN_PROGRESS | Successfully terminated instance(s) [i-xxxx] (Progress 100%).
2020-04-09 09:44:24 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1AASGA5AFF92F | UPDATE_COMPLETE | -
2020-04-09 09:44:44 UTC+0200 | SandboxEksClusterEksClusterAsgUsEast1BASG4E9ED460 | UPDATE_IN_PROGRESS | Successfully terminated instance(s) [i-xxxx] (Progress 100%).
Environment
- CLI Version : 1.28.0
Other
This is :bug: Bug Report
Thanks for reporting. I can see why this can cause a pretty major headache. We will look into this.
@stefanolczak The root cause is the update policy of the ASG. Currently, the addCapacity method will default to a RollingUpdate policy, which means any change to the launch configuration will cause node replacements.
We are considering to change this default, but in the meantime, you can specify an update policy of your own to avoid this:
import * as autoscaling from '@aws-cdk/aws-autoscaling';
this.cluster.addCapacity('Nodes', {
instanceType: new ec2.InstanceType('t2.medium'),
minCapacity: 3,
updateType: autoscaling.UpdateType.NONE,
});