Skip to content

Instantly share code, notes, and snippets.

@pahud
Last active April 4, 2020 11:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pahud/ae8280d27a574086a02114134d5ba470 to your computer and use it in GitHub Desktop.
Save pahud/ae8280d27a574086a02114134d5ba470 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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
Copy link

Does this create a ManagedNodeGroup?

@pahud
Copy link
Author

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
Copy link

Thank you so much!

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