Skip to content

Commit 0887b3b

Browse files
authored
Merge pull request #2562 from minrk/cheaper-staging
Reduce cost of staging
2 parents 5a710c1 + 5a51ad4 commit 0887b3b

File tree

9 files changed

+109
-38
lines changed

9 files changed

+109
-38
lines changed

config/staging.yaml

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,29 @@ binderhub:
77
hub_url: https://hub.gke2.staging.mybinder.org
88
badge_base_url: https://staging.mybinder.org
99
image_prefix: gcr.io/binderhub-288415/r2d-staging-g5b5b759-
10+
# image_prefix: us-central1-docker.pkg.dev/binderhub-288415/staging/r2d-2023-04-
1011
sticky_builds: true
1112
build_memory_limit: "2G"
13+
# DockerRegistry:
14+
# token_url: "https://us-central1-docker.pkg.dev/v2/token"
15+
16+
# registry:
17+
# url: "https://us-central1-docker.pkg.dev"
18+
# username: "_json_key"
19+
1220
extraEnv:
1321
EVENT_LOG_NAME: "binderhub-staging-events-text"
1422

1523
resources:
1624
requests:
17-
cpu: 0.25
25+
cpu: 0.1
1826
memory: 512Mi
1927

2028
hpa:
2129
enabled: true
2230
maxReplicas: 3
2331
minReplicas: 1
24-
targetCPU: 50 # 50% of cpu request, so 0.125 CPU
32+
targetCPU: 90 # 90% of cpu request, so 90m CPU
2533

2634
dind:
2735
resources:
@@ -30,7 +38,7 @@ binderhub:
3038
memory: 1Gi
3139
limits:
3240
cpu: "1"
33-
memory: 2.5Gi
41+
memory: 1Gi
3442

3543
ingress:
3644
hosts:
@@ -41,14 +49,14 @@ binderhub:
4149
hub:
4250
resources:
4351
requests:
44-
memory: 512Mi
45-
cpu: null
52+
memory: 100M
53+
cpu: "10m"
4654
singleuser:
4755
memory:
48-
guarantee: 256M
56+
guarantee: 100M
4957
limit: 256M
5058
cpu:
51-
guarantee: 0.1
59+
guarantee: .01
5260
limit: 0.5
5361
ingress:
5462
hosts:
@@ -61,7 +69,20 @@ binderhub:
6169
- hub.gke2.staging.mybinder.org
6270
scheduling:
6371
userPlaceholder:
64-
replicas: 2
72+
replicas: 1
73+
74+
proxy:
75+
chp:
76+
resources:
77+
requests:
78+
memory: 100M
79+
cpu: 10m
80+
81+
minesweeper:
82+
resources:
83+
requests:
84+
cpu: 5m
85+
memory: 100Mi
6586

6687
grafana:
6788
ingress:
@@ -101,8 +122,16 @@ prometheus:
101122

102123
ingress-nginx:
103124
controller:
125+
replicaCount: 2
104126
service:
105127
loadBalancerIP: 35.222.35.25
128+
resources:
129+
requests:
130+
cpu: 10m
131+
memory: 100Mi
132+
limits:
133+
cpu: 500m
134+
memory: 500Mi
106135

107136
static:
108137
ingress:
@@ -137,7 +166,9 @@ analyticsPublisher:
137166
events:
138167
logName: binderhub-staging-events-text
139168
sourceBucket: binder-staging-events-raw-export
140-
169+
resources:
170+
requests:
171+
cpu: 10m
141172
# TODO: copy to values
142173
cloudCosts:
143174
sourceBucket: binder-billing-archive
@@ -153,6 +184,13 @@ gcsProxy:
153184
federationRedirect:
154185
host: staging.mybinder.org
155186
enabled: true
187+
resources:
188+
requests:
189+
cpu: 10m
190+
memory: 100Mi
191+
limits:
192+
cpu: 0.2
193+
memory: 200Mi
156194
hosts:
157195
gke:
158196
url: https://gke2.staging.mybinder.org

mybinder/templates/analytics-publisher/deployment.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ spec:
5050
- name: config
5151
mountPath: /etc/analytics-publisher
5252
readOnly: true
53-
resources:
54-
requests:
55-
cpu: 0.2
56-
memory: 200Mi
57-
limits:
58-
cpu: 0.2
59-
memory: 300Mi
53+
resources: {{ .Values.analyticsPublisher.resources | toJson }}
6054

6155
{{- end }}

mybinder/templates/federation-redirect/deployment.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ spec:
5454
- name: config
5555
mountPath: /etc/federation-redirect
5656
readOnly: true
57+
{{- with .Values.federationRedirect.resources }}
5758
resources:
58-
requests:
59-
cpu: 0.2
60-
memory: 200Mi
61-
limits:
62-
cpu: 0.2
63-
memory: 300Mi
59+
{{- . | toYaml | nindent 10 }}
60+
{{- end }}
6461
tolerations:
6562
- key: "node.kubernetes.io/unschedulable"
6663
operator: "Exists"

mybinder/templates/matomo/deployment.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ spec:
5959
volumeMounts:
6060
- name: matomo-config-rw
6161
mountPath: /var/www/html/config/
62-
resources: {{ toJson .Values.matomo.resources }}
62+
{{- with .Values.matomo.resources }}
63+
resources:
64+
{{- . | toYaml | nindent 10 }}
65+
{{- end }}
6366
- name: nginx
6467
image: nginx:1.15
6568
ports:

mybinder/templates/minesweeper/daemonset.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ spec:
5757
add:
5858
- KILL
5959
{{- with .Values.minesweeper.resources }}
60-
resources: {{ toJson . }}
60+
resources:
61+
{{- . | toYaml | nindent 10 }}
6162
{{- end }}
6263
volumeMounts:
6364
- name: config

mybinder/values.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,28 @@ analyticsPublisher:
542542
fileName: cloud-costs.jsonl
543543
kind: csv
544544
nodeSelector: {}
545+
resources:
546+
requests:
547+
cpu: 0.2
548+
memory: 200Mi
549+
limits:
550+
cpu: 0.2
551+
memory: 300Mi
545552

546553
# this is defined in secrets/ for the OVH cluster
547554
eventsArchiver:
548555
serviceAccountKey: ""
549556

550557
federationRedirect:
551-
host: mybinder.org
552558
enabled: false
559+
host: mybinder.org
560+
resources:
561+
requests:
562+
cpu: 0.2
563+
memory: 200Mi
564+
limits:
565+
cpu: 0.2
566+
memory: 300Mi
553567
image:
554568
name: jupyterhub/mybinder.org-federation-redirect
555569
tag: "set-by-chartpress"

terraform/gcp/modules/mybinder/resource.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ locals {
1616
},
1717
binderhub-builder = {
1818
display_name = "Storage access for ${var.name} image builder",
19-
role = "roles/storage.admin",
19+
role = var.use_artifact_registry ? "roles/artifactregistry.createOnPushWriter" : "roles/storage.admin",
2020
},
2121
}
2222
# add -staging to events prefix, but don't include 'prod' in prod events
@@ -25,6 +25,13 @@ locals {
2525
events_log_prefix = var.name == "prod" ? "binderhub" : "binderhub-${var.name}"
2626
}
2727

28+
resource "google_artifact_registry_repository" "repo" {
29+
location = var.registry_location != null ? var.registry_location : data.google_client_config.provider.region
30+
repository_id = var.name
31+
description = "${var.name} container registry"
32+
format = "DOCKER"
33+
}
34+
2835
resource "google_container_cluster" "cluster" {
2936
name = var.name
3037
location = var.gke_location != null ? var.gke_location : data.google_client_config.provider.zone

terraform/gcp/modules/mybinder/variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@ variable "gke_master_version" {
1414

1515
variable "gke_location" {
1616
type = string
17-
description = "GKE location for cluster if different, e.g. us-central1 for regional cluster"
17+
description = "GKE location for cluster if different from provider zone, e.g. us-central1 for regional cluster"
18+
default = null
19+
}
20+
21+
variable "use_artifact_registry" {
22+
type = bool
23+
description = "Use artifact registry instead of legacy container registry"
24+
default = false
25+
}
26+
27+
variable "registry_location" {
28+
type = string
29+
description = "Registry location for cluster if different from provider region, e.g. us for multi-region"
1830
default = null
1931
}
2032

terraform/gcp/staging/main.tf

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,36 @@ provider "google" {
1212
}
1313

1414
locals {
15-
gke_version = "1.19.14-gke.1900"
15+
gke_version = "1.24.10-gke.2300"
1616
}
1717

1818
module "mybinder" {
19-
source = "../modules/mybinder"
20-
name = "staging"
21-
gke_master_version = local.gke_version
22-
federation_members = []
19+
source = "../modules/mybinder"
20+
name = "staging"
21+
gke_master_version = local.gke_version
22+
use_artifact_registry = false
23+
federation_members = []
2324
}
2425

2526
# define node pools here, too hard to encode with variables
26-
resource "google_container_node_pool" "pool" {
27-
name = "pool-2020-09"
27+
resource "google_container_node_pool" "pool-1" {
28+
name = "pool-2023-04"
2829
cluster = module.mybinder.cluster_name
2930

3031
autoscaling {
3132
min_node_count = 1
32-
max_node_count = 4
33+
max_node_count = 3
3334
}
3435

3536
version = local.gke_version
3637

3738
node_config {
38-
machine_type = "n1-standard-4"
39-
disk_size_gb = 500
39+
# e2-medium is 2cpu, 8GB shared-core
40+
# only 1 CPU allocatable, though, and k8s itself needs most of that
41+
# e2-standard-2 is 2x as expensive
42+
# but 2 e2-standard-2 is $100/month
43+
machine_type = "e2-standard-2"
44+
disk_size_gb = 100
4045
disk_type = "pd-standard"
4146
# https://www.terraform.io/docs/providers/google/r/container_cluster.html#oauth_scopes-1
4247
oauth_scopes = [
@@ -65,7 +70,7 @@ resource "google_container_node_pool" "pool" {
6570

6671
output "private_keys" {
6772
value = module.mybinder.private_keys
68-
description = "GCP serice account keys"
73+
description = "GCP service account keys"
6974
sensitive = true
7075
}
7176

0 commit comments

Comments
 (0)