From fdd3309ee98a8dcd9542d8ffec9defcdbdcd28af Mon Sep 17 00:00:00 2001 From: Pahud Hsieh Date: Fri, 7 Jul 2023 11:43:29 -0400 Subject: [PATCH] feat(eks): support eks with k8s 1.27 (#25897) Similar to https://github.com/aws/aws-cdk/pull/25088, this PR add eks with k8s 1.27 support. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/aws-cdk-lib/aws-eks/README.md | 48 ++++++++++----------- packages/aws-cdk-lib/aws-eks/lib/cluster.ts | 9 ++++ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/packages/aws-cdk-lib/aws-eks/README.md b/packages/aws-cdk-lib/aws-eks/README.md index fb55cffb619f3..d8bff843d4667 100644 --- a/packages/aws-cdk-lib/aws-eks/README.md +++ b/packages/aws-cdk-lib/aws-eks/README.md @@ -39,12 +39,12 @@ This example defines an Amazon EKS cluster with the following configuration: * A Kubernetes pod with a container based on the [paulbouwer/hello-kubernetes](https://github.com/paulbouwer/hello-kubernetes) image. ```ts -import { KubectlV26Layer } from '@aws-cdk/lambda-layer-kubectl-v26'; +import { KubectlV27Layer } from '@aws-cdk/lambda-layer-kubectl-v27'; // provisioning a cluster const cluster = new eks.Cluster(this, 'hello-eks', { - version: eks.KubernetesVersion.V1_26, - kubectlLayer: new KubectlV26Layer(this, 'kubectl'), + version: eks.KubernetesVersion.V1_27, + kubectlLayer: new KubectlV27Layer(this, 'kubectl'), }); // apply a kubernetes manifest to the cluster @@ -110,7 +110,7 @@ Creating a new cluster is done using the `Cluster` or `FargateCluster` construct ```ts new eks.Cluster(this, 'HelloEKS', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, }); ``` @@ -118,7 +118,7 @@ You can also use `FargateCluster` to provision a cluster that uses only fargate ```ts new eks.FargateCluster(this, 'HelloEKS', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, }); ``` @@ -142,7 +142,7 @@ At cluster instantiation time, you can customize the number of instances and the ```ts new eks.Cluster(this, 'HelloEKS', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, defaultCapacity: 5, defaultCapacityInstance: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.SMALL), }); @@ -154,7 +154,7 @@ Additional customizations are available post instantiation. To apply them, set t ```ts const cluster = new eks.Cluster(this, 'HelloEKS', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, defaultCapacity: 0, }); @@ -213,7 +213,7 @@ const eksClusterNodeGroupRole = new iam.Role(this, 'eksClusterNodeGroupRole', { }); const cluster = new eks.Cluster(this, 'HelloEKS', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, defaultCapacity: 0, }); @@ -356,7 +356,7 @@ The following code defines an Amazon EKS cluster with a default Fargate Profile ```ts const cluster = new eks.FargateCluster(this, 'MyCluster', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, }); ``` @@ -433,7 +433,7 @@ You can also configure the cluster to use an auto-scaling group as the default c ```ts const cluster = new eks.Cluster(this, 'HelloEKS', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, defaultCapacityType: eks.DefaultCapacityType.EC2, }); ``` @@ -526,7 +526,7 @@ You can configure the [cluster endpoint access](https://docs.aws.amazon.com/eks/ ```ts const cluster = new eks.Cluster(this, 'hello-eks', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, endpointAccess: eks.EndpointAccess.PRIVATE, // No access outside of your VPC. }); ``` @@ -588,7 +588,7 @@ You can specify the VPC of the cluster using the `vpc` and `vpcSubnets` properti declare const vpc: ec2.Vpc; new eks.Cluster(this, 'HelloEKS', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, vpc, vpcSubnets: [{ subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }], }); @@ -635,7 +635,7 @@ You can configure the environment of the Cluster Handler functions by specifying ```ts declare const proxyInstanceSecurityGroup: ec2.SecurityGroup; const cluster = new eks.Cluster(this, 'hello-eks', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, clusterHandlerEnvironment: { https_proxy: 'http://proxy.myproxy.com', }, @@ -706,7 +706,7 @@ You can configure the environment of this function by specifying it at cluster i ```ts const cluster = new eks.Cluster(this, 'hello-eks', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, kubectlEnvironment: { 'http_proxy': 'http://proxy.myproxy.com', }, @@ -726,11 +726,11 @@ Depending on which version of kubernetes you're targeting, you will need to use the `@aws-cdk/lambda-layer-kubectl-vXY` packages. ```ts -import { KubectlV26Layer } from '@aws-cdk/lambda-layer-kubectl-v26'; +import { KubectlV27Layer } from '@aws-cdk/lambda-layer-kubectl-v27'; const cluster = new eks.Cluster(this, 'hello-eks', { - version: eks.KubernetesVersion.V1_26, - kubectlLayer: new KubectlV26Layer(this, 'kubectl'), + version: eks.KubernetesVersion.V1_27, + kubectlLayer: new KubectlV27Layer(this, 'kubectl'), }); ``` @@ -765,7 +765,7 @@ const cluster1 = new eks.Cluster(this, 'MyCluster', { kubectlLayer: layer, vpc, clusterName: 'cluster-name', - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, }); // or @@ -783,7 +783,7 @@ By default, the kubectl provider is configured with 1024MiB of memory. You can u ```ts new eks.Cluster(this, 'MyCluster', { kubectlMemory: Size.gibibytes(4), - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, }); // or @@ -822,7 +822,7 @@ When you create a cluster, you can specify a `mastersRole`. The `Cluster` constr ```ts declare const role: iam.Role; new eks.Cluster(this, 'HelloEKS', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, mastersRole: role, }); ``` @@ -872,7 +872,7 @@ You can use the `secretsEncryptionKey` to configure which key the cluster will u const secretsKey = new kms.Key(this, 'SecretsKey'); const cluster = new eks.Cluster(this, 'MyCluster', { secretsEncryptionKey: secretsKey, - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, }); ``` @@ -882,7 +882,7 @@ You can also use a similar configuration for running a cluster built using the F const secretsKey = new kms.Key(this, 'SecretsKey'); const cluster = new eks.FargateCluster(this, 'MyFargateCluster', { secretsEncryptionKey: secretsKey, - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, }); ``` @@ -1172,7 +1172,7 @@ when a cluster is defined: ```ts new eks.Cluster(this, 'MyCluster', { - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, prune: false, }); ``` @@ -1559,7 +1559,7 @@ property. For example: ```ts const cluster = new eks.Cluster(this, 'Cluster', { // ... - version: eks.KubernetesVersion.V1_26, + version: eks.KubernetesVersion.V1_27, clusterLogging: [ eks.ClusterLoggingTypes.API, eks.ClusterLoggingTypes.AUTHENTICATOR, diff --git a/packages/aws-cdk-lib/aws-eks/lib/cluster.ts b/packages/aws-cdk-lib/aws-eks/lib/cluster.ts index 573c30cc30728..545eb31bcadeb 100644 --- a/packages/aws-cdk-lib/aws-eks/lib/cluster.ts +++ b/packages/aws-cdk-lib/aws-eks/lib/cluster.ts @@ -918,6 +918,15 @@ export class KubernetesVersion { */ public static readonly V1_26 = KubernetesVersion.of('1.26'); + /** + * Kubernetes version 1.27 + * + * When creating a `Cluster` with this version, you need to also specify the + * `kubectlLayer` property with a `KubectlV27Layer` from + * `@aws-cdk/lambda-layer-kubectl-v27`. + */ + public static readonly V1_27 = KubernetesVersion.of('1.27'); + /** * Custom cluster version * @param version custom version number