main.tf
3.02 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
args = [var.args]
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
volume_host_path = [
{
volume_name = var.app_log_path_volume_name
path_on_node = var.app_log_path
}
]
volume_mount = [
{
mount_path = var.app_log_path
volume_name = var.app_log_path_volume_name
}
]
#domian map to /etc/hosts
hosts = [
for host_list in var.hosts :
{
hostname = host_list.hostname,
ip = host_list.ip
}
]
#affinity: default=true
prevent_deploy_on_the_same_node = var.prevent_deploy_on_the_same_node
#RollingUpdate
rolling_update = [
{
"max_surge" = var.max_surge,
"max_unavailable" = var.max_unavailable
}
]
}
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 = [
for p in var.ports :
{
name = "port-${p}"
internal_port = p
external_port = p
protocol = "TCP"
}
]
}
module "ingress" {
count = var.ingress_switch.switch == "on" ? 1 : 0
source = "./modules/ingress/kubernetes"
ingress_name = local.name
service_namespace = local.namespace
service_name = local.name
# annotations = {
# "nginx.ingress.kubernetes.io/proxy-send-timeout" = "360"
# "nginx.ingress.kubernetes.io/proxy-read-timeout" = "360"
# }
annotations = var.ingress_switch.annotations
rule = [
{
domain = var.ingress_switch.domain_name
external_port = var.ports[0] // Service port
path = var.ingress_switch.path
path_type = var.ingress_switch.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)
}