-
Notifications
You must be signed in to change notification settings - Fork 89
/
kubernetes.tf
251 lines (206 loc) · 7.36 KB
/
kubernetes.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
provider "kubernetes" {
{% if cookiecutter.provider == "local" %}
config_path = "~/.kube/config"
{% if cookiecutter.local.kube_context is defined %}
config_context = "{{ cookiecutter.local.kube_context }}"
{% endif %}
{% elif cookiecutter.provider == "azure" %}
username = module.kubernetes.credentials.username
password = module.kubernetes.credentials.password
client_certificate = module.kubernetes.credentials.client_certificate
client_key = module.kubernetes.credentials.client_key
cluster_ca_certificate = module.kubernetes.credentials.cluster_ca_certificate
host = module.kubernetes.credentials.endpoint
{% else %}
host = module.kubernetes.credentials.endpoint
cluster_ca_certificate = module.kubernetes.credentials.cluster_ca_certificate
token = module.kubernetes.credentials.token
{% endif %}
}
provider "kubernetes-alpha" {
{% if cookiecutter.provider == "local" %}
config_path = "~/.kube/config"
{% if cookiecutter.local.kube_context is defined %}
config_context = "{{ cookiecutter.local.kube_context }}"
{% endif %}
{% elif cookiecutter.provider == "azure" %}
username = module.kubernetes.credentials.username
password = module.kubernetes.credentials.password
client_certificate = module.kubernetes.credentials.client_certificate
client_key = module.kubernetes.credentials.client_key
cluster_ca_certificate = module.kubernetes.credentials.cluster_ca_certificate
host = module.kubernetes.credentials.endpoint
{% else %}
host = module.kubernetes.credentials.endpoint
cluster_ca_certificate = module.kubernetes.credentials.cluster_ca_certificate
token = module.kubernetes.credentials.token
{% endif %}
}
module "kubernetes-initialization" {
source = "./modules/kubernetes/initialization"
namespace = var.environment
secrets = []
}
{% if cookiecutter.provider == "aws" -%}
module "kubernetes-nfs-mount" {
source = "./modules/kubernetes/nfs-mount"
name = "nfs-mount"
namespace = var.environment
nfs_capacity = "{{ cookiecutter.storage.shared_filesystem }}"
nfs_endpoint = module.efs.credentials.dns_name
}
{% else -%}
module "kubernetes-nfs-server" {
source = "./modules/kubernetes/nfs-server"
name = "nfs-server"
namespace = var.environment
nfs_capacity = "{{ cookiecutter.storage.shared_filesystem }}"
node-group = local.node_groups.general
depends_on = [
module.kubernetes-initialization
]
}
module "kubernetes-nfs-mount" {
source = "./modules/kubernetes/nfs-mount"
name = "nfs-mount"
namespace = var.environment
nfs_capacity = "{{ cookiecutter.storage.shared_filesystem }}"
nfs_endpoint = module.kubernetes-nfs-server.endpoint_ip
depends_on = [
module.kubernetes-nfs-server
]
}
{% endif %}
module "kubernetes-conda-store-server" {
source = "./modules/kubernetes/services/conda-store"
name = "qhub"
namespace = var.environment
nfs_capacity = "{{ cookiecutter.storage.conda_store }}"
node-group = local.node_groups.general
conda-store-image = var.conda-store-image
environments = {
{% for key in cookiecutter.environments %}
"{{ key }}" = file("../environments/{{ key }}")
{% endfor %}
}
depends_on = [
module.kubernetes-initialization
]
}
module "kubernetes-conda-store-mount" {
source = "./modules/kubernetes/nfs-mount"
name = "conda-store"
namespace = var.environment
nfs_capacity = "{{ cookiecutter.storage.conda_store }}"
nfs_endpoint = module.kubernetes-conda-store-server.endpoint_ip
depends_on = [
module.kubernetes-conda-store-server
]
}
provider "helm" {
kubernetes {
{% if cookiecutter.provider == "local" %}
config_path = "~/.kube/config"
{%- else %}
host = module.kubernetes.credentials.endpoint
cluster_ca_certificate = module.kubernetes.credentials.cluster_ca_certificate
{% if cookiecutter.provider == "azure" -%}
username = module.kubernetes.credentials.username
password = module.kubernetes.credentials.password
client_certificate = module.kubernetes.credentials.client_certificate
client_key = module.kubernetes.credentials.client_key
{%- else -%}
token = module.kubernetes.credentials.token
{%- endif -%}
{% endif %}
}
}
{% if cookiecutter.provider == "aws" -%}
module "kubernetes-autoscaling" {
source = "./modules/kubernetes/services/cluster-autoscaler"
namespace = var.environment
aws-region = var.region
cluster-name = local.cluster_name
depends_on = [
module.kubernetes-initialization
]
}
{% endif -%}
module "kubernetes-ingress" {
source = "./modules/kubernetes/ingress"
namespace = var.environment
node-group = local.node_groups.general
{% if cookiecutter.certificate.type == "lets-encrypt" %}
enable-certificates = true
acme-email = "{{ cookiecutter.certificate.acme_email }}"
acme-server = "{{ cookiecutter.certificate.acme_server }}"
{% endif %}
depends_on = [
module.kubernetes-initialization
]
}
module "qhub" {
source = "./modules/kubernetes/services/meta/qhub"
name = "qhub"
namespace = var.environment
home-pvc = module.kubernetes-nfs-mount.persistent_volume_claim.name
conda-store-pvc = module.kubernetes-conda-store-mount.persistent_volume_claim.name
external-url = var.endpoint
jupyterhub-image = var.jupyterhub-image
jupyterlab-image = var.jupyterlab-image
dask-worker-image = var.dask-worker-image
dask-gateway-image = var.dask-gateway-image
general-node-group = local.node_groups.general
user-node-group = local.node_groups.user
worker-node-group = local.node_groups.worker
{% if cookiecutter.certificate.type == "existing" %}
certificate-secret-name = "{{ cookiecutter.certificate.secret_name }}"
{% endif %}
jupyterhub-overrides = [
file("jupyterhub.yaml")
]
dask_gateway_extra_config = file("dask_gateway_config.py.j2")
forwardauth-jh-client-id = local.forwardauth-jh-client-id
forwardauth-jh-client-secret = random_password.forwardauth-jhsecret.result
forwardauth-callback-url-path = local.forwardauth-callback-url-path
depends_on = [
module.kubernetes-ingress
]
}
{% if cookiecutter.prefect.enabled -%}
module "prefect" {
source = "./modules/kubernetes/services/prefect"
depends_on = [
module.qhub
]
namespace = var.environment
jupyterhub_api_token = module.qhub.jupyterhub_api_token
prefect_token = var.prefect_token
{% if cookiecutter.prefect.image is defined -%}
image = "{{ cookiecutter.prefect.image }}"
{% endif -%}
}
{% endif -%}
{% if cookiecutter.clearml.enabled -%}
module "clearml" {
source = "./modules/kubernetes/services/clearml"
namespace = var.environment
external-url = var.endpoint
tls = module.qhub.tls
depends_on = [
module.qhub
]
}
{% endif -%}
resource "random_password" "forwardauth-jhsecret" {
length = 32
special = false
}
module "forwardauth" {
source = "./modules/kubernetes/forwardauth"
namespace = var.environment
external-url = var.endpoint
jh-client-id = local.forwardauth-jh-client-id
jh-client-secret = random_password.forwardauth-jhsecret.result
callback-url-path = local.forwardauth-callback-url-path
}