@@ -12,11 +12,11 @@ import { KubernetesManifest, KubernetesManifestOptions } from './k8s-manifest';
1212import { KubernetesObjectValue } from './k8s-object-value' ;
1313import { KubernetesPatch } from './k8s-patch' ;
1414import { IKubectlProvider , KubectlProvider , KubectlProviderOptions } from './kubectl-provider' ;
15- import { Nodegroup , NodegroupOptions } from './managed-nodegroup' ;
15+ import { Nodegroup , NodegroupAmiType , NodegroupOptions } from './managed-nodegroup' ;
1616import { OpenIdConnectProvider } from './oidc-provider' ;
1717import { BottleRocketImage } from './private/bottlerocket' ;
1818import { ServiceAccount , ServiceAccountOptions } from './service-account' ;
19- import { renderAmazonLinuxUserData , renderBottlerocketUserData } from './user-data' ;
19+ import { renderAmazonLinux2023UserData , renderAmazonLinuxUserData , renderBottlerocketUserData } from './user-data' ;
2020import * as autoscaling from 'aws-cdk-lib/aws-autoscaling' ;
2121import * as ec2 from 'aws-cdk-lib/aws-ec2' ;
2222import * as iam from 'aws-cdk-lib/aws-iam' ;
@@ -65,6 +65,12 @@ export interface ICluster extends IResource, ec2.IConnectable {
6565 */
6666 readonly clusterCertificateAuthorityData : string ;
6767
68+ /**
69+ * The CIDR block to assign Kubernetes service IP addresses from
70+ * @attribute
71+ */
72+ readonly serviceIpv4Cidr ?: string ;
73+
6874 /**
6975 * The id of the cluster security group that was created by Amazon EKS for the cluster.
7076 * @attribute
@@ -676,6 +682,15 @@ export class KubernetesVersion {
676682 */
677683 public static readonly V1_32 = KubernetesVersion . of ( '1.32' ) ;
678684
685+ /**
686+ * Kubernetes version 1.33
687+ *
688+ * When creating a `Cluster` with this version, you need to also specify the
689+ * `kubectlLayer` property with a `KubectlV33Layer` from
690+ * `@aws-cdk/lambda-layer-kubectl-v33`.
691+ */
692+ public static readonly V1_33 = KubernetesVersion . of ( '1.33' ) ;
693+
679694 /**
680695 * Custom cluster version
681696 * @param version custom version number
@@ -837,9 +852,18 @@ abstract class ClusterBase extends Resource implements ICluster {
837852 }
838853
839854 if ( bootstrapEnabled ) {
840- const userData = options . machineImageType === MachineImageType . BOTTLEROCKET ?
841- renderBottlerocketUserData ( this ) :
842- renderAmazonLinuxUserData ( this , autoScalingGroup , options . bootstrapOptions ) ;
855+ let userData = [ ] ;
856+ switch ( options . machineImageType ) {
857+ case MachineImageType . AMAZON_LINUX_2023 :
858+ userData = renderAmazonLinux2023UserData ( this , autoScalingGroup ) ;
859+ break ;
860+ case MachineImageType . BOTTLEROCKET :
861+ userData = renderBottlerocketUserData ( this ) ;
862+ break ;
863+ default :
864+ userData = renderAmazonLinuxUserData ( this , autoScalingGroup , options . bootstrapOptions ) ;
865+ break ;
866+ }
843867 autoScalingGroup . addUserData ( ...userData ) ;
844868 }
845869
@@ -967,6 +991,11 @@ export class Cluster extends ClusterBase {
967991 */
968992 public readonly clusterEncryptionConfigKeyArn : string ;
969993
994+ /**
995+ * The CIDR block to assign Kubernetes service IP addresses from
996+ */
997+ public readonly serviceIpv4Cidr ?: string ;
998+
970999 /**
9711000 * Manages connection rules (Security Group Rules) for the cluster
9721001 *
@@ -1079,6 +1108,7 @@ export class Cluster extends ClusterBase {
10791108 this . prune = props . prune ?? true ;
10801109 this . vpc = props . vpc || new ec2 . Vpc ( this , 'DefaultVpc' ) ;
10811110 this . version = props . version ;
1111+ this . serviceIpv4Cidr = props . serviceIpv4Cidr ;
10821112
10831113 this . _kubectlProviderOptions = props . kubectlProviderOptions ;
10841114
@@ -1305,12 +1335,25 @@ export class Cluster extends ClusterBase {
13051335 const instanceType = props . defaultCapacityInstance || DEFAULT_CAPACITY_TYPE ;
13061336 // If defaultCapacityType is undefined, use AUTOMODE as the default
13071337 const capacityType = props . defaultCapacityType ?? DefaultCapacityType . AUTOMODE ;
1338+ const arch = cpuArchForInstanceType ( instanceType ) ;
1339+ const minorVersion = + this . version . version . split ( '.' ) [ 1 ] ;
13081340
13091341 // Only create EC2 or Nodegroup capacity if not using AUTOMODE
13101342 if ( capacityType === DefaultCapacityType . EC2 ) {
1311- this . defaultCapacity = this . addAutoScalingGroupCapacity ( 'DefaultCapacity' , { instanceType, minCapacity } ) ;
1343+ this . defaultCapacity = this . addAutoScalingGroupCapacity ( 'DefaultCapacity' , {
1344+ instanceType,
1345+ minCapacity,
1346+ machineImageType : minorVersion > 32 ? MachineImageType . AMAZON_LINUX_2023 : undefined ,
1347+ } ) ;
13121348 } else if ( capacityType === DefaultCapacityType . NODEGROUP ) {
1313- this . defaultNodegroup = this . addNodegroupCapacity ( 'DefaultCapacity' , { instanceTypes : [ instanceType ] , minSize : minCapacity } ) ;
1349+ this . defaultNodegroup = this . addNodegroupCapacity ( 'DefaultCapacity' , {
1350+ instanceTypes : [ instanceType ] ,
1351+ minSize : minCapacity ,
1352+ amiType : minorVersion > 32 ? arch === CpuArch . ARM_64
1353+ ? NodegroupAmiType . AL2023_ARM_64_STANDARD
1354+ : NodegroupAmiType . AL2023_X86_64_STANDARD
1355+ : undefined ,
1356+ } ) ;
13141357 }
13151358 // For AUTOMODE, we don't create any explicit capacity as it's managed by EKS
13161359 }
@@ -1424,21 +1467,39 @@ export class Cluster extends ClusterBase {
14241467 */
14251468 @MethodMetadata ( )
14261469 public addAutoScalingGroupCapacity ( id : string , options : AutoScalingGroupCapacityOptions ) : autoscaling . AutoScalingGroup {
1427- if ( options . machineImageType === MachineImageType . BOTTLEROCKET && options . bootstrapOptions !== undefined ) {
1428- throw new Error ( 'bootstrapOptions is not supported for Bottlerocket' ) ;
1470+ if (
1471+ ( options . machineImageType === MachineImageType . BOTTLEROCKET || options . machineImageType === MachineImageType . AMAZON_LINUX_2023 )
1472+ && options . bootstrapOptions !== undefined ) {
1473+ throw new Error ( 'bootstrapOptions is not supported for Bottlerocket and Amazon Linux 2023' ) ;
14291474 }
1430- const asg = new autoscaling . AutoScalingGroup ( this , id , {
1431- ...options ,
1432- vpc : this . vpc ,
1433- machineImage : options . machineImageType === MachineImageType . BOTTLEROCKET ?
1434- new BottleRocketImage ( {
1475+
1476+ let machineImage : ec2 . IMachineImage ;
1477+ switch ( options . machineImageType ) {
1478+ case MachineImageType . AMAZON_LINUX_2023 :
1479+ machineImage = new Eks2023OptimizedImage ( {
1480+ nodeType : nodeTypeForInstanceType ( options . instanceType ) ,
1481+ cpuArch : cpuArchForInstanceType ( options . instanceType ) ,
1482+ kubernetesVersion : this . version . version ,
1483+ } ) ;
1484+ break ;
1485+ case MachineImageType . BOTTLEROCKET :
1486+ machineImage = new BottleRocketImage ( {
14351487 kubernetesVersion : this . version . version ,
1436- } ) :
1437- new EksOptimizedImage ( {
1488+ } ) ;
1489+ break ;
1490+ default :
1491+ machineImage = new EksOptimizedImage ( {
14381492 nodeType : nodeTypeForInstanceType ( options . instanceType ) ,
14391493 cpuArch : cpuArchForInstanceType ( options . instanceType ) ,
14401494 kubernetesVersion : this . version . version ,
1441- } ) ,
1495+ } ) ;
1496+ break ;
1497+ }
1498+
1499+ const asg = new autoscaling . AutoScalingGroup ( this , id , {
1500+ ...options ,
1501+ vpc : this . vpc ,
1502+ machineImage,
14421503 } ) ;
14431504
14441505 this . connectAutoScalingGroupCapacity ( asg , {
@@ -2046,6 +2107,40 @@ export class EksOptimizedImage implements ec2.IMachineImage {
20462107 }
20472108}
20482109
2110+ /**
2111+ * Construct an Amazon Linux 2023 image from the latest EKS Optimized AMI published in SSM
2112+ */
2113+ export class Eks2023OptimizedImage implements ec2 . IMachineImage {
2114+ private readonly cpuArch ?: CpuArch ;
2115+ private readonly kubernetesVersion ?: string ;
2116+ private readonly amiParameterName : string ;
2117+
2118+ /**
2119+ * Constructs a new instance of the EksOptimizedAmi class.
2120+ */
2121+ public constructor ( props : EksOptimizedImageProps = { } ) {
2122+ this . cpuArch = props . cpuArch ?? CpuArch . X86_64 ;
2123+ this . kubernetesVersion = props . kubernetesVersion ?? LATEST_KUBERNETES_VERSION ;
2124+
2125+ this . amiParameterName = `/aws/service/eks/optimized-ami/${ this . kubernetesVersion } /amazon-linux-2023/`
2126+ + ( this . cpuArch === CpuArch . ARM_64 ? 'arm64/' : 'x86_64/' )
2127+ + 'standard/recommended/image_id' ;
2128+ }
2129+
2130+ /**
2131+ * Return the correct image
2132+ */
2133+ public getImage ( scope : Construct ) : ec2 . MachineImageConfig {
2134+ const ami = ssm . StringParameter . valueForStringParameter ( scope , this . amiParameterName ) ;
2135+
2136+ return {
2137+ imageId : ami ,
2138+ osType : ec2 . OperatingSystemType . LINUX ,
2139+ userData : ec2 . UserData . custom ( '' ) ,
2140+ } ;
2141+ }
2142+ }
2143+
20492144// MAINTAINERS: use ./scripts/kube_bump.sh to update LATEST_KUBERNETES_VERSION
20502145const LATEST_KUBERNETES_VERSION = '1.24' ;
20512146
@@ -2126,6 +2221,10 @@ export enum DefaultCapacityType {
21262221 * The machine image type
21272222 */
21282223export enum MachineImageType {
2224+ /**
2225+ * Amazon EKS-optimized Linux 2023 AMI
2226+ */
2227+ AMAZON_LINUX_2023 ,
21292228 /**
21302229 * Amazon EKS-optimized Linux AMI
21312230 */
0 commit comments