Skip to main content

@smallcase/cdk-eks-cluster-module

Project description

cdk-eks-cluster-module

cdk-eks-cluster-module is a CDK that helps you configure complete EKS clusters that are fully bootstrapped with the operational software that is needed to deploy and operate workloads. You can describe the configuration for the desired state of your EKS cluster, such as the control plane, worker nodes, and Kubernetes add-ons, as code.

:sparkles: Features

  • :white_check_mark: AWS EKS Cluster Addons
  • :white_check_mark: Support for Multiple NodeGroups with labels and taints
  • :white_check_mark: Support for Multiple fargate profiles with labels and namespace
  • :white_check_mark: AWS EKS Identity Provider Configuration
  • :white_check_mark: Support for custom AMI, custom launch template, and custom user data including custom user data template
  • :white_check_mark: commonComponents interface allow to install custom repo/local helm chart
  • :white_check_mark: Install aws-ebs-csi-driver,aws-efs-csi-driver,node-problem-detector helm charts to help manage storage, and nodes.

:clapper: Quick Start

The quick start shows you how to create an AWS-EKS using this module.

Prerequisites

  • A working aws CLI installation with access to an account and administrator privileges
  • You'll need a recent NodeJS installation
  • kubectl to interact with your fresh cluster

To get going you'll need a CDK project. For details please refer to the detailed guide for CDK.

Create an empty directory on your system.

mkdir aws-quick-start-eks && cd aws-quick-start-eks

Bootstrap your CDK project, we will use TypeScript, but you can switch to any other supported language.

npx cdk init sample-eks  --language typescript
npx cdk bootstrap

Install using NPM:

npm install @smallcase/cdk-eks-cluster-module

Using yarn

yarn add @smallcase/cdk-eks-cluster-module

Using eks cluster can be deployed using the following sample code snippet:

import {
  EKSCluster,
  VpcCniAddonVersion,
} from '@smallcase/cdk-eks-cluster-module';

const key = new kms.Key(this, 'EKS-KMS', {
      enabled: true,
      alias: 'EKS-KMS',
    });
key.addToResourcePolicy(new iam.PolicyStatement({
      sid: 'encrypt root volumes of nodeGroup using kms',
      actions: [
        'kms:Encrypt',
        'kms:Decrypt',
        'kms:ReEncrypt*',
        'kms:GenerateDataKey*',
        'kms:CreateGrant',
        'kms:DescribeKey',
      ],
      resources: ['*'],
      principals: [new iam.AnyPrincipal()],
      conditions: {
        StringEquals: {
          'kms:CallerAccount': '<YOUR-AWS-ID>',
          'kms:ViaService': 'ec2.<REGION>.amazonaws.com',
        },
      },
    }));

  const securityGroup = new ec2.SecurityGroup(
      this,
      'EKS-WORKER-SG',
      {
        vpc: vpc,
        description: 'Kubernetes Worker SecurityGroup',
      },
    );

  const testNodeTemplete = new ec2.LaunchTemplate(this, 'testNodeTemplete', {
      instanceType: new ec2.InstanceType('m5a.large'),
      blockDevices: [
        {
          deviceName: '/dev/xvda',
          volume: ec2.BlockDeviceVolume.ebs(40,
            {
              deleteOnTermination: true,
              encrypted: true,
              volumeType: ec2.EbsDeviceVolumeType.GP3,
              kmsKey: key,
            },
          ),
          mappingEnabled: true,
        },
      ],
    });
let ekscluster = new EKSCluster(this, 'EKS-CLUSTER', {
      availabilityZones: Stack.of(this).availabilityZones,
      clusterVPC: vpc,
      kmsKey: key,
      region: Stack.of(this).region,
      workerSecurityGroup: securityGroup,
      addonProps: {
        vpnCniAddonVersion: VpcCniAddonVersion.V1_11_0,
      },
      clusterConfig: {
        clusterName: 'EKS-CLUSTER',
        clusterVersion: eks.KubernetesVersion.V1_22,
        // this will create cluster autoscaler service account with iam role
        addAutoscalerIam: true,
        albControllerVersion: eks.AlbControllerVersion.V2_2_4,
        defaultCapacity: 3,
        subnets: {
          privateSubnetGroupName: 'Private',
        },
        nodeGroups: [
          {
            name: 'test-node',
            instanceTypes: [],
            minSize: 3,
            maxSize: 6,
            launchTemplateSpec: {
              version: testNodeTemplete.versionNumber,
              id: testNodeTemplete.launchTemplateId!,
            },
            subnetGroupName: 'Private',
            labels: {
              role: 'test-eks-cluster',
            },
            taints: {
              role: 'test-eks-cluster',
            },
            tags: {
              'k8s.io/cluster-autoscaler/enabled': 'TRUE',
              'k8s.io/cluster-autoscaler/EKS-CLUSTER':
                'owned',
            },
          },
        ]
        commonComponents: {
          'aws-efs-csi-driver': {
            iamPolicyPath: ['../../assets/policy/aws-efs-csi-driver-policy.json'],
            // above mention iam policy will be used for this service account
            serviceAccounts: ['efs-csi-controller-sa', 'efs-csi-node-sa'],
            helm: {
              chartName: 'aws-efs-csi-driver',
              chartVersion: '2.2.0',
              helmRepository: 'https://kubernetes-sigs.github.io/aws-efs-csi-driver/',
              namespace: 'kube-system',
            },
          },
        },
        teamMembers: [
          "your-aws-user",
        ],
        teamExistingRolePermission: { //optional
          '<YOUR_ROLE_ARN>': 'system:masters',
        },
      }
  })

API.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk_eks_cluster_module-0.0.38.tar.gz (108.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdk_eks_cluster_module-0.0.38-py3-none-any.whl (106.5 kB view details)

Uploaded Python 3

File details

Details for the file cdk_eks_cluster_module-0.0.38.tar.gz.

File metadata

  • Download URL: cdk_eks_cluster_module-0.0.38.tar.gz
  • Upload date:
  • Size: 108.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.14.3

File hashes

Hashes for cdk_eks_cluster_module-0.0.38.tar.gz
Algorithm Hash digest
SHA256 9579c84263100196749767dcd95b7d7d70dab199127f4ee73a5c10a70c3e33b1
MD5 872260ff5c74574b546b185f8bd9a99b
BLAKE2b-256 d229c5dfc81b6b8c095994ca9b76f5102b150ec510e00f59220df6c4869839ed

See more details on using hashes here.

File details

Details for the file cdk_eks_cluster_module-0.0.38-py3-none-any.whl.

File metadata

File hashes

Hashes for cdk_eks_cluster_module-0.0.38-py3-none-any.whl
Algorithm Hash digest
SHA256 98d2194122d3be3cffc771aa96a783f95c53967323c890adf7e3cc9075d917f2
MD5 54dd8e3e3eabdba309fc88e340b5eb3e
BLAKE2b-256 847581b7b1d56e509a45a6368d541539b5137ad4997b871661883b14411703a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page