Skip to content

Commit

Permalink
Merge pull request #157 from yuvipanda/easier-testing
Browse files Browse the repository at this point in the history
Simplify setup instructions
  • Loading branch information
willingc committed Apr 18, 2018
2 parents 5170da9 + e316f4d commit cf2a3ac
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 58 deletions.
99 changes: 44 additions & 55 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,52 @@ the container and redeploy.
There is an easier way, with minikube and some networking tricks. Only tested on Linux
at this time, but should work for OS X too.

1. Install [minikube](http://kubernetes.io/docs/getting-started-guides/minikube/). Use the
[VirtualBox](https://virtualbox.org) provider. This will set up a kubernetes cluster inside
a VM on your machine. It'll also setup `kubectl` on your host machine to interact with
the kubernetes cluster, and a `~/.kube/config` file with credentials for connecting to this
cluster.
2. Run `minikube start`. This will start your kubernetes cluster if it isn't already up. Run
`kubectl get node` to make sure it is.
3. Run `minikube stop`. This will stop the VM, allowing us to perform some amount of surgery
on it to setup networking as we want.
4. Run `VBoxManage hostonlyif create`. This will create a network interface to communicate
between your VM and your host. Note the output of this command - it will mention the name of
your hostonly interface. For example, your output might be:

```
Interface 'vboxnet4' was successfully created
```

In this case, our interface name is `vboxnet4`.
5. Run the following command on your host
```
VBoxManage modifyvm minikube --nic3 hostonly --cableconnected3 on --hostonlyadapter3 vboxnet4
```
Instead of `vboxnet4` use whatever the output from step 4 was.
6. Start up minikube again with `minikube start`.
7. Now the containers running on kubernetes can connect to your host, via the IP address for `vboxnet4`
interface. You can find this IP with:
```
LINUX:
ip addr show vboxnet4 | grep 'scope global' | awk '{ print $2; }' | sed 's/\/.*$//'
1. Install [minikube](http://kubernetes.io/docs/getting-started-guides/minikube/). Use the
[VirtualBox](https://virtualbox.org) provider. This will set up a kubernetes cluster inside
a VM on your machine. It'll also setup `kubectl` on your host machine to interact with
the kubernetes cluster, and a `~/.kube/config` file with credentials for connecting to this
cluster.
2. Run `minikube start`. This will start your kubernetes cluster if it isn't already up. Run
`kubectl get node` to make sure it is.
3. Make it possible for your host to be able to talk to the pods on minikube.

MACOS:
ifconfig vboxnet4 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
```
Substituting vboxnet4 with whatever was the output of step 4.
8. Now, we need to be able to access pod ips from your host. We can do this by adding a static route
directly on your host. First we delete any existing routes for 172.17.0.0/16 (which is the pod network),
with:
```
sudo ip route delete 172.17.0.0/16
```
Note that if you had docker installed on your host, this *will* futz with it! You might have to stop
the docker daemon before doing it. Restarting the docker daemon should bring it back to working order,
however.

Then, we can add a static route that routes all pod traffic to the virtual machine, with:
```
LINUX:
sudo ip route add 172.17.0.0/16 via $(minikube ip)
On Linux:

```bash
sudo ip route add 172.17.0.0/16 via $(minikube ip)
```

On OS X:

```bash
sudo route -n add -net 172.17.0.0/16 $(minikube ip)
```

If you get an error message like the following:

```
RTNETLINK answers: File exists
```

it most likely means you have docker running on your host using the same
IP range minikube is using. You can fix this by editing your
`/etc/docker/daemon.json` file to add the following:

```json
{
"bip": "172.19.1.1/16"
}
```

If some JSON already exists in that file, make sure to just add the
`bip` key rather than replace it all. The final file needs to be valid
JSON.

Once edited, restart docker with `sudo systemctl restart docker`. It
should come up using a different IP range, and you can run the
`sudo ip route add` command again. Note that restarting docker will
restart all your running containers by default.

MACOS:
sudo route -n add -net 172.17.0.0/16 $(minikube ip)
```

TADA! Now you have a kubernetes cluster that has two way communication with your host! This lets you
run JupyterHub on your host (for faster development) while spawning pods inside Kubernetes in the
VM.

## Setting up JupyterHub for development ##

Once you have kubernetes setup this way, you can stup JupyterHub for development fairly easily on your
Expand Down
13 changes: 10 additions & 3 deletions jupyterhub_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import socket


c.JupyterHub.spawner_class = 'kubespawner.KubeSpawner'
Expand All @@ -16,9 +17,15 @@
# Our simplest user image! Optimized to just... start, and be small!
c.KubeSpawner.singleuser_image_spec = 'jupyterhub/singleuser:0.8'

# The spawned containers need to be able to talk to the hub through the proxy!
c.KubeSpawner.hub_connect_ip = os.environ['HUB_CONNECT_IP']
c.JupyterHub.hub_connect_ip = os.environ['HUB_CONNECT_IP']
# Find the IP of the machine that minikube is most likely able to talk to
# Graciously used from https://stackoverflow.com/a/166589
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
host_ip = s.getsockname()[0]
s.close()

c.KubeSpawner.hub_connect_ip = host_ip
c.JupyterHub.hub_connect_ip = c.KubeSpawner.hub_connect_ip

c.KubeSpawner.singleuser_service_account = 'default'
# Do not use any authentication at all - any username / password will work.
Expand Down

0 comments on commit cf2a3ac

Please sign in to comment.