Amazon EKS Blueprints for CDK

repository·main·Indexed 19 days ago

https://github.com/awslabs/cdk-eks-blueprints

An opinionated, developer-oriented framework built on top of AWS CDK for automated deployment of Amazon EKS clusters. It provides higher-level abstractions including a builder pattern, add-on orchestration, and validation frameworks. Supports IPv4 and IPv6 clusters and includes a variety of pre-configured add-ons such as ArgoCD, Karpenter, AWS Controllers for Kubernetes (ACK), and AWS Distro for OpenTelemetry (ADOT).

Tokens
179.9K
Snippets
458
Records
684
Agent score
68%

What's inside cdk-eks-blueprints

  1. What is Amazon EKS Blueprints?

    main

    Amazon EKS Blueprints is an Infrastructure as Code (IaC) framework used to compose and manage complete Amazon EKS clusters. It allows you to describe the desired state of your EKS environment—including the control plane, worker nodes, and Kubernetes add-ons—as a blueprint.

    Once configured, these blueprints can be used to deploy consistent environments across multiple AWS accounts and Regions using continuous deployment automation. It is designed to bootstrap clusters with both Amazon EKS add-ons and popular open-source software such as:

    • Observability: Prometheus, Fluent Bit
    • Scaling & Networking: Karpenter, Nginx, Traefik, AWS Load Balancer Controller
    • Workload Management: Keda, ArgoCD

    It also provides mechanisms to implement security controls for multi-team workload operations within a single cluster.

  2. What is a Blueprint in EKS Blueprints?

    main
    A blueprint is the primary cohesive object in the eks-blueprints framework. It combines an EKS cluster, a set of add-ons (operational software), and a set of teams (IAM identities with namespace access) into a single deployable unit. Once configured, a blueprint can be deployed across multiple AWS accounts and regions. It also supports GitOps tooling for cluster bootstrapping and workload onboarding.
  3. What are EKS Capabilities and how do they differ from Addons?

    main

    EKS Capabilities are fully managed cluster features where AWS handles installation, upgrades, scaling, and security patching. This is the AWS-managed equivalent of self-managed addons.

    Important: Conflict Prevention The blueprints framework automatically detects conflicts between Capabilities and Addons. If you attempt to add both a capability and its corresponding addon (for example, AckCapability and AckAddOn), the build will fail with a conflict error.

  4. Tune Fluent Bit log performance

    main

    By default, the addon sends both Fluent Bit application logs and Kubernetes metadata to CloudWatch. To reduce log volume and costs, you can:

    1. Stop one or both data sources from being sent to CloudWatch.
    2. Apply filters to the logs.

    For detailed guidance on reducing volume, refer to the Amazon CloudWatch documentation on Reducing log volume from Fluent Bit. You can also inspect the aws-for-fluent-bit chart filter section to find specific ways to apply filters.

  5. Understand the functionality of the Ingress NGINX Add-on

    main

    The Ingress NGINX Add-on provides the following capabilities:

    • Installs the Ingress NGINX controller.
    • Integrates with the AWS Load Balancer Controller to leverage a Network Load Balancer (NLB) for the load balancer.
    • Integrates with the External DNS add-on for automatic integration with Amazon Route 53.
    • Supports configuring TLS termination at the load balancer provisioned by the add-on.
    • Supports standard Helm configuration options.
  6. Rename mounted secrets using secretAlias

    main

    By default, mounted Kubernetes secrets inherit the name of their corresponding AWS Secret or SSM Parameter. If the AWS name contains slashes (/ or \), the CSI Driver replaces them with underscores. To maintain a specific filename when mounting the secret to a pod, use the secretAlias option.

    Note: secretAlias is only applicable to secrets that are mounted to a pod. In these scenarios, secretName should match the name of the Secret or Parameter in AWS.

    {
        secretProvider: new blueprints.LookupSsmSecretByAttrs('/path/to/my/parameter', 1),
        kubernetesSecret: {
            secretName: 'my_parameter', // Should match the AWS name
            secretAlias: 'my_parameter', // The filename used when mounted in the pod
        }
    }
  7. How OPA Gatekeeper policy enforcement works

    main

    OPA Gatekeeper uses a hierarchical approach to policy enforcement via Kubernetes Custom Resource Definitions (CRDs):

    1. Constraint Template: A template that defines the logic for a new type of constraint using the Rego query language. It acts as the blueprint for how a specific policy should be evaluated.
    2. Constraint: A specific declaration of a requirement. It uses a ConstraintTemplate to define what must be met. Constraints are evaluated as a logical AND; if any single Constraint is not satisfied, the entire request is rejected.
    3. Target: A set of objects (like Pods or Namespaces) that are selected for validation based on a common identification or selection scheme.
    4. Enforcement Point: The location where the check happens. In Gatekeeper, this is typically the Kubernetes Admission Controller, which intercepts requests to create, update, or delete objects.
  8. Use BedrockTeam to manage generative AI workloads

    main

    The BedrockTeam is an extension of ApplicationTeam designed to manage the namespace for generative AI workloads. It automates the creation of an IAM Role for Service Accounts (IRSA), which allows pods running in a specific namespace to access Amazon Bedrock services.

    Important: BedrockTeam MUST be used in conjunction with the Bedrock Builder.

    import * as cdk from 'aws-cdk-lib';
    import * as blueprints from '@aws-quickstart/eks-blueprints';
    
    const app = new cdk.App();
          
    const bedrockTeamProps: blueprints.BedrockTeamProps = {
      namespace: 'bedrock',
      createNamespace: true,
      serviceAccountName: 'bedrock-service-account',
    };
    
    const blueprint = blueprints.EksBlueprint.builder()
      .version("auto")
      .teams(new blueprints.BedrockTeam(bedrockTeamProps))
      .build(app, 'my-stack-name');
  9. Manage add-on installation order and dependencies

    main

    Add-ons in EKS Blueprints are provisioned using CDK/CloudFormation constructs. While many add-ons have built-in dependencies (e.g., Istio* add-ons depend on IstioBase), others may require manual ordering to prevent race conditions.

    Built-in Dependencies

    Many add-ons use the @dependable decorator on their deploy method to declare dependencies that the framework handles automatically.

    Custom Ordering via Strict Ordering

    If the framework does not capture a necessary dependency, you can enforce a deployment order at the project level using the following logic:

    1. Add the prerequisite add-on to the blueprint first.
    2. Mark the prerequisite add-on as "strictly ordered" using Reflect.defineMetadata. This ensures that all add-ons declared after the marked add-on will only be provisioned after the marked add-on has successfully deployed.

    Alternatively, you can subclass an add-on and override the deploy method to declare additional dependencies manually.

  10. Configure GitOps deployment modes for AddOns

    main

    When using Argo CD, you can choose how EKS Blueprints AddOns are deployed via the enableGitOps method on the EksBlueprint.builder(). There are two modes:

    1. GitOpsMode.APPLICATION: CDK deploys an Application resource for each enabled AddOn. Argo CD then manages the actual AddOn deployment based on those resources.
    2. GitOpsMode.APP_OF_APPS: CDK deploys a single Application resource (the 'bootstrap-apps') which points to your bootstrapRepo. Argo CD then manages all AddOns based on the contents of that repository. This requires the naming pattern in your Git repository to match the AddOn names.
    // Example: GitOpsMode.APPLICATION
    const addOns: Array<blueprints.ClusterAddOn> = [
        prodBootstrapArgo,
        new blueprints.addons.AppMeshAddOn(),
        new blueprints.addons.MetricsServerAddOn(),
    ];
    
    blueprints.EksBlueprint.builder()
        .version("auto")
        .addOns(...addOns)
        .enableGitOps(blueprints.GitOpsMode.APPLICATION)
        .build(scope, stackID);
    
    // Example: GitOpsMode.APP_OF_APPS
    blueprints.EksBlueprint.builder()
        .version("auto")
        .addOns(...addOns)
        .enableGitOps(blueprints.GitOpsMode.APP_OF_APPS)
        .build(scope, stackID);
  11. Use the MngClusterProvider for EKS Managed Node Groups

    main

    The MngClusterProvider allows you to provision an Amazon EKS cluster that uses EKS Managed Node Groups (MNGs) for compute capacity. MNGs automate the provisioning and lifecycle management of the EC2 instances used as worker nodes. Use this provider when you want AWS to handle the maintenance and updates of your node groups.

    import * as cdk from 'aws-cdk-lib';
    import * as ec2 from 'aws-cdk-lib/aws-ec2';
    import * as eks from 'aws-cdk-lib/aws-eks';
    import * as bp from '@aws-quickstart/eks-blueprints';
    
    const app = new cdk.App();
    
    const props: bp.MngClusterProviderProps = {
        minSize: 1,
        maxSize: 10,
        desiredSize: 4,
        instanceTypes: [new ec2.InstanceType('m5.large')],
        amiType: eks.NodegroupAmiType.AL2023_X86_64_STANDARD,
        nodeGroupCapacityType: eks.CapacityType.ON_DEMAND,
        amiReleaseVersion: "1.30.0-20240615" // this will upgrade kubelet to 1.30.0
    };
    
    const clusterProvider = new bp.MngClusterProvider(props);
    new bp.EksBlueprint(app, { id: 'blueprint-1', addOns:[], teams: [], clusterProvider, version: eks.KubernetesVersion.V1_30 });
  12. How Teams and access control work

    main

    Teams define logical groupings of IAM identities and the access permissions they have within your EKS clusters. The framework supports two primary team types:

    • ApplicationTeam: Members are granted access to specific Kubernetes namespaces.
    • PlatformTeam: Members are granted administrative access to the clusters.

    This allows you to manage multi-tenant environments by isolating workloads and administrative duties.