-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
88 lines (80 loc) · 1.63 KB
/
main.tf
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
78
79
80
81
82
83
84
85
86
87
88
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
}
}
}
provider "kubernetes" {
config_path = "~/.kube/config"
}
resource "kubernetes_namespace" "terraform-demo-nginx" {
metadata {
annotations = {
name = "terraform-demo-nginx"
}
labels = {
app = "terraform-demo-nginx"
}
name = "terraform-demo-nginx"
}
}
resource "kubernetes_deployment" "terraform-demo-nginx" {
metadata {
name = "terraform-demo-nginx"
namespace= "terraform-demo-nginx"
labels = {
app = "terraform-demo-nginx"
}
}
spec {
replicas = 2
selector {
match_labels = {
app = "terraform-demo-nginx"
}
}
template {
metadata {
labels = {
app = "terraform-demo-nginx"
}
}
spec {
container {
image = var.image_tag
name = "terraform-demo-nginx"
port {
container_port = var.nginx_port
}
resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
}
}
}
}
}
resource "kubernetes_service" "terraform-demo-nginx" {
metadata {
name = "terraform-demo-nginx"
namespace = kubernetes_namespace.terraform-demo-nginx.metadata.0.name
}
spec {
selector = {
app = kubernetes_deployment.terraform-demo-nginx.spec.0.template.0.metadata.0.labels.app
}
type = "LoadBalancer"
port {
port = 80
target_port = 80
}
}
}