Skip to content

Commit

Permalink
feat(eks): add k8s v1.22 (#19756)
Browse files Browse the repository at this point in the history
EKS 1.22 just got released

https://aws.amazon.com/blogs/containers/amazon-eks-now-supports-kubernetes-1-22/

https://aws.amazon.com/about-aws/whats-new/2022/04/amazon-eks-distro-eks-anywhere-kubernetes-1-22/

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
robertd authored Apr 5, 2022
1 parent f351e06 commit 9a518c5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 46 deletions.
38 changes: 19 additions & 19 deletions packages/@aws-cdk/aws-eks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This example defines an Amazon EKS cluster with the following configuration:
```ts
// provisiong a cluster
const cluster = new eks.Cluster(this, 'hello-eks', {
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
});

// apply a kubernetes manifest to the cluster
Expand Down Expand Up @@ -143,15 +143,15 @@ Creating a new cluster is done using the `Cluster` or `FargateCluster` construct

```ts
new eks.Cluster(this, 'HelloEKS', {
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
});
```

You can also use `FargateCluster` to provision a cluster that uses only fargate workers.

```ts
new eks.FargateCluster(this, 'HelloEKS', {
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
});
```

Expand All @@ -175,7 +175,7 @@ At cluster instantiation time, you can customize the number of instances and the

```ts
new eks.Cluster(this, 'HelloEKS', {
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
defaultCapacity: 5,
defaultCapacityInstance: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.SMALL),
});
Expand All @@ -187,7 +187,7 @@ Additional customizations are available post instantiation. To apply them, set t

```ts
const cluster = new eks.Cluster(this, 'HelloEKS', {
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
defaultCapacity: 0,
});

Expand Down Expand Up @@ -345,7 +345,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_21,
version: eks.KubernetesVersion.V1_22,
});
```

Expand Down Expand Up @@ -422,7 +422,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_21,
version: eks.KubernetesVersion.V1_22,
defaultCapacityType: eks.DefaultCapacityType.EC2,
});
```
Expand Down Expand Up @@ -515,7 +515,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_21,
version: eks.KubernetesVersion.V1_22,
endpointAccess: eks.EndpointAccess.PRIVATE, // No access outside of your VPC.
});
```
Expand All @@ -537,7 +537,7 @@ To deploy the controller on your EKS cluster, configure the `albController` prop

```ts
new eks.Cluster(this, 'HelloEKS', {
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
albController: {
version: eks.AlbControllerVersion.V2_4_1,
},
Expand Down Expand Up @@ -577,7 +577,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_21,
version: eks.KubernetesVersion.V1_22,
vpc,
vpcSubnets: [{ subnetType: ec2.SubnetType.PRIVATE }],
});
Expand Down Expand Up @@ -624,7 +624,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_21,
version: eks.KubernetesVersion.V1_22,
clusterHandlerEnvironment: {
https_proxy: 'http://proxy.myproxy.com',
},
Expand Down Expand Up @@ -662,7 +662,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_21,
version: eks.KubernetesVersion.V1_22,
kubectlEnvironment: {
'http_proxy': 'http://proxy.myproxy.com',
},
Expand Down Expand Up @@ -706,7 +706,7 @@ const cluster1 = new eks.Cluster(this, 'MyCluster', {
kubectlLayer: layer,
vpc,
clusterName: 'cluster-name',
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
});

// or
Expand All @@ -724,7 +724,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_21,
version: eks.KubernetesVersion.V1_22,
});

// or
Expand Down Expand Up @@ -763,7 +763,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_21,
version: eks.KubernetesVersion.V1_22,
mastersRole: role,
});
```
Expand Down Expand Up @@ -791,7 +791,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_21,
version: eks.KubernetesVersion.V1_22,
});
```

Expand All @@ -801,7 +801,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_21,
version: eks.KubernetesVersion.V1_22,
});
```

Expand Down Expand Up @@ -1076,7 +1076,7 @@ when a cluster is defined:

```ts
new eks.Cluster(this, 'MyCluster', {
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
prune: false,
});
```
Expand Down Expand Up @@ -1431,7 +1431,7 @@ property. For example:
```ts
const cluster = new eks.Cluster(this, 'Cluster', {
// ...
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
clusterLogging: [
eks.ClusterLoggingTypes.API,
eks.ClusterLoggingTypes.AUTHENTICATOR,
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-eks/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ export class KubernetesVersion {

/**
* Kubernetes version 1.18
* @deprecated Use newer version of EKS
*/
public static readonly V1_18 = KubernetesVersion.of('1.18');

Expand All @@ -814,6 +815,11 @@ export class KubernetesVersion {
*/
public static readonly V1_21 = KubernetesVersion.of('1.21');

/**
* Kubernetes version 1.22
*/
public static readonly V1_22 = KubernetesVersion.of('1.22');

/**
* Custom cluster version
* @param version custom version number
Expand Down
26 changes: 13 additions & 13 deletions packages/@aws-cdk/aws-eks/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { testFixture, testFixtureNoVpc } from './util';

/* eslint-disable max-len */

const CLUSTER_VERSION = eks.KubernetesVersion.V1_21;
const CLUSTER_VERSION = eks.KubernetesVersion.V1_22;

describe('cluster', () => {

Expand Down Expand Up @@ -135,9 +135,9 @@ describe('cluster', () => {
test('throws if selecting more than one subnet group', () => {
expect(() => new eks.Cluster(stack, 'Cluster', {
vpc: vpc,
vpcSubnets: [{ subnetType: ec2.SubnetType.PUBLIC }, { subnetType: ec2.SubnetType.PRIVATE }],
vpcSubnets: [{ subnetType: ec2.SubnetType.PUBLIC }, { subnetType: ec2.SubnetType.PRIVATE_WITH_NAT }],
defaultCapacity: 0,
version: eks.KubernetesVersion.V1_21,
version: CLUSTER_VERSION,
})).toThrow(/cannot select multiple subnet groups/);


Expand All @@ -149,7 +149,7 @@ describe('cluster', () => {
vpc: vpc,
vpcSubnets: [{ subnetType: ec2.SubnetType.PUBLIC }],
defaultCapacity: 0,
version: eks.KubernetesVersion.V1_21,
version: CLUSTER_VERSION,
});

// THEN
Expand Down Expand Up @@ -697,7 +697,7 @@ describe('cluster', () => {
Template.fromStack(stack).hasResourceProperties('Custom::AWSCDK-EKS-Cluster', {
Config: {
roleArn: { 'Fn::GetAtt': ['ClusterRoleFA261979', 'Arn'] },
version: '1.21',
version: '1.22',
resourcesVpcConfig: {
securityGroupIds: [{ 'Fn::GetAtt': ['ClusterControlPlaneSecurityGroupD274242C', 'GroupId'] }],
subnetIds: [
Expand Down Expand Up @@ -1657,7 +1657,7 @@ describe('cluster', () => {
const { app, stack } = testFixtureNoVpc();

// WHEN
new eks.EksOptimizedImage({ kubernetesVersion: '1.21' }).getImage(stack);
new eks.EksOptimizedImage({ kubernetesVersion: '1.22' }).getImage(stack);

// THEN
const assembly = app.synth();
Expand All @@ -1668,7 +1668,7 @@ describe('cluster', () => {
)).toEqual(true);
expect(Object.entries(parameters).some(
([k, v]) => k.startsWith('SsmParameterValueawsserviceeksoptimizedami') &&
(v as any).Default.includes('/1.21/'),
(v as any).Default.includes('/1.22/'),
)).toEqual(true);

});
Expand Down Expand Up @@ -1806,7 +1806,7 @@ describe('cluster', () => {
const { app, stack } = testFixtureNoVpc();

// WHEN
new BottleRocketImage({ kubernetesVersion: '1.21' }).getImage(stack);
new BottleRocketImage({ kubernetesVersion: '1.22' }).getImage(stack);

// THEN
const assembly = app.synth();
Expand All @@ -1817,7 +1817,7 @@ describe('cluster', () => {
)).toEqual(true);
expect(Object.entries(parameters).some(
([k, v]) => k.startsWith('SsmParameterValueawsservicebottlerocketaws') &&
(v as any).Default.includes('/aws-k8s-1.21/'),
(v as any).Default.includes('/aws-k8s-1.22/'),
)).toEqual(true);

});
Expand All @@ -1838,7 +1838,7 @@ describe('cluster', () => {
Config: {
name: 'my-cluster-name',
roleArn: { 'Fn::GetAtt': ['MyClusterRoleBA20FE72', 'Arn'] },
version: '1.21',
version: '1.22',
resourcesVpcConfig: {
securityGroupIds: [
{ 'Fn::GetAtt': ['MyClusterControlPlaneSecurityGroup6B658F79', 'GroupId'] },
Expand Down Expand Up @@ -2789,7 +2789,7 @@ describe('cluster', () => {
natGateways: 1,
subnetConfiguration: [
{
subnetType: ec2.SubnetType.PRIVATE,
subnetType: ec2.SubnetType.PRIVATE_WITH_NAT,
name: 'Private1',
},
{
Expand Down Expand Up @@ -2848,7 +2848,7 @@ describe('cluster', () => {

for (let i = 0; i < 20; i++) {
subnetConfiguration.push({
subnetType: ec2.SubnetType.PRIVATE,
subnetType: ec2.SubnetType.PRIVATE_WITH_NAT,
name: `Private${i}`,
},
);
Expand Down Expand Up @@ -2897,7 +2897,7 @@ describe('cluster', () => {

for (let i = 0; i < 20; i++) {
subnetConfiguration.push({
subnetType: ec2.SubnetType.PRIVATE,
subnetType: ec2.SubnetType.PRIVATE_WITH_NAT,
name: `Private${i}`,
},
);
Expand Down
24 changes: 12 additions & 12 deletions packages/@aws-cdk/aws-eks/test/integ.eks-cluster.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@
]
},
"Config": {
"version": "1.21",
"version": "1.22",
"roleArn": {
"Fn::GetAtt": [
"ClusterRoleFA261979",
Expand Down Expand Up @@ -1593,7 +1593,7 @@
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": {
"Ref": "SsmParameterValueawsserviceeksoptimizedami121amazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceeksoptimizedami122amazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"InstanceType": "t2.medium",
"IamInstanceProfile": {
Expand Down Expand Up @@ -1918,7 +1918,7 @@
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": {
"Ref": "SsmParameterValueawsserviceeksoptimizedami121amazonlinux2arm64recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceeksoptimizedami122amazonlinux2arm64recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"InstanceType": "m6g.medium",
"IamInstanceProfile": {
Expand Down Expand Up @@ -2243,7 +2243,7 @@
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": {
"Ref": "SsmParameterValueawsservicebottlerocketawsk8s121x8664latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsservicebottlerocketawsk8s122x8664latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"InstanceType": "t3.small",
"IamInstanceProfile": {
Expand Down Expand Up @@ -2568,7 +2568,7 @@
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": {
"Ref": "SsmParameterValueawsserviceeksoptimizedami121amazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceeksoptimizedami122amazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"InstanceType": "t3.large",
"IamInstanceProfile": {
Expand Down Expand Up @@ -3594,7 +3594,7 @@
"Properties": {
"LaunchTemplateData": {
"ImageId": {
"Ref": "SsmParameterValueawsserviceeksoptimizedami121amazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
"Ref": "SsmParameterValueawsserviceeksoptimizedami122amazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter"
},
"InstanceType": "t3.small",
"UserData": {
Expand Down Expand Up @@ -4039,17 +4039,17 @@
"Type": "String",
"Description": "Artifact hash for asset \"fedb0b025bbf74f4daee09934a81c34a6cf5b06a765baa86bf42234971244a09\""
},
"SsmParameterValueawsserviceeksoptimizedami121amazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter": {
"SsmParameterValueawsserviceeksoptimizedami122amazonlinux2recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/aws/service/eks/optimized-ami/1.21/amazon-linux-2/recommended/image_id"
"Default": "/aws/service/eks/optimized-ami/1.22/amazon-linux-2/recommended/image_id"
},
"SsmParameterValueawsserviceeksoptimizedami121amazonlinux2arm64recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter": {
"SsmParameterValueawsserviceeksoptimizedami122amazonlinux2arm64recommendedimageidC96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/aws/service/eks/optimized-ami/1.21/amazon-linux-2-arm64/recommended/image_id"
"Default": "/aws/service/eks/optimized-ami/1.22/amazon-linux-2-arm64/recommended/image_id"
},
"SsmParameterValueawsservicebottlerocketawsk8s121x8664latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter": {
"SsmParameterValueawsservicebottlerocketawsk8s122x8664latestimageidC96584B6F00A464EAD1953AFF4B05118Parameter": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/aws/service/bottlerocket/aws-k8s-1.21/x86_64/latest/image_id"
"Default": "/aws/service/bottlerocket/aws-k8s-1.22/x86_64/latest/image_id"
}
}
}
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-eks/test/integ.eks-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EksClusterStack extends TestStack {
vpc: this.vpc,
mastersRole,
defaultCapacity: 2,
version: eks.KubernetesVersion.V1_21,
version: eks.KubernetesVersion.V1_22,
secretsEncryptionKey,
tags: {
foo: 'bar',
Expand Down Expand Up @@ -206,7 +206,7 @@ class EksClusterStack extends TestStack {
const lt = new ec2.CfnLaunchTemplate(this, 'LaunchTemplate', {
launchTemplateData: {
imageId: new eks.EksOptimizedImage({
kubernetesVersion: eks.KubernetesVersion.V1_21.version,
kubernetesVersion: eks.KubernetesVersion.V1_22.version,
}).getImage(this).imageId,
instanceType: new ec2.InstanceType('t3.small').toString(),
userData: Fn.base64(userData.render()),
Expand Down

0 comments on commit 9a518c5

Please sign in to comment.