-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafana.tf
112 lines (102 loc) · 2.67 KB
/
grafana.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
resource "random_string" "grafana_volume_id" {
length = 30
special = false
upper = false
numeric = false
}
resource "kubernetes_deployment" "grafana_deployment" {
metadata {
name = "grafana-deployment"
namespace = "essentials-srikanth-iyengar"
}
spec {
replicas = 1
selector {
match_labels = {
App = "grafana-deployment"
}
}
template {
metadata {
labels = {
App = "grafana-deployment"
}
}
spec {
init_container {
name = "init-master"
image = "busybox"
image_pull_policy = "Always"
command = ["sh", "-c", "chmod 777 /volumes/*"]
volume_mount {
mount_path = "/volumes/${random_string.grafana_volume_id.result}"
name = random_string.grafana_volume_id.result
}
}
init_container {
name = "init-volume-grafana"
image = "grafana/grafana"
image_pull_policy = "IfNotPresent"
command = ["sh", "-c", "echo initializing volume... && (cp -Rv /var/lib/grafana/. /init-volume-0 || true)"]
volume_mount {
mount_path = "/init-volume-0"
name = random_string.grafana_volume_id.result
sub_path = random_string.grafana_volume_id.result
}
}
container {
image = "grafana/grafana"
name = "grafana-deployment"
resources {
limits = {
cpu = "1"
memory = "1024Mi"
}
}
volume_mount {
name = random_string.grafana_volume_id.result
mount_path = "/var/lib/grafana"
sub_path = random_string.grafana_volume_id.result
}
}
volume {
name = random_string.grafana_volume_id.result
persistent_volume_claim {
claim_name = random_string.grafana_volume_id.result
}
}
}
}
}
}
resource "kubernetes_service" "grafana_service" {
metadata {
name = "grafana-service"
namespace = "essentials-srikanth-iyengar"
}
spec {
selector = {
App = "grafana-deployment"
}
port {
name = "grafana-service"
port = 3000
target_port = 3000
protocol = "TCP"
}
}
}
resource "kubernetes_persistent_volume_claim" "grafana_pvc" {
metadata {
name = random_string.grafana_volume_id.result
namespace = "essentials-srikanth-iyengar"
}
spec {
access_modes = ["ReadWriteOnce"]
resources {
requests = {
storage = "1.0Gi"
}
}
}
}