-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (55 loc) · 1.5 KB
/
main.go
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
package main
import (
"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
"github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2"
"github.com/cloudnativehero/cdk8s/examples/hello-world/imports/k8s"
)
type MyChartProps struct {
cdk8s.ChartProps
}
func NewMyChart(scope constructs.Construct, id string, props *MyChartProps) cdk8s.Chart {
var cprops cdk8s.ChartProps
if props != nil {
cprops = props.ChartProps
}
chart := cdk8s.NewChart(scope, jsii.String(id), &cprops)
// define resources here
label := map[string]*string{"app": jsii.String("hello-k8s")}
k8s.NewKubeService(chart, jsii.String("service"), &k8s.KubeServiceProps{
Spec: &k8s.ServiceSpec{
Type: jsii.String("ClusterIP"),
Ports: &[]*k8s.ServicePort{{
Port: jsii.Number(80),
TargetPort: k8s.IntOrString_FromNumber(jsii.Number(80)),
}},
Selector: &label,
},
})
k8s.NewKubeDeployment(chart, jsii.String("deployment"), &k8s.KubeDeploymentProps{
Spec: &k8s.DeploymentSpec{
Replicas: jsii.Number(2),
Selector: &k8s.LabelSelector{
MatchLabels: &label,
},
Template: &k8s.PodTemplateSpec{
Metadata: &k8s.ObjectMeta{
Labels: &label,
},
Spec: &k8s.PodSpec{
Containers: &[]*k8s.Container{{
Name: jsii.String("my-hello-world-nginx"),
Image: jsii.String("nginx"),
Ports: &[]*k8s.ContainerPort{{ContainerPort: jsii.Number(80)}},
},
}},
},
},
})
return chart
}
func main() {
app := cdk8s.NewApp(nil)
NewMyChart(app, "hello", nil)
app.Synth()
}