in src/main.ts [6:66]
constructor(scope: cdk.Construct, id: string, props: cdk.StackProps = {}) {
super(scope, id, props);
const vpc = getOrCreateVpc(this);
// create the cluster and a default maanged nodegroup of 2 x m5.large instances
const cluster = new eks.Cluster(this, 'Cluster', {
vpc,
version: eks.KubernetesVersion.V1_19,
});
// conditionally create spot managed nodegroup
if (this.node.tryGetContext('with_spot_nodegroup') === 'yes') {
cluster.addNodegroupCapacity('SpotMNG', {
capacityType: eks.CapacityType.SPOT,
instanceTypes: [
new ec2.InstanceType('m5.large'),
new ec2.InstanceType('c5.large'),
new ec2.InstanceType('t3.large'),
],
desiredSize: 3,
});
};
// conditionally create service account for a pod
if (this.node.tryGetContext('with_irsa') === 'yes') {
const sa = cluster.addServiceAccount('MyServiceAccount', {});
cluster.addManifest('mypod', {
apiVersion: 'v1',
kind: 'Pod',
metadata: { name: 'mypod' },
spec: {
serviceAccountName: sa.serviceAccountName,
containers: [
{
name: 'main',
image: 'pahud/aws-whoami',
ports: [{ containerPort: 5000 }],
},
],
},
});
new cdk.CfnOutput(this, 'SARoleArn', { value: sa.role.roleArn });
};
// conditionally create a fargate profile
if (this.node.tryGetContext('with_fargate_profile') === 'yes') {
const profile = cluster.addFargateProfile('FargateProfile', {
selectors: [
{ namespace: 'default' },
],
});
profile.fargateProfileName;
new cdk.CfnOutput(this, 'FargareProfileName', { value: profile.fargateProfileName });
};
}