-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for EKS Auto Mode (#1519)
This change adds support for EKS Auto Mode (see [AWS docs](https://docs.aws.amazon.com/eks/latest/userguide/automode.html)). It's a new feature that fully automates compute, storage, and networking management for Kubernetes clusters. To support EKS Auto Mode, `pulumi-aws` was upgraded to `6.65.0` and the required options are exposed via the Cluster component's input properties.
- Loading branch information
1 parent
7297e8f
commit 684aabe
Showing
56 changed files
with
2,625 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: eks-auto-mode | ||
description: EKS Cluster in auto mode | ||
runtime: nodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# EKS Auto Mode | ||
|
||
EKS Auto Mode fully automates compute, storage, and networking management for Kubernetes clusters. | ||
In this example we use it to deploy a webserver (nginx) and expose it via a load balancer. | ||
EKS Auto mode manages all necessary infrastructure for this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as awsx from "@pulumi/awsx"; | ||
import * as eks from "@pulumi/eks"; | ||
import * as k8s from "@pulumi/kubernetes"; | ||
import { SubnetType } from "@pulumi/awsx/ec2"; | ||
|
||
const config = new pulumi.Config(); | ||
const clusterName = config.require("clusterName"); | ||
|
||
const eksVpc = new awsx.ec2.Vpc("eks-auto-mode", { | ||
enableDnsHostnames: true, | ||
cidrBlock: "10.0.0.0/16", | ||
subnetSpecs: [ | ||
// Necessary tags for EKS Auto Mode to identify the subnets for the load balancers. | ||
// See: https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.1/deploy/subnet_discovery/ | ||
{type: SubnetType.Public, tags: {[`kubernetes.io/cluster/${clusterName}`]: "shared", "kubernetes.io/role/elb": "1"}}, | ||
{type: SubnetType.Private, tags: {[`kubernetes.io/cluster/${clusterName}`]: "shared", "kubernetes.io/role/internal-elb": "1"}}, | ||
], | ||
subnetStrategy: "Auto" | ||
}); | ||
|
||
const cluster = new eks.Cluster("eks-auto-mode", { | ||
name: clusterName, | ||
// EKS Auto Mode requires Access Entries, use either the `Api` or `ApiAndConfigMap` authentication mode. | ||
authenticationMode: eks.AuthenticationMode.Api, | ||
vpcId: eksVpc.vpcId, | ||
publicSubnetIds: eksVpc.publicSubnetIds, | ||
privateSubnetIds: eksVpc.privateSubnetIds, | ||
|
||
// Enables compute, storage and load balancing for the cluster. | ||
autoMode: { | ||
enabled: true, | ||
} | ||
}); | ||
|
||
const appName = "nginx"; | ||
const ns = new k8s.core.v1.Namespace(appName, { | ||
metadata: { name: appName }, | ||
}, { provider: cluster.provider }); | ||
|
||
const configMap = new k8s.core.v1.ConfigMap(appName, { | ||
metadata: { | ||
namespace: ns.metadata.name, | ||
}, | ||
data: { | ||
"index.html": "<html><body><h1>Hello, Pulumi!</h1></body></html>", | ||
}, | ||
}, { provider: cluster.provider }); | ||
|
||
const deployment = new k8s.apps.v1.Deployment(appName, { | ||
metadata: { | ||
namespace: ns.metadata.name | ||
}, | ||
spec: { | ||
selector: { matchLabels: { app: appName } }, | ||
replicas: 3, | ||
template: { | ||
metadata: { labels: { app: appName } }, | ||
spec: { | ||
containers: [{ | ||
name: appName, | ||
image: appName, | ||
ports: [{ containerPort: 80 }], | ||
volumeMounts: [{ name: "nginx-index", mountPath: "/usr/share/nginx/html" }], | ||
}], | ||
volumes: [{ | ||
name: "nginx-index", | ||
configMap: { name: configMap.metadata.name }, | ||
}], | ||
}, | ||
}, | ||
}, | ||
}, { provider: cluster.provider }); | ||
|
||
const service = new k8s.core.v1.Service(appName, { | ||
metadata: { | ||
name: appName, | ||
namespace: ns.metadata.name | ||
}, | ||
spec: { | ||
selector: { app: appName }, | ||
ports: [{ port: 80, targetPort: 80 }], | ||
}, | ||
}, { provider: cluster.provider, dependsOn: [deployment] }); | ||
|
||
const ingressClass = new k8s.networking.v1.IngressClass("alb", { | ||
metadata: { | ||
namespace: ns.metadata.name, | ||
labels: { | ||
"app.kubernetes.io/name": "LoadBalancerController", | ||
}, | ||
name: "alb", | ||
}, | ||
spec: { | ||
controller: "eks.amazonaws.com/alb", | ||
} | ||
}, { provider: cluster.provider }); | ||
|
||
const ingress = new k8s.networking.v1.Ingress(appName, { | ||
metadata: { | ||
namespace: ns.metadata.name, | ||
// Annotations for EKS Auto Mode to identify the Ingress as internet-facing and target-type as IP. | ||
annotations: { | ||
"alb.ingress.kubernetes.io/scheme": "internet-facing", | ||
"alb.ingress.kubernetes.io/target-type": "ip", | ||
} | ||
}, | ||
spec: { | ||
ingressClassName: ingressClass.metadata.name, | ||
rules: [{ | ||
http: { | ||
paths: [{ | ||
path: "/", | ||
pathType: "Prefix", | ||
backend: { | ||
service: { | ||
name: service.metadata.name, | ||
port: { | ||
number: 80, | ||
}, | ||
}, | ||
}, | ||
}], | ||
}, | ||
}], | ||
} | ||
}, { provider: cluster.provider }); | ||
|
||
export const defaultNodeGroup = cluster.defaultNodeGroupAsgName; | ||
export const nodeRoleName = cluster.autoModeNodeRoleName; | ||
export const url = ingress.status.loadBalancer.ingress[0].hostname.apply(h => `http://${h}:80`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "eks-auto-mode", | ||
"devDependencies": { | ||
"typescript": "^4.0.0", | ||
"@types/node": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@pulumi/kubernetes": "^4.18.3", | ||
"@pulumi/awsx": "^2.0.2", | ||
"@pulumi/eks": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"lib": [ | ||
"es6" | ||
], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2016-2024, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import * as aws from "@pulumi/aws"; | ||
import { ClusterOptions, createCore } from "./cluster"; | ||
|
||
describe("createCore", () => { | ||
const name = "test-cluster"; | ||
|
||
it("should throw an error if both instanceRole and instanceRoles are set", () => { | ||
const rawArgs = { | ||
instanceRole: new aws.iam.Role("test-role", { assumeRolePolicy: "{}" }), | ||
instanceRoles: [new aws.iam.Role("test-role-1", { assumeRolePolicy: "{}" })], | ||
}; | ||
|
||
expect(() => createCore(name, rawArgs, undefined as any)).toThrow( | ||
"instanceRole and instanceRoles are mutually exclusive, and cannot both be set.", | ||
); | ||
}); | ||
|
||
it("should throw an error if both subnetIds and publicSubnetIds/privateSubnetIds are set", () => { | ||
const rawArgs = { | ||
subnetIds: ["subnet-123"], | ||
publicSubnetIds: ["subnet-456"], | ||
}; | ||
|
||
expect(() => createCore(name, rawArgs, undefined as any)).toThrow( | ||
"subnetIds, and the use of publicSubnetIds and/or privateSubnetIds are mutually exclusive. Choose a single approach.", | ||
); | ||
}); | ||
|
||
it("should throw an error if both nodeGroupOptions and singular node group options are set", () => { | ||
const rawArgs = { | ||
nodeGroupOptions: {}, | ||
nodeSubnetIds: ["subnet-123"], | ||
}; | ||
|
||
expect(() => createCore(name, rawArgs, undefined as any)).toThrow( | ||
"Setting nodeGroupOptions, and any set of singular node group option(s) on the cluster, is mutually exclusive. Choose a single approach.", | ||
); | ||
}); | ||
|
||
it("should throw an error if autoMode is enabled and authentication mode does not support access entries", () => { | ||
const rawArgs = { | ||
autoMode: { enabled: true }, | ||
authenticationMode: "CONFIG_MAP", | ||
} satisfies ClusterOptions; | ||
|
||
expect(() => createCore(name, rawArgs, undefined as any)).toThrow( | ||
"Access entries are required when using EKS Auto Mode. Use the authentication mode 'API' or 'API_AND_CONFIG_MAP'.", | ||
); | ||
}); | ||
}); |
Oops, something went wrong.