-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(aws-eks): Add L2 Construct for Amazon EKS clusters and worker nodes #991
Changes from all commits
c5d4676
0c049d8
c4c85c6
c126a38
942877e
26ddaa5
1aade1a
9fa4cef
bfe3569
f0bba75
86dc5f6
6475ffd
9c2dbb2
d1b6c44
8f44986
1ded6ce
401b689
34969a1
8e7d651
1252310
c62b704
c173ab5
8360f75
087c8ee
99af1d2
1435470
60abab7
0ea4322
7d233da
047a35f
a345efa
05fc921
9df96d5
9016535
bd3db55
c445ffe
2f00418
d88cc2e
0b94ceb
593780f
021fa3c
732975b
4f3a873
856359f
2079abf
4f5b074
e4404e3
76c547d
eebaf95
d823381
bde4025
468c016
3b684a8
4a194d1
360236b
1f5bcf4
7066ed1
ee4999e
1329d87
56bbadd
777692f
cca308d
b4645b2
e27aa0e
38abbe1
9c4313d
b2f9e12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"app": "node index", | ||
"context": { | ||
"availability-zones:413174413047:us-east-1": [ | ||
"us-east-1a", | ||
"us-east-1b", | ||
"us-east-1c", | ||
"us-east-1d", | ||
"us-east-1e", | ||
"us-east-1f" | ||
], | ||
"ssm:413174413047:us-east-1:/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2": "ami-0ff8a91507f77f867", | ||
"ssm:413174413047:us-east-1:/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2": "ami-0922553b7b0369273" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import ec2 = require("@aws-cdk/aws-ec2"); | ||
import eks = require("@aws-cdk/aws-eks"); | ||
import cdk = require("@aws-cdk/cdk"); | ||
|
||
const ENV = "dev"; | ||
const app = new cdk.App(); | ||
|
||
/** | ||
* Ths stack creates the VPC and network for the cluster | ||
* | ||
* @default single public subnet per availability zone (3) | ||
* This creates three (3) total subnets with an Internet Gateway | ||
* The subnets could be private with a Nat Gateway | ||
* they must not be isolated, as instances later need to | ||
* have outbound internet access to contact the API Server | ||
*/ | ||
const networkStack = new cdk.Stack(app, "Network"); | ||
|
||
const vpc = new ec2.VpcNetwork(networkStack, "VPC", { | ||
cidr: "10.244.0.0/16", | ||
maxAZs: 3, | ||
natGateways: 0, | ||
subnetConfiguration: [ | ||
{ | ||
name: "pub", | ||
cidrMask: 24, | ||
subnetType: ec2.SubnetType.Public | ||
} | ||
], | ||
tags: { | ||
env: `${ENV}` | ||
} | ||
}); | ||
const vpcExport = vpc.export(); | ||
|
||
/** | ||
* This stack creates the EKS Cluster with the imported VPC | ||
* above, and puts the cluster inside the chosen placement | ||
* | ||
* clusterName can be set (not recommended), let cfn generate | ||
* version can be specified, only 1.10 supported now | ||
* will become useful when more versions are supported | ||
* | ||
* It also creates a group of 3 worker nodes with default types | ||
* and given min, max and sshKeys | ||
*/ | ||
const clusterStack = new cdk.Stack(app, "Cluster"); | ||
|
||
const clusterVpc = ec2.VpcNetworkRef.import( | ||
clusterStack, | ||
"ClusterVpc", | ||
vpcExport | ||
); | ||
const cluster = new eks.Cluster(clusterStack, "Cluster", { | ||
vpc: clusterVpc, | ||
vpcPlacement: { | ||
subnetsToUse: ec2.SubnetType.Public | ||
} | ||
}); | ||
|
||
/** | ||
* This is optional and should be more specific to given | ||
* corparate CIDRS for access from the outside, maybe | ||
* even a bastion host inside AWS. | ||
*/ | ||
cluster.connections.allowFromAnyIPv4(new ec2.TcpPort(443)); | ||
|
||
const grp1 = new eks.Nodes(clusterStack, "NodeGroup1", { | ||
vpc: clusterVpc, | ||
cluster, | ||
minNodes: 3, | ||
maxNodes: 6, | ||
sshKeyName: "aws-dev-key" | ||
}); | ||
grp1.nodeGroup.connections.allowFromAnyIPv4(new ec2.TcpPort(22)); | ||
|
||
/** | ||
* This adds a second group of worker nodes of different | ||
* InstanceClass and InstanceSize | ||
* This gets pushed into an Array of Nodes | ||
*/ | ||
const grp2 = new eks.Nodes(clusterStack, "NodeGroup2", { | ||
vpc: clusterVpc, | ||
cluster, | ||
nodeClass: ec2.InstanceClass.T2, | ||
nodeSize: ec2.InstanceSize.Medium, | ||
nodeType: eks.NodeType.Normal, | ||
minNodes: 2, | ||
maxNodes: 4, | ||
sshKeyName: "aws-dev-key" | ||
}); | ||
/** | ||
* This is optional and should be more specific to given | ||
* corparate CIDRS for access from the outside, maybe | ||
* even a bastion host inside AWS. | ||
*/ | ||
grp2.nodeGroup.connections.allowFromAnyIPv4(new ec2.TcpPort(22)); | ||
|
||
app.run(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context in this file should not be committed.
I know, it's a pain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crap, yea will fix.