Skip to content

Commit 2009741

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

File tree

5 files changed

+484
-3
lines changed

5 files changed

+484
-3
lines changed

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: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as cdk from 'aws-cdk-lib';
33
import * as eks from 'aws-cdk-lib/aws-eks'
44
import * as iam from 'aws-cdk-lib/aws-iam';
55
import request from 'sync-request-curl'; //npm install sync-request-curl (cdk requires sync functions, async not allowed)
6+
import { Apply_Podinfo_Http_YAMLs, Apply_Podinfo_Https_YAMLs, Podinfo_Helm_Config, Podinfo_HELM_Generator } from "../../lib/Podinfo_Manifests";
7+
68
//Intended Use:
79
//EasyEKS Admins: edit this file with config to apply to all dev cluster's in your org.
810

@@ -31,5 +33,17 @@ export function deploy_workload_dependencies(config: Easy_EKS_Config_Data, stack
3133
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3234

3335
export function deploy_workloads(config: Easy_EKS_Config_Data, stack: cdk.Stack, cluster: eks.Cluster){
34-
35-
}//end deploy_workloads()
36+
const podinfo_helm_config_a: Podinfo_Helm_Config = (new Podinfo_HELM_Generator({
37+
cluster, config,
38+
release: "sample-app-a"
39+
}
40+
)).generate_manifests()
41+
Apply_Podinfo_Http_YAMLs(stack, cluster, config, podinfo_helm_config_a)
42+
43+
const podinfo_helm_config_b: Podinfo_Helm_Config = (new Podinfo_HELM_Generator({
44+
cluster, config,
45+
release: "sample-app-b"
46+
}
47+
)).generate_manifests()
48+
Apply_Podinfo_Https_YAMLs(stack, cluster, config, podinfo_helm_config_b)
49+
}//end deploy_workloads()

lib/Podinfo_Manifests.ts

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as eks from 'aws-cdk-lib/aws-eks';
3+
import { IConstruct } from 'constructs';
4+
import { Easy_EKS_Config_Data } from "./Easy_EKS_Config_Data";
5+
6+
export interface Podinfo_Helm_Config {
7+
helm_chart_version: string,
8+
helm_chart_release: string,
9+
helm_chart_values?: Record<string, any> | undefined,
10+
}
11+
12+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
13+
export class Podinfo_HELM_Generator {
14+
15+
config: Easy_EKS_Config_Data;
16+
cluster: eks.Cluster;
17+
release: string;
18+
19+
// Plausible Values to expect:
20+
constructor(input_parmeters: Partial<Podinfo_HELM_Generator>) {
21+
Object.assign(this, input_parmeters);
22+
}
23+
24+
generate_manifests(): Podinfo_Helm_Config {
25+
let config = this.config;
26+
let cluster = this.cluster;
27+
28+
const array_of_yaml_manifests_to_return = {
29+
helm_chart_release: this.release,
30+
}
31+
32+
return array_of_yaml_manifests_to_return as Podinfo_Helm_Config;
33+
} //end generate_manifests
34+
35+
} //end class Podinfo_YAML_Generator
36+
37+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38+
const Podinfo_Http_Ingress_Yaml_Generator = (serviceName: string, servicePort: number): Record<string, any> => {
39+
return {
40+
"apiVersion": "networking.k8s.io/v1",
41+
"kind": "Ingress",
42+
"metadata": {
43+
"name": `${serviceName}-ingress`,
44+
"namespace": "default",
45+
"annotations": {
46+
"kubernetes.io/ingress.class": "alb",
47+
"alb.ingress.kubernetes.io/scheme": "internet-facing",
48+
"alb.ingress.kubernetes.io/target-type": "ip",
49+
"alb.ingress.kubernetes.io/group.name": serviceName,
50+
"alb.ingress.kubernetes.io/ip-address-type": "dualstack",
51+
"alb.ingress.kubernetes.io/listen-ports": '[{"HTTP": 80}]',
52+
"alb.ingress.kubernetes.io/backend-protocol": "HTTP",
53+
54+
},
55+
"labels": {
56+
"app": `${serviceName}-ingress`
57+
}
58+
},
59+
"spec": {
60+
"rules": [
61+
{
62+
"http": {
63+
"paths": [
64+
{
65+
"path": "/",
66+
"pathType": "Prefix",
67+
"backend": {
68+
"service": {
69+
"name": serviceName,
70+
"port": {
71+
"number": servicePort,
72+
}
73+
},
74+
}
75+
}
76+
]
77+
}
78+
}
79+
]
80+
}
81+
} as Record<string, any>;
82+
}
83+
84+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85+
const Podinfo_Https_Ingress_Yaml_Generator = (serviceName: string, servicePort: number, certificateArn: string, host: string): Record<string, any> => {
86+
return {
87+
"apiVersion": "networking.k8s.io/v1",
88+
"kind": "Ingress",
89+
"metadata": {
90+
"name": `${serviceName}-ingress`,
91+
"namespace": "default",
92+
"annotations": {
93+
"kubernetes.io/ingress.class": "alb",
94+
"alb.ingress.kubernetes.io/scheme": "internet-facing",
95+
"alb.ingress.kubernetes.io/target-type": "ip",
96+
"alb.ingress.kubernetes.io/group.name": serviceName,
97+
"alb.ingress.kubernetes.io/ip-address-type": "dualstack",
98+
"alb.ingress.kubernetes.io/listen-ports": '[{"HTTP": 80}, {"HTTPS": 443}]',
99+
"alb.ingress.kubernetes.io/backend-protocol": "HTTP",
100+
"alb.ingress.kubernetes.io/actions.ssl-redirect": '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}',
101+
"alb.ingress.kubernetes.io/certificate-arn": certificateArn
102+
},
103+
"labels": {
104+
"app": `${serviceName}-ingress`
105+
}
106+
},
107+
"spec": {
108+
"rules": [
109+
{
110+
"host": host,
111+
"http": {
112+
"paths": [
113+
{
114+
"path": "/",
115+
"pathType": "Prefix",
116+
"backend": {
117+
"service": {
118+
"name": serviceName,
119+
"port": {
120+
"number": servicePort,
121+
}
122+
},
123+
}
124+
}
125+
]
126+
}
127+
}
128+
]
129+
}
130+
} as Record<string, any>;
131+
}
132+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133+
const Apply_Podinfo_YAMLs = (stack: cdk.Stack, cluster: eks.Cluster,
134+
config: Easy_EKS_Config_Data,
135+
podinfo_helm_config: Podinfo_Helm_Config,
136+
readiness_dependency: IConstruct | undefined = undefined) => {
137+
if (readiness_dependency) {
138+
cluster.node.addDependency(readiness_dependency);
139+
}
140+
141+
cluster.addHelmChart(`podinfo_${podinfo_helm_config.helm_chart_release}`, {
142+
repository: "https://stefanprodan.github.io/podinfo",
143+
chart: "podinfo",
144+
release: podinfo_helm_config.helm_chart_release,
145+
version: podinfo_helm_config.helm_chart_version || "6.9.0",
146+
values: {
147+
...podinfo_helm_config.helm_chart_values,
148+
},
149+
})
150+
151+
} //end function Apply_Podinfo_YAMLs
152+
153+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
154+
export function Apply_Podinfo_Http_YAMLs(stack: cdk.Stack, cluster: eks.Cluster,
155+
config: Easy_EKS_Config_Data,
156+
podinfo_helm_config: Podinfo_Helm_Config,
157+
readiness_dependency: IConstruct | undefined = undefined) {
158+
159+
160+
Apply_Podinfo_YAMLs(stack, cluster, config, podinfo_helm_config, readiness_dependency);
161+
const apply_podinfo_ingress_YAML = new eks.KubernetesManifest(stack, `${podinfo_helm_config.helm_chart_release}-podinfo-ingress`,
162+
{
163+
cluster: cluster,
164+
manifest: [Podinfo_Http_Ingress_Yaml_Generator(`${podinfo_helm_config.helm_chart_release}-podinfo`, 9898)],
165+
overwrite: true,
166+
prune: true,
167+
}
168+
);
169+
if (readiness_dependency) {
170+
apply_podinfo_ingress_YAML.node.addDependency(readiness_dependency);
171+
}
172+
apply_podinfo_ingress_YAML.node.addDependency(cluster.awsAuth);
173+
} //end function Apply_Podinfo_Http_YAMLs
174+
175+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
176+
export function Apply_Podinfo_Https_YAMLs(stack: cdk.Stack, cluster: eks.Cluster,
177+
config: Easy_EKS_Config_Data,
178+
podinfo_helm_config: Podinfo_Helm_Config,
179+
readiness_dependency: IConstruct | undefined = undefined) {
180+
181+
Apply_Podinfo_YAMLs(stack, cluster, config, podinfo_helm_config, readiness_dependency);
182+
const apply_podinfo_ingress_YAML = new eks.KubernetesManifest(stack, `${podinfo_helm_config.helm_chart_release}-podinfo-ingress`,
183+
{
184+
cluster: cluster,
185+
manifest: [
186+
Podinfo_Https_Ingress_Yaml_Generator(
187+
`${podinfo_helm_config.helm_chart_release}-podinfo`,
188+
9898,
189+
"arn:aws:acm:ap-southeast-2:092464092456:certificate/a2e016d5-58fb-4308-b894-f7a21f7df0b8",
190+
"kefeng-easyeks.gcp.au-pod-1.cs.doit-playgrounds.dev")],
191+
overwrite: true,
192+
prune: true,
193+
}
194+
);
195+
if (readiness_dependency) {
196+
apply_podinfo_ingress_YAML.node.addDependency(readiness_dependency);
197+
}
198+
apply_podinfo_ingress_YAML.node.addDependency(cluster.awsAuth);
199+
} //end function Apply_Podinfo_Https_YAMLs
200+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)