Skip to content
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: Add EKS cluster with VPC and self managed ASG example #224

Merged
merged 7 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions typescript/eks/cluster/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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', {
clusterName: id,
andskli marked this conversation as resolved.
Show resolved Hide resolved
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();
29 changes: 29 additions & 0 deletions typescript/eks/cluster/package.json
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": "^8.10.38",
"typescript": "^3.2.4"
},
"dependencies": {
"@aws-cdk/aws-autoscaling": "*",
"@aws-cdk/aws-ec2": "*",
"@aws-cdk/aws-eks": "*",
"@aws-cdk/aws-iam": "*",
"@aws-cdk/core": "*",
"aws-cdk": "*"
}
}
20 changes: 20 additions & 0 deletions typescript/eks/cluster/tsconfig.json
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
}
}