@@ -12,11 +12,11 @@ import { KubernetesManifest, KubernetesManifestOptions } from './k8s-manifest';
12
12
import { KubernetesObjectValue } from './k8s-object-value' ;
13
13
import { KubernetesPatch } from './k8s-patch' ;
14
14
import { IKubectlProvider , KubectlProvider , KubectlProviderOptions } from './kubectl-provider' ;
15
- import { Nodegroup , NodegroupOptions } from './managed-nodegroup' ;
15
+ import { Nodegroup , NodegroupAmiType , NodegroupOptions } from './managed-nodegroup' ;
16
16
import { OpenIdConnectProvider } from './oidc-provider' ;
17
17
import { BottleRocketImage } from './private/bottlerocket' ;
18
18
import { ServiceAccount , ServiceAccountOptions } from './service-account' ;
19
- import { renderAmazonLinuxUserData , renderBottlerocketUserData } from './user-data' ;
19
+ import { renderAmazonLinux2023UserData , renderAmazonLinuxUserData , renderBottlerocketUserData } from './user-data' ;
20
20
import * as autoscaling from 'aws-cdk-lib/aws-autoscaling' ;
21
21
import * as ec2 from 'aws-cdk-lib/aws-ec2' ;
22
22
import * as iam from 'aws-cdk-lib/aws-iam' ;
@@ -65,6 +65,12 @@ export interface ICluster extends IResource, ec2.IConnectable {
65
65
*/
66
66
readonly clusterCertificateAuthorityData : string ;
67
67
68
+ /**
69
+ * The CIDR block to assign Kubernetes service IP addresses from
70
+ * @attribute
71
+ */
72
+ readonly serviceIpv4Cidr ?: string ;
73
+
68
74
/**
69
75
* The id of the cluster security group that was created by Amazon EKS for the cluster.
70
76
* @attribute
@@ -676,6 +682,15 @@ export class KubernetesVersion {
676
682
*/
677
683
public static readonly V1_32 = KubernetesVersion . of ( '1.32' ) ;
678
684
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
+
679
694
/**
680
695
* Custom cluster version
681
696
* @param version custom version number
@@ -837,9 +852,18 @@ abstract class ClusterBase extends Resource implements ICluster {
837
852
}
838
853
839
854
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
+ }
843
867
autoScalingGroup . addUserData ( ...userData ) ;
844
868
}
845
869
@@ -967,6 +991,11 @@ export class Cluster extends ClusterBase {
967
991
*/
968
992
public readonly clusterEncryptionConfigKeyArn : string ;
969
993
994
+ /**
995
+ * The CIDR block to assign Kubernetes service IP addresses from
996
+ */
997
+ public readonly serviceIpv4Cidr ?: string ;
998
+
970
999
/**
971
1000
* Manages connection rules (Security Group Rules) for the cluster
972
1001
*
@@ -1079,6 +1108,7 @@ export class Cluster extends ClusterBase {
1079
1108
this . prune = props . prune ?? true ;
1080
1109
this . vpc = props . vpc || new ec2 . Vpc ( this , 'DefaultVpc' ) ;
1081
1110
this . version = props . version ;
1111
+ this . serviceIpv4Cidr = props . serviceIpv4Cidr ;
1082
1112
1083
1113
this . _kubectlProviderOptions = props . kubectlProviderOptions ;
1084
1114
@@ -1305,12 +1335,25 @@ export class Cluster extends ClusterBase {
1305
1335
const instanceType = props . defaultCapacityInstance || DEFAULT_CAPACITY_TYPE ;
1306
1336
// If defaultCapacityType is undefined, use AUTOMODE as the default
1307
1337
const capacityType = props . defaultCapacityType ?? DefaultCapacityType . AUTOMODE ;
1338
+ const arch = cpuArchForInstanceType ( instanceType ) ;
1339
+ const minorVersion = + this . version . version . split ( '.' ) [ 1 ] ;
1308
1340
1309
1341
// Only create EC2 or Nodegroup capacity if not using AUTOMODE
1310
1342
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
+ } ) ;
1312
1348
} 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
+ } ) ;
1314
1357
}
1315
1358
// For AUTOMODE, we don't create any explicit capacity as it's managed by EKS
1316
1359
}
@@ -1424,21 +1467,39 @@ export class Cluster extends ClusterBase {
1424
1467
*/
1425
1468
@MethodMetadata ( )
1426
1469
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' ) ;
1429
1474
}
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 ( {
1435
1487
kubernetesVersion : this . version . version ,
1436
- } ) :
1437
- new EksOptimizedImage ( {
1488
+ } ) ;
1489
+ break ;
1490
+ default :
1491
+ machineImage = new EksOptimizedImage ( {
1438
1492
nodeType : nodeTypeForInstanceType ( options . instanceType ) ,
1439
1493
cpuArch : cpuArchForInstanceType ( options . instanceType ) ,
1440
1494
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,
1442
1503
} ) ;
1443
1504
1444
1505
this . connectAutoScalingGroupCapacity ( asg , {
@@ -2046,6 +2107,40 @@ export class EksOptimizedImage implements ec2.IMachineImage {
2046
2107
}
2047
2108
}
2048
2109
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
+
2049
2144
// MAINTAINERS: use ./scripts/kube_bump.sh to update LATEST_KUBERNETES_VERSION
2050
2145
const LATEST_KUBERNETES_VERSION = '1.24' ;
2051
2146
@@ -2126,6 +2221,10 @@ export enum DefaultCapacityType {
2126
2221
* The machine image type
2127
2222
*/
2128
2223
export enum MachineImageType {
2224
+ /**
2225
+ * Amazon EKS-optimized Linux 2023 AMI
2226
+ */
2227
+ AMAZON_LINUX_2023 ,
2129
2228
/**
2130
2229
* Amazon EKS-optimized Linux AMI
2131
2230
*/
0 commit comments