-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
55 lines (48 loc) · 1.93 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
import { Construct } from 'constructs'
import { App, Chart, ChartProps } from 'cdk8s'
// imported constructs
import { KubeDeployment, KubeService, IntOrString } from './imports/k8s'
export class SampleChart extends Chart {
constructor(scope: Construct, id: string, props: ChartProps = {}) {
super(scope, id, props)
// define resources here
const label = { app: 'cdk8s-sample' }
// notice that there is no assignment necessary when creating resources.
// simply instantiating the resource is enough because it adds it to the construct tree via
// the first argument, which is always the parent construct.
// its a little confusing at first glance, but this is an inherent aspect of the constructs
// programming model, and you will encounter it many times.
// you can still perform an assignment of course, if you need to access
// attributes of the resource in other parts of the code.
new KubeService(this, 'service', {
spec: {
type: 'LoadBalancer',
ports: [{ port: 80, targetPort: IntOrString.fromNumber(8080) }],
selector: label,
},
})
new KubeDeployment(this, 'deployment', {
spec: {
replicas: 2,
selector: {
matchLabels: label,
},
template: {
metadata: { labels: label },
spec: {
containers: [
{
name: 'hello-kubernetes',
image: 'paulbouwer/hello-kubernetes:1.7',
ports: [{ containerPort: 8080 }],
},
],
},
},
},
})
}
}
const app = new App()
new SampleChart(app, 'cdk8s-sample')
app.synth()