forked from hashicorp/terraform-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·69 lines (63 loc) · 2.38 KB
/
main.py
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
#!/usr/bin/env python
from constructs import Construct
from cdktf import App, TerraformStack
from imports.kubernetes import Namespace, Service, Deployment, KubernetesProvider
class MyStack(TerraformStack):
def __init__(self, scope: Construct, ns: str):
super().__init__(scope, ns)
KubernetesProvider(self, 'kind', config_path="~/.kube/config")
example_namespace = Namespace(self, "tf-cdk-example",
metadata=[{
'name': 'tf-cdk-example'
}])
app_name = "nginx-example"
Deployment(self, 'nginx-deployment',
metadata=[{
'name': app_name,
'namespace': example_namespace.metadata_input[0].name,
'labels': {
'app': app_name
}
}],
spec=[{
'replicas': 2,
'selector': [{
'matchLabels': {
'app': app_name
}
}],
'template': [{
'metadata': [{
'labels': {
'app': app_name
}
}],
'spec': [{
'container': [{
'image': 'nginx:1.7.9',
'name': 'example',
'ports': [{
'containerPort': 80
}]
}]
}]
}]
}])
Service(self, "tf-cdk-service",
metadata=[{
'name': 'tf-cdk-service'
}],
spec=[{
'selector': {
'app': app_name
},
'port': [{
'nodePort': 30201,
'port': 80,
'target_port': 80
}],
'type': 'NodePort'
}])
app = App()
MyStack(app, "python-kubernetes")
app.synth()