main.tf
2.7 KB
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
113
114
115
terraform {
required_providers {
kubectl = {
source = "gavinbunney/kubectl"
version = "1.14.0"
}
}
}
module "deployment" {
# disable wait for all pods be ready.
#
wait_for_rollout = false
# always pull latest version avoid fake updating.
#
image_pull_policy = "Always"
# Use local paths to avoid accessing external networks
# This module comes from terraform registry "terraform-iaac/deployment/kubernetes 1.4.2"
source = "./modules/deployment/kubernetes"
name = local.name
namespace = local.namespace
image = var.image
replicas = var.replicas
restart_policy = var.restart_policy
resources = {
request_cpu = var.request_cpu == "" ? null : var.request_cpu
limit_cpu = var.limit_cpu == "" ? null : var.limit_cpu
request_memory = var.request_memory == "" ? null : var.request_memory
limit_memory = var.limit_memory == "" ? null : var.limit_memory
}
env = var.env
readiness_probe = {
http_get = {
path = var.probe_http_path
port = var.probe_http_port
scheme = "HTTP"
}
success_threshold = 1
failure_threshold = 3
initial_delay_seconds = 30
period_seconds = 30
timeout_seconds = 3
}
# start time 4 minute failure_threshold * period_seconds = 4m
startup_probe = {
http_get = {
path = var.probe_http_path
port = var.probe_http_port
scheme = "HTTP"
}
success_threshold = 1
failure_threshold = 3
initial_delay_seconds = 10
period_seconds = 10
timeout_seconds = 5
}
}
module "service" {
# Use local paths to avoid accessing external networks
# This module comes from terraform registry "terraform-iaac/service/kubernetes 1.0.4"
source = "./modules/service/kubernetes"
app_name = local.name
app_namespace = local.namespace
type = "NodePort"
port_mapping = [
{
name = "port-${var.port}"
internal_port = var.port
external_port = var.port
protocol = "TCP"
}
]
}
module "ingress" {
source = "./modules/ingress/kubernetes"
ingress_name = local.name
service_namespace = local.namespace
service_name = local.name
rule = [
{
domain = var.domain_name
external_port = var.port // Service port
path = var.path
path_type = var.path_type
}
]
}
data "kubernetes_service" "service" {
depends_on = [module.service]
metadata {
name = local.name
namespace = local.namespace
}
}
locals {
name = coalesce(var.name, "${var.walrus_metadata_service_name}")
namespace = coalesce(var.namespace, var.walrus_metadata_namespace_name)
}