-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
77 lines (69 loc) · 1.94 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* eslint-disable max-len */
import { App, TerraformStack } from 'cdktf';
import { Construct } from 'constructs';
import * as path from 'path';
import * as k8s from '@cdktf/provider-kubernetes';
import { MyKindCluster } from './cluster-setup/cluster';
import { LocalRegistryConfigMap } from './cluster-setup/local-registry-configmap';
import { SimpleKubernetesWebApp } from './constructs';
import { SimpleKubernetesWebAppConfig } from './constructs/types';
class MyStack extends TerraformStack {
constructor(scope: Construct, name: string, config: {
frontend: SimpleKubernetesWebAppConfig;
backend: SimpleKubernetesWebAppConfig;
}) {
super(scope, name);
new k8s.provider.KubernetesProvider(this, 'kind', {
configPath: path.join(__dirname, '../kubeconfig.yaml'),
});
new MyKindCluster(this, 'test-cluster');
new LocalRegistryConfigMap(this, 'local-registry-hosting');
const appBackend = new SimpleKubernetesWebApp(this, 'back', config.backend);
new SimpleKubernetesWebApp(this, 'frontend', {
...config.frontend,
env: {
BACKEND_APP_URL: `http://localhost:${appBackend.config.port}`
}
});
// NOTE: So this is a pod that I built by my own now its time to deploy
// Some docker images that I should build by my self and push them
// To my registry then, deploy the pods.
new k8s.pod.Pod(this, 'nginx', {
metadata: {
name: 'test-nginx',
labels: {
app: 'test',
}
},
spec: {
container: [{
image: 'nginx:latest',
name: 'test-container-with-cdktf',
port: [{
containerPort: 80,
}]
}]
}
});
}
}
const app = new App();
new MyStack(app, 'infra', {
frontend: {
image: 'localhost:5000/nocorp-frontend:latest',
replicas: 3,
port: 30001,
app: 'myapp',
environment: 'dev',
component: 'frontend',
},
backend: {
image: 'localhost:5000/nocorp-backend:latest',
replicas: 3,
port: 30002,
app: 'myapp',
environment: 'dev',
component: 'backend',
}
});
app.synth();