Skip to content

Commit faee8e9

Browse files
hakuna-matatahHarish Kuna
andauthored
mega vpc to support kit clusters (#52)
Co-authored-by: Harish Kuna <[email protected]>
1 parent 4050b19 commit faee8e9

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

testbed/addons/flux/construct.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class Flux extends cdk.Construct {
3535
// we can adjust this later if we want to be more aggressive
3636
interval: '5m0s',
3737
ref: {
38-
branch: value.branch ?? "testbed",
38+
branch: value.branch ?? "main",
3939
},
4040
secretRef: {
4141
name: 'github-key'

testbed/stack.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,50 @@ export class Testbed extends cdk.Stack {
1414
constructor(scope: cdk.Construct, id: string, props: TestbedProps) {
1515
super(scope, id)
1616

17-
const vpc = new ec2.Vpc(this, 'vpc', {})
17+
const vpc = new ec2.Vpc(this, id, {
18+
cidr: '10.0.0.0/16',
19+
maxAzs: 99,
20+
subnetConfiguration: [
21+
{
22+
name: 'pub-subnet-1',
23+
subnetType: ec2.SubnetType.PUBLIC,
24+
cidrMask: 28,
25+
},
26+
{
27+
name: 'priv-subnet-1',
28+
subnetType: ec2.SubnetType.PRIVATE_WITH_NAT,
29+
cidrMask: 28,
30+
},
31+
],
32+
});
33+
//ToDo: revisit once this is resolved - https://github.com/aws/aws-cdk/issues/5927
34+
// index<=8 will give us 9 /16 cidrs additionally to make a mega VPC.
35+
for (let index = 0; index <= 8; index++) {
36+
let additionalCidr = new ec2.CfnVPCCidrBlock(this, `${id}-cidr-${index}`, {
37+
vpcId: vpc.vpcId,
38+
cidrBlock: `10.${index + 1}.0.0/16`
39+
});
40+
let privateSubnet = new ec2.PrivateSubnet(this, `${id}-private-subnet-${index}`, {
41+
availabilityZone: cdk.Stack.of(this).availabilityZones[index%cdk.Stack.of(this).availabilityZones.length],
42+
vpcId: vpc.vpcId,
43+
cidrBlock: `10.${index + 1}.0.0/16`
44+
})
45+
privateSubnet.node.addDependency(additionalCidr);
1846

47+
ec2.NatProvider.gateway().configureNat({
48+
natSubnets: [
49+
new ec2.PublicSubnet(this, `${id}-nat-subnet-${index}`, {
50+
availabilityZone: cdk.Stack.of(this).availabilityZones[index%cdk.Stack.of(this).availabilityZones.length],
51+
vpcId: vpc.vpcId,
52+
cidrBlock: `10.0.64.${index*16}/28`
53+
})
54+
],
55+
privateSubnets: [
56+
privateSubnet
57+
],
58+
vpc: vpc
59+
})
60+
}
1961
const cluster = new eks.Cluster(this, 'cluster', {
2062
clusterName: id,
2163
vpc: vpc,
@@ -33,7 +75,7 @@ export class Testbed extends cdk.Stack {
3375
cluster.addNodegroupCapacity('node-group', {
3476
nodegroupName: 'default',
3577
subnets: vpc.selectSubnets({
36-
subnetType: ec2.SubnetType.PRIVATE
78+
subnetType: ec2.SubnetType.PRIVATE_WITH_NAT
3779
}),
3880
nodeRole: new iam.Role(this, 'node-role', {
3981
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),

0 commit comments

Comments
 (0)