forked from aws-samples/aws-cdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add EKS cluster with VPC and self managed ASG example (aws-samp…
…les#224) Adds a typescript example EKS cluster with a VPC & auto-scaling group.
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "node index" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import autoscaling = require('@aws-cdk/aws-autoscaling'); | ||
import iam = require('@aws-cdk/aws-iam'); | ||
import ec2 = require('@aws-cdk/aws-ec2'); | ||
import eks = require('@aws-cdk/aws-eks'); | ||
import cdk = require('@aws-cdk/core'); | ||
|
||
class EKSCluster extends cdk.Stack { | ||
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
const vpc = new ec2.Vpc(this, 'EKSVpc'); // Create a new VPC for our cluster | ||
|
||
// IAM role for our EC2 worker nodes | ||
const workerRole = new iam.Role(this, 'EKSWorkerRole', { | ||
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com') | ||
}); | ||
|
||
const eksCluster = new eks.Cluster(this, 'Cluster', { | ||
vpc: vpc, | ||
kubectlEnabled: true, // we want to be able to manage k8s resources using CDK | ||
defaultCapacity: 0 // we want to manage capacity our selves | ||
}); | ||
|
||
const onDemandASG = new autoscaling.AutoScalingGroup(this, 'OnDemandASG', { | ||
vpc: vpc, | ||
role: workerRole, | ||
minCapacity: 1, | ||
maxCapacity: 10, | ||
instanceType: new ec2.InstanceType('t3.medium'), | ||
machineImage: new eks.EksOptimizedImage({ | ||
kubernetesVersion: '1.14', | ||
nodeType: eks.NodeType.STANDARD // wihtout this, incorrect SSM parameter for AMI is resolved | ||
}), | ||
updateType: autoscaling.UpdateType.ROLLING_UPDATE | ||
}); | ||
|
||
eksCluster.addAutoScalingGroup(onDemandASG, {}); | ||
} | ||
} | ||
|
||
const app = new cdk.App(); | ||
new EKSCluster(app, 'MyEKSCluster'); | ||
app.synth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "eks-cluster", | ||
"version": "1.0.0", | ||
"description": "Basic EKS cluster with VPC and self managed AutoScalingGroup", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"cdk": "cdk" | ||
}, | ||
"author": { | ||
"name": "Andreas Lindh", | ||
"url": "https://aws.amazon.com", | ||
"organization": true | ||
}, | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/node": "^10.17.0", | ||
"typescript": "~3.7.2" | ||
}, | ||
"dependencies": { | ||
"@aws-cdk/aws-autoscaling": "*", | ||
"@aws-cdk/aws-ec2": "*", | ||
"@aws-cdk/aws-eks": "*", | ||
"@aws-cdk/aws-iam": "*", | ||
"@aws-cdk/core": "*", | ||
"aws-cdk": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target":"ES2018", | ||
"module": "commonjs", | ||
"lib": ["es2016", "es2017.object", "es2017.string"], | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"noImplicitThis": true, | ||
"alwaysStrict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": false, | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"experimentalDecorators": true, | ||
"strictPropertyInitialization":false | ||
} | ||
} |