aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

[aws-eks] Default NodeGroup uses all subnets of VPC instead of selected ones

Open moserda opened this issue 6 years ago • 3 comments

When creating an EKS cluster with a custom subnet selection, the default NodeGroup tries to use all subnets of the VPC instead of the selected ones, which results in CloudFormation failing with Subnets are not tagged with the required tag. Please tag all subnets with Key: kubernetes.io/cluster/...

Reproduction Steps

const vpc = ec2.Vpc.fromLookup(this, "myvpc", {
  vpcId: "<VPC ID of VPC with multiple private subnets>"
});

const cluster = new eks.Cluster(this, "mycluster", {
  clusterName: "mycluster",
  version: eks.KubernetesVersion.V1_17,
  defaultCapacityType: eks.DefaultCapacityType.NODEGROUP,
  defaultCapacity: 2,
  defaultCapacityInstance: new ec2.InstanceType(defaultCapacityInstance),
  endpointAccess: eks.EndpointAccess.PRIVATE,
  vpc: vpc,
  vpcSubnets: [
    {subnets: vpc.privateSubnets.slice(0, 1)}
  ]
});

What did you expect to happen?

The CloudFormation deployment should succeed and the NodeGroup should use only the specified subnets

What actually happened?

CloudFormation failed with Subnets are not tagged with the required tag. Please tag all subnets with Key: kubernetes.io/cluster/.... CloudTrail log proves that indeed all subnets of the VPC are included in the CreateNodegroup call instead of only the selected ones.

Environment

  • CLI Version : 1.62.0 (build 8c2d7fc)
  • Framework Version: 1.62.0 (build 8c2d7fc)
  • Node.js Version: 12.18.3
  • OS :
  • Language (Version): TypeScript

Other

When the default Nodegroup is created, no subnets are passed to the constructor (https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-eks/lib/cluster.ts#L991), therefore props.subnets in https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-eks/lib/managed-nodegroup.ts#L272 is empty and all subnets are selected.

So I guess this.addNodegroup('DefaultCapacity', { instanceType, minSize: minCapacity }) should instead be something like this.addNodegroup('DefaultCapacity', { instanceType, minSize: minCapacity, subnets: this.vpcSubnets })


This is :bug: Bug Report

moserda avatar Sep 11 '20 17:09 moserda

@dmoser04 Thanks for reporting this.

As a workaround for anyone interested, you can add capacity post instantiation with specific subnet selection:

const cluster = new eks.Cluster(this, "mycluster", {
  clusterName: "mycluster",
  version: eks.KubernetesVersion.V1_17,
  defaultCapacityType: eks.DefaultCapacityType.NODEGROUP,
  endpointAccess: eks.EndpointAccess.PRIVATE,
  vpc: vpc,
  vpcSubnets: [
    {subnets: vpc.privateSubnets.slice(0, 1)}
  ]
});

cluster.addNodeGroup('node-group', {
  subnets: { subnets: vpc.privateSubnets.slice(0, 1) },
  minSize: 2,
})

iliapolo avatar Sep 20 '20 21:09 iliapolo

Duplicate of https://github.com/aws/aws-cdk/issues/17023.

otaviomacedo avatar Dec 16 '21 16:12 otaviomacedo

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Dec 16 '21 16:12 github-actions[bot]