Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CDK for Amazon EKS with c5.12xlarge nodegroup
import cdk = require('@aws-cdk/core');
import eks = require('@aws-cdk/aws-eks');
import iam = require('@aws-cdk/aws-iam');
import autoscaling = require('@aws-cdk/aws-autoscaling');
import { InstanceType } from '@aws-cdk/aws-ec2';
export class CdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// first define the role
const clusterAdmin = new iam.Role(this, 'AdminRole', {
assumedBy: new iam.AccountRootPrincipal()
});
// eks cluster with nodegroup of 2x m5.large instances in dedicated vpc with default configuratrion
const cluster = new eks.Cluster(this, 'Cluster', {
clusterName: 'cdk-eks3',
defaultCapacity: 0,
mastersRole: clusterAdmin
});
const asg = new autoscaling.AutoScalingGroup(this, 'NG', {
vpc: cluster.vpc,
// on-demand price of c5.12xlarge in us-west-2
spotPrice: '2.0400',
instanceType: new InstanceType('c5.12xlarge'),
machineImage: new eks.EksOptimizedAmi({
kubernetesVersion: '1.13',
nodeType: eks.NodeType.NORMAL
}),
updateType: autoscaling.UpdateType.ROLLING_UPDATE
})
cluster.addAutoScalingGroup(asg, {
// https://github.com/awslabs/amazon-eks-ami/blob/master/files/eni-max-pods.txt
maxPods: 234,
mapRole: true
})
@pahud

This comment has been minimized.

Copy link
Owner Author

@pahud pahud commented Aug 22, 2019

After the cluster is running, you need update the aws-vpc-cni to 1.5.2 or above

kubectl -n kube-system set image  ds/aws-node aws-node=602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon-k8s-cni:v1.5.2
@farshadniayeshpour

This comment has been minimized.

Copy link

@farshadniayeshpour farshadniayeshpour commented Apr 3, 2020

Does this create a ManagedNodeGroup?

@pahud

This comment has been minimized.

Copy link
Owner Author

@pahud pahud commented Apr 3, 2020

Does this create a ManagedNodeGroup?

No, but the next release of CDK(1.32.0) will be allow you to create managed nodegroup.

@farshadniayeshpour

This comment has been minimized.

Copy link

@farshadniayeshpour farshadniayeshpour commented Apr 4, 2020

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment