Skip to content

Commit 1a2122a

Browse files
authored
Merge pull request #23 from doitintl/splitting_into_3_phases
Did some manual testing before merging to main.
2 parents 75ee91c + d2fb844 commit 1a2122a

24 files changed

+3717
-1762
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ node_modules
77

88
.cdk.staging
99
cdk.out
10+
11+
# IDE files
12+
.idea/
13+
.vscode/
1014
################################

bin/cdk-main.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ TS(TypeScript) import syntax that means:
1111
* The "named import" can be arbtirarily named.
1212
* Items in the named import can be referenced with the dot operator.
1313
*/
14+
import { ensure_existance_of_kubectl_helm_lambda_deployer_role_used_by_easy_eks } from '../lib/Utilities';
1415
import { Opinionated_VPC } from '../lib/Opinionated_VPC';
1516
import { Easy_EKS } from '../lib/Easy_EKS'; //AWS EKS L2 construct based cluster
1617
/* ^--_This---^
@@ -24,6 +25,16 @@ TS import syntax that means:
2425
////////////////////////////////////////////////////////////////////////////////////////////
2526

2627

28+
////////////////////////////////////////////////////////////////////////////////////////////
29+
ensure_existance_of_kubectl_helm_lambda_deployer_role_used_by_easy_eks();
30+
// ^-- This uses aws cli and node.js shell to ensure a dependency IAM role exists.
31+
// Note:
32+
// When a user first runs "cdk list" or "cdk deploy *"
33+
// The code will auto-runs (without requesting permission/input from the user)
34+
// This is for UX reasons, as cdk failures will occur if it's not pre-existing.
35+
////////////////////////////////////////////////////////////////////////////////////////////
36+
37+
2738
////////////////////////////////////////////////////////////////////////////////////////////
2839
// IMPORTANT NOTE: For Conceptual Understanding and Comprehension:
2940
const cdk_state = new cdk.App(); //<-- Root AWS "Construct"
@@ -128,28 +139,36 @@ dev1_eks.apply_global_baseline_eks_config();
128139
dev1_eks.apply_my_orgs_baseline_eks_config();
129140
dev1_eks.apply_lower_envs_eks_config();
130141
dev1_eks.apply_dev_eks_config();
131-
dev1_eks.stage_deployment_of_eks_construct_into_this_objects_stack();
132-
dev1_eks.stage_deployment_of_global_baseline_eks_dependencies();
133-
dev1_eks.stage_deployment_of_my_orgs_baseline_eks_dependencies();
134-
dev1_eks.stage_deployment_of_lower_envs_eks_dependencies();
135-
dev1_eks.stage_deployment_of_dev_eks_dependencies();
136-
dev1_eks.stage_deployment_of_global_baseline_eks_workload_dependencies();
137-
dev1_eks.stage_deployment_of_my_orgs_baseline_eks_workload_dependencies();
138-
dev1_eks.stage_deployment_of_lower_envs_eks_workload_dependencies();
139-
dev1_eks.stage_deployment_of_dev_eks_workload_dependencies();
142+
dev1_eks.stage_deployment_of_eks_cluster();
143+
dev1_eks.stage_deployment_of_global_baseline_eks_addons();
144+
dev1_eks.stage_deployment_of_my_orgs_baseline_eks_addons();
145+
dev1_eks.stage_deployment_of_lower_envs_eks_addons();
146+
dev1_eks.stage_deployment_of_dev_eks_addons();
147+
//^-- `cdk deploy dev1-eks-cluster has a deployment time of ~17mins
148+
///////////////////////////////////////////////////////////////////////
149+
dev1_eks.stage_deployment_of_global_baseline_eks_essentials();
150+
dev1_eks.stage_deployment_of_my_orgs_baseline_eks_essentials();
151+
dev1_eks.stage_deployment_of_lower_envs_eks_essentials();
152+
dev1_eks.stage_deployment_of_dev_eks_essentials();
153+
//^-- `cdk deploy dev1-eks-essentials has a deployment time of ~2mins
154+
///////////////////////////////////////////////////////////////////////
140155
dev1_eks.stage_deployment_of_global_baseline_eks_workloads();
141156
dev1_eks.stage_deployment_of_my_orgs_baseline_eks_workloads();
142157
dev1_eks.stage_deployment_of_lower_envs_eks_workloads();
143158
dev1_eks.stage_deployment_of_dev_eks_workloads();
144-
//^-- deployment time of ~18.6mins (~15-20mins)
159+
//^-- `cdk deploy dev1-eks-workloads has a deployment time of ~1min
160+
161+
162+
163+
///////////////////////////////////////////////////////////////////////////////////////////
145164

146165
//Example 2: Equivalent to Example 1, just with convenience methods as short hand
147166
//(This format balances usability and debugability)
148167
const dev2_eks = new Easy_EKS(cdk_state, 'dev2-eks', low_co2_AMER_stack_config);
149168
dev2_eks.apply_dev_baseline_config(); //<-- convenience method #1
150-
dev2_eks.stage_deployment_of_eks_construct_into_this_objects_stack();
151-
dev2_eks.stage_deployment_of_dev_baseline_dependencies(); //<-- convenience method #2
152-
dev2_eks.stage_deployment_of_dev_baseline_workload_dependencies(); //<-- convenience method #3
169+
dev2_eks.stage_deployment_of_eks_cluster();
170+
dev2_eks.stage_deployment_of_dev_baseline_addons(); //<-- convenience method #2
171+
dev2_eks.stage_deployment_of_dev_baseline_essentials(); //<-- convenience method #3
153172
dev2_eks.stage_deployment_of_dev_baseline_workloads(); //<-- convenience method #4
154173

155174
//Example 3: Equivalent to Examples 1 & 2, just shorter

cdk.context.json

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
{
2-
"availability-zones:account=905418347382:region=ca-central-1": [
3-
"ca-central-1a",
4-
"ca-central-1b",
5-
"ca-central-1d"
6-
],
7-
"ami:account=905418347382:filters.image-type.0=machine:filters.name.0=fck-nat-al2023-*-arm64-ebs:filters.state.0=available:owners.0=568608671756:region=ca-central-1": "ami-045d3a84706b8feeb",
8-
"key-provider:account=905418347382:aliasName=alias/eks/lower-envs:region=ca-central-1": {
9-
"keyId": "2c710e12-cad3-42f5-a92f-e7d7980aebea"
10-
},
11-
"acknowledged-issue-numbers": [
12-
32775
13-
]
14-
}
1+
{}

config/eks/dev_eks_config.ts

Lines changed: 90 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,55 @@
11
import { Easy_EKS_Config_Data } from '../../lib/Easy_EKS_Config_Data';
22
import * as cdk from 'aws-cdk-lib';
33
import * as eks from 'aws-cdk-lib/aws-eks'
4-
import * as iam from 'aws-cdk-lib/aws-iam';
5-
import request from 'sync-request-curl'; //npm install sync-request-curl (cdk requires sync functions, async not allowed)
4+
import {
5+
Apply_Podinfo_Helm_Chart,
6+
Apply_Podinfo_Http_Alb_YAML,
7+
Apply_Podinfo_Https_Alb_YAML,
8+
Podinfo_Helm_Config,
9+
} from "../../lib/Podinfo_Manifests";
10+
611
//Intended Use:
712
//EasyEKS Admins: edit this file with config to apply to all dev / sandbox cluster's in your org.
813

9-
export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack){ //config: is of type Easy_EKS_Config_Data
10-
config.addTag("Environment", "Dev");
14+
export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack) { //config: is of type Easy_EKS_Config_Data
15+
config.addTag("Environment", "Dev");
1116
}//end apply_config()
1217

1318
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1419
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1520
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1621

17-
export function deploy_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
22+
export function deploy_addons(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster) {
23+
24+
// v-- most won't need this, so commented out by default
25+
// const pvc_snapshot_controller = new eks.CfnAddon(stack, 'snapshot-controller', {
26+
// clusterName: cluster.clusterName,
27+
// addonName: 'snapshot-controller',
28+
// addonVersion: 'v8.2.0-eksbuild.1', //v--query for latest
29+
// // aws eks describe-addon-versions --kubernetes-version=1.31 --addon-name=snapshot-controller --query='addons[].addonVersions[].addonVersion' | jq '.[0]'
30+
// resolveConflicts: 'OVERWRITE',
31+
// configurationValues: '{}',
32+
// });
1833

19-
}//end deploy_dependencies()
34+
}//end deploy_addons()
2035

2136
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2237
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2338
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2439

25-
export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
40+
export function deploy_essentials(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.ICluster){
41+
42+
}//end deploy_essentials()
43+
44+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
45+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
46+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47+
48+
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.ICluster) {
49+
2650
// This is an example of a workload that uses a PersistentVolumeClaim with a storage class that is encrypted
2751
// with AWS KMS key.
28-
// IMPORTANT: if the cdk insfrastructure is destroyed it will leave the volume orphans, and they will
52+
// IMPORTANT: if the cdk insfrastructure is destroyed it will leave the volume orphans, and they will
2953
// need to be manually deleted.
3054
let name="test-claim-gp3";
3155
let size="10Gi";
@@ -91,13 +115,64 @@ export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack
91115
overwrite: true,
92116
prune: true,
93117
});
94-
pvc_demo_construct.node.addDependency(cluster.awsAuth);
95-
}//end deploy_workload_dependencies()
96118

97-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100119

101-
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
102120

103-
}//end deploy_workloads()
121+
122+
123+
124+
// Define a BLUE podinfo application with insecure ALB (HTTP)
125+
const BLUE_PODINFO_HELM_CONFIG = {
126+
helm_chart_release: "podinfo-blue",
127+
helm_chart_values: {
128+
ui: {
129+
color: "#0000FF",
130+
message: "This is an insecure application with BLUE background",
131+
},
132+
} as Record<string, any>,
133+
} as Podinfo_Helm_Config
134+
135+
// Deploy a podinfo sample application with BLUE background
136+
// Apply_Podinfo_Helm_Chart(cluster, config, stack, BLUE_PODINFO_HELM_CONFIG);
137+
138+
// Provisioning HTTP ALB, which includes HTTP ALB, Listener, Target Group, etc.
139+
// Apply_Podinfo_Http_Alb_YAML(cluster, config, stack, BLUE_PODINFO_HELM_CONFIG)
140+
141+
// Define a GREEN podinfo application with secure ALB (HTTPS)
142+
const GREEN_PODINFO_HELM_CONFIG = {
143+
helm_chart_release: "podinfo-green",
144+
helm_chart_values: {
145+
ui: {
146+
color: "#008000",
147+
message: "This is an secure application with GREEN background",
148+
},
149+
} as Record<string, any>,
150+
} as Podinfo_Helm_Config
151+
152+
// Deploy a podinfo sample application with GREEN background
153+
// Apply_Podinfo_Helm_Chart(cluster, config, stack, GREEN_PODINFO_HELM_CONFIG);
154+
155+
// Generate HTTPS ingress manifest
156+
/**
157+
* TODO: due to DNS ACME challenge, we just use the existing ACME's ARN and subdomain
158+
* To make this happen, you need to do:
159+
* 1. Prepare a domain or sub-domain
160+
* 2. Create a certificate in ACM for the domain / sub-domain
161+
* 3. Create CNAME to verify the certificate successfully
162+
* 4. Get the ARN of the certificate
163+
* 5. Deploy the stack
164+
* 6. After ALB is provisioned, create a CNAME record of the domain/sub-domain with the value in the DNS hostname of the ALB
165+
*/
166+
// const https_ingress_yaml = Podinfo_Https_Ingress_Yaml_Generator(
167+
// GREEN_PODINFO_HELM_CONFIG,
168+
// // ACME ARN
169+
// "arn:aws:acm:ap-southeast-2:092464092456:certificate/a2e016d5-58fb-4308-b894-f7a21f7df0b8",
170+
// // Sub-domain
171+
// "kefeng-easyeks.gcp.au-pod-1.cs.doit-playgrounds.dev",
172+
// )
173+
174+
// kubectl apply manifest
175+
// Apply_Podinfo_Https_Alb_YAML(cluster, config, stack,
176+
// GREEN_PODINFO_HELM_CONFIG,
177+
// "arn:aws:acm:ap-southeast-2:092464092456:certificate/a2e016d5-58fb-4308-b894-f7a21f7df0b8")
178+
}//end deploy_workloads()

config/eks/global_baseline_eks_config.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack){ //
1616
// More details:
1717
// - https://docs.aws.amazon.com/eks/latest/userguide/eks-using-tags.html#tag-restrictions
1818
// - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions
19-
19+
config.addClusterAdminARN(`arn:aws:iam::${process.env.CDK_DEFAULT_ACCOUNT}:role/kubectl-helm-lambda-deployer-role-used-by-easy-eks`);
20+
//^-- cdk-main.ts calls a Utility.ts library that uses aws cli to ensure this role exists (cdk errors would occur if it wasn't pre-existing.)
2021
}//end apply_config()
2122

2223
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2324
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2425
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2526

26-
export function deploy_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
27+
export function deploy_addons(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
2728

2829
/*To see official names of all eks add-ons:
2930
aws eks describe-addon-versions \
@@ -42,20 +43,20 @@ export function deploy_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Sta
4243
// but if you manually update in GUI it'll stay updated
4344
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4445

45-
}//end deploy_dependencies()
46+
}//end deploy_addons()
4647

4748
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4849
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4950
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5051

51-
export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
52+
export function deploy_essentials(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.ICluster){
5253

53-
}//end deploy_workload_dependencies()
54+
}//end deploy_essentials()
5455

5556
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5657
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5758
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5859

59-
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
60+
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.ICluster){
6061

6162
}//end deploy_workloads()

0 commit comments

Comments
 (0)