-
Notifications
You must be signed in to change notification settings - Fork 4
/
cluster-stack.ts
65 lines (58 loc) · 2.73 KB
/
cluster-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Stack, StackProps, CfnOutput } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ssm from 'aws-cdk-lib/aws-ssm';
import * as iam from 'aws-cdk-lib/aws-iam';
import { CapacityType, KubernetesVersion } from 'aws-cdk-lib/aws-eks';
import * as blueprints from '@aws-quickstart/eks-blueprints';
/**
* TODO:
* Add 'accelerator: nvidia-gpu' label
*
*/
export default class EksBlueprintStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const vpcId = this.node.tryGetContext('vpcId') || ssm.StringParameter.valueFromLookup(this, '/eks-gpu-autoscaling/vpc-id');
const addOns: Array<blueprints.ClusterAddOn> = [
new blueprints.addons.MetricsServerAddOn,
new blueprints.addons.ClusterAutoScalerAddOn,
new blueprints.addons.ContainerInsightsAddOn,
new blueprints.addons.AwsLoadBalancerControllerAddOn,
new blueprints.addons.VpcCniAddOn,
new blueprints.addons.CoreDnsAddOn,
new blueprints.addons.KubeProxyAddOn
];
const clusterProvider = new blueprints.GenericClusterProvider({
version: KubernetesVersion.V1_21,
managedNodeGroups: [
{
id: "cpu-ng",
minSize: 2,
maxSize: 10,
instanceTypes: [new ec2.InstanceType('c5.large')],
nodeGroupCapacityType: CapacityType.SPOT,
},
{
id: "gpu-ng",
minSize: 2,
maxSize: 10,
instanceTypes: [new ec2.InstanceType('g4dn.xlarge')],
nodeGroupCapacityType: CapacityType.SPOT
}
]
});
const eksBlueprint = blueprints.EksBlueprint.builder()
.addOns(...addOns)
.resourceProvider(blueprints.GlobalResources.Vpc, new blueprints.VpcProvider(vpcId))
.clusterProvider(clusterProvider)
.enableControlPlaneLogTypes('api')
.build(this, id, props);
// AmazonSSMManagedInstanceCore role is added to connect to EC2 instances by using SSM on AWS web console
eksBlueprint.getClusterInfo().nodeGroups?.forEach(n => {
n.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonSSMManagedInstanceCore'));
});
new CfnOutput(this, 'ClusterName', { value: eksBlueprint.getClusterInfo().cluster.clusterName });
new CfnOutput(this, 'ClusterArn', { value: eksBlueprint.getClusterInfo().cluster.clusterArn });
}
}