Skip to content

Commit 35450f0

Browse files
authored
Merge pull request #3158 from rgaiacs/3157-kubernetes-with-docker-desktop
Support Local Development with Kubernetes with Docker Desktop
2 parents bf4f547 + 9fc8eee commit 35450f0

File tree

6 files changed

+172
-4
lines changed

6 files changed

+172
-4
lines changed

config/localhost.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# 127.0.0.1.nip.io will not work because when pods try to use it,
2+
# the domain will resolve to the pod itself.
3+
# The deploy.py overwrite the 127.0.0.1 to the user IP address.
4+
binderhub:
5+
config:
6+
BinderHub:
7+
# Use Kubernetes DNS
8+
hub_url: http://jupyterhub.mybinder.127.0.0.1.nip.io
9+
use_registry: false
10+
image_prefix: dummy.io/localhost/binder-
11+
12+
extraConfig:
13+
# Disable send events to StackDriver on Google Cloud
14+
01-eventlog:
15+
16+
registry:
17+
username: "your-username"
18+
# This is unsafe! Only se for local development
19+
password: "your-password"
20+
21+
ingress:
22+
https:
23+
# This is unsafe! Only se for local development
24+
enabled: false
25+
hosts:
26+
- mybinder.127.0.0.1.nip.io
27+
28+
jupyterhub:
29+
ingress:
30+
hosts:
31+
- jupyterhub.mybinder.127.0.0.1.nip.io
32+
33+
static:
34+
ingress:
35+
tls:
36+
# This is unsafe! Only se for local development
37+
enabled: false
38+
hosts:
39+
- static.127.0.0.1.nip.io
40+
41+
analyticsPublisher:
42+
enabled: false
43+
44+
prometheus:
45+
enabled: false
46+
47+
grafana:
48+
enabled: false
49+
50+
cryptnono:
51+
enabled: false
52+
53+
cluster-autoscaler:
54+
enabled: false

deploy.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232

3333
# Projects using raw KUBECONFIG files
34-
KUBECONFIG_CLUSTERS = {"ovh2", "hetzner-2i2c", "hetzner-2i2c-bare"}
34+
KUBECONFIG_CLUSTERS = {"localhost", "ovh2", "hetzner-2i2c", "hetzner-2i2c-bare"}
3535

3636
# Mapping of config name to cluster name for AWS EKS deployments
3737
AWS_DEPLOYMENTS = {"curvenote": "binderhub"}
@@ -199,7 +199,14 @@ def get_config_files(release, config_dir="config"):
199199
return config_files
200200

201201

202-
def deploy(release, name=None, dry_run=False, diff=False):
202+
def deploy(
203+
release,
204+
name=None,
205+
dry_run=False,
206+
diff=False,
207+
ip_address=None,
208+
additional_helm_args=[],
209+
):
203210
"""Deploys a federation member to a k8s cluster.
204211
205212
Waits for deployments and daemonsets to become Ready
@@ -239,6 +246,20 @@ def deploy(release, name=None, dry_run=False, diff=False):
239246
for config_file in config_files:
240247
helm.extend(["-f", config_file])
241248

249+
if release == "localhost":
250+
helm.extend(
251+
[
252+
"--set",
253+
f"binderhub.config.BinderHub.hub_url=http://jupyterhub.mybinder.{ip_address}.nip.io",
254+
"--set",
255+
f"binderhub.ingress.hosts={{mybinder.{ip_address}.nip.io}}",
256+
"--set",
257+
f"binderhub.jupyterhub.ingress.hosts={{jupyterhub.mybinder.{ip_address}.nip.io}}",
258+
"--set",
259+
f"static.ingress.hosts={{static.{ip_address}.nip.io}}",
260+
].extend(additional_helm_args)
261+
)
262+
242263
check_call(helm, dry_run)
243264
print(
244265
BOLD + GREEN + f"SUCCESS: Helm {helm_commands[0]} for {release} completed" + NC,
@@ -457,6 +478,10 @@ def main():
457478
action="store_true",
458479
help="If the script is running locally, skip auth step",
459480
)
481+
argparser.add_argument(
482+
"--local-ip",
483+
help="IP address of the local machine",
484+
)
460485
argparser.add_argument(
461486
"--dry-run",
462487
action="store_true",
@@ -474,9 +499,20 @@ def main():
474499
default=stages[0],
475500
help="Stage to deploy, default all",
476501
)
502+
argparser.add_argument(
503+
"--additional-helm-args",
504+
action="append",
505+
help="Additional argument for Helm. For example, '--additional-helm-args=--set=ingress-nginx.enabled=false' to disable the installation of ingress-nginx.",
506+
)
477507

478508
args = argparser.parse_args()
479509

510+
if args.release == "localhost":
511+
args.local = True
512+
513+
if args.local_ip is None:
514+
raise ValueError("Cluster localhost requires IP address.")
515+
480516
# if one argument given make cluster == release
481517
cluster = args.cluster or args.release
482518

@@ -518,17 +554,26 @@ def main():
518554
setup_auth_gcloud(args.release, cluster, args.dry_run)
519555
elif cluster in AWS_DEPLOYMENTS:
520556
setup_auth_aws(cluster, args.dry_run)
557+
elif cluster == "localhost":
558+
pass
521559
else:
522560
raise Exception("Cloud cluster not recognised!")
523561

524562
if args.stage in ("all", "networkban"):
525563
update_networkbans(cluster, args.dry_run)
526564
if args.stage in ("all", "system"):
527565
deploy_system_charts(args.release, args.name, args.dry_run, args.diff)
528-
if args.stage in ("all", "certmanager"):
566+
if args.stage in ("all", "certmanager") and cluster != "localhost":
529567
setup_certmanager(args.dry_run, args.diff)
530568
if args.stage in ("all", "mybinder"):
531-
deploy(args.release, args.name, args.dry_run, args.diff)
569+
deploy(
570+
args.release,
571+
args.name,
572+
args.dry_run,
573+
args.diff,
574+
args.local_ip,
575+
args.additional_helm_args,
576+
)
532577

533578

534579
if __name__ == "__main__":

docs/source/getting_started/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ permissions, as well as contextual information about the mybinder.org deployment
99
.. toctree::
1010
:maxdepth: 3
1111

12+
local_environment
1213
getting_started
1314
production_environment
1415
terminology
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Getting started with local development
2+
3+
This page contains a starting point for people who want to know more about the BinderHub deployment by playing around with a local development instance.
4+
5+
## Local Kubernetes
6+
7+
You will need a local Kubernetes cluster. A few options are
8+
9+
- [K3s](https://k3s.io/)
10+
- [Kubernetes with Rancher Desktop](https://www.rancher.com/products/rancher-desktop)
11+
- [minikube](https://minikube.sigs.k8s.io/docs/)
12+
- [k3d](https://k3d.io/stable/)
13+
- [kind](https://kind.sigs.k8s.io/)
14+
- [Kubernetes with Docker Desktop](https://docs.docker.com/desktop/features/kubernetes/)
15+
16+
### Install Docker Desktop
17+
18+
Install Docker Desktop on [Mac](https://docs.docker.com/desktop/setup/install/mac-install/), [Windows](https://docs.docker.com/desktop/setup/install/windows-install/), or [Linux](https://docs.docker.com/desktop/setup/install/linux/). And [turn on Kubernetes](https://docs.docker.com/desktop/features/kubernetes/#install-and-turn-on-kubernetes).
19+
20+
## Set up `kubectl` to connect to Kubernetes
21+
22+
Once you have `kubectl` installed, you can connect it with your local Kubernetes.
23+
To do so, run the following command:
24+
25+
```bash
26+
kubectl config use-context k8s-context-name
27+
```
28+
29+
If using Docker Desktop, `k8s-context-name` is `docker-desktop`.
30+
31+
You can test this out by running:
32+
33+
```bash
34+
kubectl get -A pods
35+
```
36+
37+
and a list of all running pods should be printed.
38+
39+
## Deploy mybinder.org to Kubernetes
40+
41+
Run the following command:
42+
43+
```bash
44+
source cert-manager.env
45+
```
46+
47+
```bash
48+
for d in ./mybinder*/; do
49+
helm dependency update "$d"
50+
done
51+
```
52+
53+
```bash
54+
chartpress --skip-build
55+
```
56+
57+
`deploy.py` requires your IP address (represented by `xxx.xxx.xxx.xxx` in the next command).
58+
59+
```bash
60+
python deploy.py localhost --local-ip xxx.xxx.xxx.xxx
61+
```
62+
63+
## Access your mybinder.org
64+
65+
Open http://xxx.xxx.xxx.xxx with your favourite web browser.

mybinder/templates/static/ingress.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ spec:
3030
port:
3131
number: 80
3232
{{- end }}
33+
{{- if .Values.static.ingress.tls.enabled }}
3334
tls:
3435
- secretName: {{ .Values.static.ingress.tls.secretName }}
3536
hosts:
3637
{{- range $host := .Values.static.ingress.hosts }}
3738
- {{ $host }}
3839
{{- end }}
40+
{{- end }}

mybinder/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ static:
571571
kubernetes.io/ingress.class: nginx
572572
kubernetes.io/tls-acme: "true"
573573
tls:
574+
enabled: true
574575
secretName: kubelego-tls-static
575576

576577
# values ref: https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml

0 commit comments

Comments
 (0)