Skip to content

Commit b223219

Browse files
committed
CSI-1655: added two sample apps
1 parent f77782c commit b223219

File tree

6 files changed

+474
-12
lines changed

6 files changed

+474
-12
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ node_modules
88
.cdk.staging
99
cdk.out
1010

11-
# other CDK files
12-
cdk.context.json
13-
1411
# IDE files
1512
.idea/
1613
.vscode/

bin/cdk-main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ dev1_eks.deploy_my_orgs_baseline_eks_workloads();
127127
dev1_eks.deploy_lower_envs_eks_workloads();
128128
dev1_eks.deploy_dev_eks_workloads();
129129
//^-- deployment time of ~18.6mins (~15-20mins)
130+
///////////////////////////////////////////////////////////////////////////////////////////
130131

131132
//Example 2: Equivalent to Example 1, just with convenience methods as short hand
132133
//(This format balances usability and debugability)
@@ -136,6 +137,7 @@ dev2_eks.deploy_eks_construct_into_this_objects_stack(); //<-- creates eks clust
136137
dev2_eks.deploy_dev_baseline_dependencies(); //<-- convenience method #2
137138
dev2_eks.deploy_dev_baseline_workload_dependencies(); //<-- convenience method #3
138139
dev2_eks.deploy_dev_baseline_workloads(); //<-- convenience method #4
140+
///////////////////////////////////////////////////////////////////////////////////////////
139141

140142
//Example 3: Equivalent to Examples 1 & 2, just shorter
141143
//(This format optimizes usability, but can make debugability slightly harder)

cdk.context.json

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,77 @@
1010
},
1111
"acknowledged-issue-numbers": [
1212
32775
13-
]
13+
],
14+
"availability-zones:account=092464092456:region=ca-central-1": [
15+
"ca-central-1a",
16+
"ca-central-1b",
17+
"ca-central-1d"
18+
],
19+
"ami:account=092464092456: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",
20+
"availability-zones:account=092464092456:region=ap-southeast-2": [
21+
"ap-southeast-2a",
22+
"ap-southeast-2b",
23+
"ap-southeast-2c",
24+
"ap-southeast-2-akl-1a"
25+
],
26+
"ami:account=092464092456:filters.image-type.0=machine:filters.name.0=fck-nat-al2023-*-arm64-ebs:filters.state.0=available:owners.0=568608671756:region=ap-southeast-2": "ami-0799b4d92d35edd4a",
27+
"vpc-provider:account=092464092456:filter.isDefault=false:filter.tag:Name=lower-envs-vpc:filter.vpc-id=vpc-0b0a49daf937ebd4e:region=ap-southeast-2:returnAsymmetricSubnets=true": {
28+
"vpcId": "vpc-0b0a49daf937ebd4e",
29+
"vpcCidrBlock": "10.99.0.0/16",
30+
"ownerAccountId": "092464092456",
31+
"availabilityZones": [],
32+
"subnetGroups": [
33+
{
34+
"name": "Public",
35+
"type": "Public",
36+
"subnets": [
37+
{
38+
"subnetId": "subnet-086ef6db7aa03a0c8",
39+
"cidr": "10.99.0.0/23",
40+
"availabilityZone": "ap-southeast-2a",
41+
"routeTableId": "rtb-0ff297699d4ac7ad7"
42+
},
43+
{
44+
"subnetId": "subnet-0aa59909b88944cae",
45+
"cidr": "10.99.2.0/23",
46+
"availabilityZone": "ap-southeast-2b",
47+
"routeTableId": "rtb-006b3e4abc859c868"
48+
},
49+
{
50+
"subnetId": "subnet-0dd9405e4884934d9",
51+
"cidr": "10.99.4.0/23",
52+
"availabilityZone": "ap-southeast-2c",
53+
"routeTableId": "rtb-098ce61b7fa0c7c14"
54+
}
55+
]
56+
},
57+
{
58+
"name": "Private",
59+
"type": "Private",
60+
"subnets": [
61+
{
62+
"subnetId": "subnet-0c1bbe1320a8d4d4f",
63+
"cidr": "10.99.32.0/19",
64+
"availabilityZone": "ap-southeast-2a",
65+
"routeTableId": "rtb-039cbceea7f95d542"
66+
},
67+
{
68+
"subnetId": "subnet-048c00d9bab4574e1",
69+
"cidr": "10.99.64.0/19",
70+
"availabilityZone": "ap-southeast-2b",
71+
"routeTableId": "rtb-09947c85e71d96615"
72+
},
73+
{
74+
"subnetId": "subnet-0835a3d4741890dfa",
75+
"cidr": "10.99.96.0/19",
76+
"availabilityZone": "ap-southeast-2c",
77+
"routeTableId": "rtb-0f3be7c4448dcd376"
78+
}
79+
]
80+
}
81+
]
82+
},
83+
"key-provider:account=092464092456:aliasName=alias/eks/lower-envs:region=ap-southeast-2": {
84+
"keyId": "53d98ec6-3051-46b6-a9c6-bd1e4dbf8904"
85+
}
1486
}

config/eks/dev_eks_config.ts

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,95 @@
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_Ingress_YAML,
7+
Podinfo_Helm_Config,
8+
Podinfo_Http_Ingress_Yaml_Generator,
9+
Podinfo_Https_Ingress_Yaml_Generator,
10+
} from "../../lib/Podinfo_Manifests";
11+
612
//Intended Use:
713
//EasyEKS Admins: edit this file with config to apply to all dev cluster's in your org.
814

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");
15+
export function apply_config(config: Easy_EKS_Config_Data, stack: cdk.Stack) { //config: is of type Easy_EKS_Config_Data
16+
config.addTag("Environment", "Dev");
1117
}//end apply_config()
1218

1319
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1420
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1521
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1622

17-
export function deploy_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
23+
export function deploy_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster) {
1824

1925
}//end deploy_dependencies()
2026

2127
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2228
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2329
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2430

25-
export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
31+
export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster) {
2632

2733
}//end deploy_workload_dependencies()
2834

2935
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3036
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3137
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3238

33-
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
39+
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster) {
40+
// Define a BLUE podinfo application with insecure ALB (HTTP)
41+
const BLUE_PODINFO_HELM_CONFIG = {
42+
helm_chart_release: "podinfo-blue",
43+
helm_chart_values: {
44+
ui: {
45+
color: "#0000FF",
46+
message: "This is an insecure application with BLUE background",
47+
},
48+
} as Record<string, any>,
49+
} as Podinfo_Helm_Config
50+
51+
// Deploy a podinfo sample application with BLUE background
52+
Apply_Podinfo_Helm_Chart(cluster, BLUE_PODINFO_HELM_CONFIG);
53+
54+
// Generate HTTP ingress manifest
55+
const http_ingress_yaml = Podinfo_Http_Ingress_Yaml_Generator(BLUE_PODINFO_HELM_CONFIG);
56+
57+
// kubectl apply manifest
58+
Apply_Podinfo_Ingress_YAML(cluster, BLUE_PODINFO_HELM_CONFIG, http_ingress_yaml)
59+
60+
// Define a GREEN podinfo application with secure ALB (HTTPS)
61+
const GREEN_PODINFO_HELM_CONFIG = {
62+
helm_chart_release: "podinfo-green",
63+
helm_chart_values: {
64+
ui: {
65+
color: "#008000",
66+
message: "This is an secure application with GREEN background",
67+
},
68+
} as Record<string, any>,
69+
} as Podinfo_Helm_Config
70+
71+
// Deploy a podinfo sample application with GREEN background
72+
Apply_Podinfo_Helm_Chart(cluster, GREEN_PODINFO_HELM_CONFIG);
73+
74+
// Generate HTTPS ingress manifest
75+
/**
76+
* TODO: due to DNS ACME challenge, we just use the existing ACME's ARN and subdomain
77+
* To make this happen, you need to do:
78+
* 1. Prepare a domain or sub-domain
79+
* 2. Create a certificate in ACM for the domain / sub-domain
80+
* 3. Create CNAME to verify the certificate successfully
81+
* 4. Get the ARN of the certificate
82+
* 5. Deploy the stack
83+
* 6. After ALB is provisioned, create a CNAME record of the domain/sub-domain with the value in the DNS hostname of the ALB
84+
*/
85+
const https_ingress_yaml = Podinfo_Https_Ingress_Yaml_Generator(
86+
GREEN_PODINFO_HELM_CONFIG,
87+
// ACME ARN
88+
"arn:aws:acm:ap-southeast-2:092464092456:certificate/a2e016d5-58fb-4308-b894-f7a21f7df0b8",
89+
// Sub-domain
90+
"kefeng-easyeks.gcp.au-pod-1.cs.doit-playgrounds.dev",
91+
)
3492

35-
}//end deploy_workloads()
93+
// kubectl apply manifest
94+
Apply_Podinfo_Ingress_YAML(cluster, GREEN_PODINFO_HELM_CONFIG, https_ingress_yaml)
95+
}//end deploy_workloads()

lib/Podinfo_Manifests.ts

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as eks from 'aws-cdk-lib/aws-eks';
3+
4+
export interface Podinfo_Helm_Config {
5+
helm_chart_version: string,
6+
helm_chart_release: string,
7+
helm_chart_values?: Record<string, any> | undefined,
8+
}
9+
10+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11+
export const Podinfo_Http_Ingress_Yaml_Generator = (
12+
podinfo_helm_config: Podinfo_Helm_Config,
13+
): Record<string, any> => {
14+
return {
15+
"apiVersion": "networking.k8s.io/v1",
16+
"kind": "Ingress",
17+
"metadata": {
18+
"name": `${podinfo_helm_config.helm_chart_release}-ingress`,
19+
"namespace": "default",
20+
"annotations": {
21+
"kubernetes.io/ingress.class": "alb",
22+
"alb.ingress.kubernetes.io/scheme": "internet-facing",
23+
"alb.ingress.kubernetes.io/target-type": "ip",
24+
"alb.ingress.kubernetes.io/group.name": podinfo_helm_config.helm_chart_release,
25+
"alb.ingress.kubernetes.io/ip-address-type": "dualstack",
26+
"alb.ingress.kubernetes.io/listen-ports": '[{"HTTP": 80}]',
27+
"alb.ingress.kubernetes.io/backend-protocol": "HTTP",
28+
29+
},
30+
"labels": {
31+
"app": podinfo_helm_config.helm_chart_release,
32+
},
33+
},
34+
"spec": {
35+
"rules": [
36+
{
37+
"http": {
38+
"paths": [
39+
{
40+
"path": "/",
41+
"pathType": "Prefix",
42+
"backend": {
43+
"service": {
44+
"name": podinfo_helm_config.helm_chart_release,
45+
"port": {
46+
"number": podinfo_helm_config.helm_chart_values?.port ?? 9898,
47+
},
48+
},
49+
},
50+
},
51+
],
52+
},
53+
},
54+
],
55+
},
56+
} as Record<string, any>;
57+
}
58+
59+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60+
export const Podinfo_Https_Ingress_Yaml_Generator = (
61+
podinfo_helm_config: Podinfo_Helm_Config,
62+
certificateArn: string,
63+
host: string,
64+
): Record<string, any> => {
65+
return {
66+
"apiVersion": "networking.k8s.io/v1",
67+
"kind": "Ingress",
68+
"metadata": {
69+
"name": `${podinfo_helm_config.helm_chart_release}-ingress`,
70+
"namespace": "default",
71+
"annotations": {
72+
"kubernetes.io/ingress.class": "alb",
73+
"alb.ingress.kubernetes.io/scheme": "internet-facing",
74+
"alb.ingress.kubernetes.io/target-type": "ip",
75+
"alb.ingress.kubernetes.io/group.name": podinfo_helm_config.helm_chart_release,
76+
"alb.ingress.kubernetes.io/ip-address-type": "dualstack",
77+
"alb.ingress.kubernetes.io/listen-ports": '[{"HTTP": 80}, {"HTTPS": 443}]',
78+
"alb.ingress.kubernetes.io/backend-protocol": "HTTP",
79+
"alb.ingress.kubernetes.io/actions.ssl-redirect": '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}',
80+
"alb.ingress.kubernetes.io/certificate-arn": certificateArn,
81+
},
82+
"labels": {
83+
"app": podinfo_helm_config.helm_chart_release,
84+
},
85+
},
86+
"spec": {
87+
"rules": [
88+
{
89+
"host": host,
90+
"http": {
91+
"paths": [
92+
{
93+
"path": "/",
94+
"pathType": "Prefix",
95+
"backend": {
96+
"service": {
97+
"name": podinfo_helm_config.helm_chart_release,
98+
"port": {
99+
"number": podinfo_helm_config.helm_chart_values?.port ?? 9898,
100+
},
101+
},
102+
},
103+
},
104+
],
105+
},
106+
},
107+
],
108+
},
109+
} as Record<string, any>;
110+
}
111+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
112+
export const Apply_Podinfo_Helm_Chart = (cluster: eks.Cluster,
113+
podinfo_helm_config: Podinfo_Helm_Config) => {
114+
const podinfo_helm = cluster.addHelmChart(podinfo_helm_config.helm_chart_release, {
115+
repository: "https://stefanprodan.github.io/podinfo",
116+
chart: "podinfo",
117+
release: podinfo_helm_config.helm_chart_release,
118+
version: podinfo_helm_config.helm_chart_version || "6.9.0",
119+
values: {
120+
...podinfo_helm_config.helm_chart_values,
121+
},
122+
})
123+
podinfo_helm.node.addDependency(cluster.awsAuth);
124+
return podinfo_helm;
125+
} //end function Apply_Podinfo_Helm_Chart
126+
127+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
128+
export function Apply_Podinfo_Ingress_YAML(cluster: eks.Cluster,
129+
podinfo_helm_config: Podinfo_Helm_Config,
130+
podinfo_http_ingress_yaml: Record<string, any>) {
131+
// kubectl apply -f
132+
const ingress_manifest = cluster.addManifest(`${podinfo_helm_config.helm_chart_release}-ingress`, podinfo_http_ingress_yaml);
133+
(ingress_manifest.node.defaultChild as cdk.CfnResource).applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);
134+
135+
return ingress_manifest
136+
} //end function Apply_Podinfo_Ingress_YAML
137+
//
138+
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)