Home > OS >  How can I edit Nodegroup in AWS EKS from AWS CDK
How can I edit Nodegroup in AWS EKS from AWS CDK

Time:07-06

I use AWS CDK to create eks cluster then use addNodegroupCapacity to add nodegroup.

    const myNodeGroup = cluster.addNodegroupCapacity('my-node-group', {
      nodegroupName: 'my-node-group',
      instanceTypes: [
        new ec2.InstanceType('t3a.small'), 
      ],
      minSize: 1,
      desiredSize: 1,
      maxSize: 1,
      diskSize: 10,
      capacityType: eks.CapacityType.SPOT,
      amiType: eks.NodegroupAmiType.AL2_X86_64,
      subnets: { subnetType: ec2.SubnetType.PUBLIC },
    })

I want to change subnet to

    subnets: { availabilityZones: ['ap-southeast-1a'] }

When I made change in CDK I got an error

    Resource handler returned message: "NodeGroup already exists with name my-node-group and cluster name  (Service: Eks, Status Code: 409, Request ID: {Request ID})" (RequestToken: {RequestToken}, HandlerErrorCode: AlreadyExists)

How can I edit this nodegroup from AWS CDK or I have to delete and recreate it?

CodePudding user response:

Changing the subnet is a replacement operation, which means the NodeGroup will be destroyed and another created. However, your explicit nodegroupName is interfering with this CloudFormation process. For this reason it's best practice to use generated resource names, not physical names.

Delete the resource manually. Remove the nodegroupName prop to avoid this problem in the future.

  • Related