🌉 Add ngrok tunnel in Tiltfile

This commit is contained in:
Jérôme Petazzoni
2021-11-28 12:46:27 +01:00
parent bc761d512a
commit c9e7dd6dfa
2 changed files with 79 additions and 17 deletions

View File

@@ -1,14 +1,58 @@
# (1) Setting up a registry, and telling Tilt to use it.
# Tilt needs a registry to store images.
# The following manifest defines a Deployment to run a basic Docker registry,
# and a NodePort Service to access it. Using a NodePort means that we don't
# need to obtain a TLS certificate, because we will be accessing the registry
# through localhost.
k8s_yaml('../k8s/tilt-registry.yaml')
# Tell Tilt to use the registry that we just deployed instead of whatever
# is defined in our Kubernetes resources. Tilt will patch image names to
# use our registry.
default_registry('localhost:30555')
# Create a port forward so that we can access the registry from our local
# environment, too. Note that if you run Tilt directly from a Kubernetes node
# (which is not typical, but might happen in some lab/training environments)
# the following might cause an error because port 30555 is already taken.
k8s_resource(workload='tilt-registry', port_forwards='30555:5000')
# (2) Telling Tilt how to build and run our app.
# Our Kubernetes manifests use images 'dockercoins/...' so we tell Tilt
# how each of these images should be built. The first argument is the name
# of the image, the second argument is the directory containing the build
# context (i.e. the Dockerfile to build the image).
docker_build('dockercoins/hasher', 'hasher')
docker_build('dockercoins/rng', 'rng')
docker_build('dockercoins/webui', 'webui')
docker_build('dockercoins/worker', 'worker')
# The following manifests defines five Deployments and four Services for
# our application.
k8s_yaml('../k8s/dockercoins.yaml')
# Uncomment the following line to let tilt run with the default kubeadm cluster-admin context.
#allow_k8s_contexts('kubernetes-admin@kubernetes')
# (3) Finishing touches.
# While we're here: if you're controlling a remote cluster, uncomment that line.
# It will create a port forward so that you can access the remote registry.
#k8s_resource(workload='registry', port_forwards='30555:5000')
# The following line lets Tilt run with the default kubeadm cluster-admin context.
allow_k8s_contexts('kubernetes-admin@kubernetes')
# This will run an ngrok tunnel to expose Tilt to the outside world.
# This is intended to be used when Tilt runs on a remote machine.
local_resource(name='ngrok:tunnel', serve_cmd='ngrok http 10350')
# This will wait until the ngrok tunnel is up, and show its URL to the user.
# We send the output to /dev/tty so that it doesn't get intercepted by
# Tilt, and gets displayed to the user's terminal instead.
# Note: this assumes that the ngrok instance will be running on port 4040.
# If you have other ngrok instances running on the machine, this might not work.
local_resource(name='ngrok:showurl', cmd='''
while sleep 1; do
TUNNELS=$(curl -fsSL http://localhost:4040/api/tunnels | jq -r .tunnels[].public_url)
[ "$TUNNELS" ] && break
done
printf "\nYou should be able to connect to the Tilt UI with the following URL(s): %s\n" "$TUNNELS" >/dev/tty
'''
)

View File

@@ -193,26 +193,44 @@ Ah, right ...
---
## Running Tilt
## Running Tilt locally
- If you're running on your local machine:
*These instructions are valid only if you run Tilt on your local machine.*
*If you are running Tilt on a remote machine or in a Pod, see next slide.*
- Start Tilt:
```bash
tilt up
```
Then press "space" or connect to http://localhost:10350/
- If you're running on a remote machine:
```bash
tilt up --host=0.0.0.0
```
Then connect to the remote machine on port 10350
- The Tilt web interface might complain about the Kubernetes context
...If it does, don't worry, we'll fix that right away!
- Then press "space" or connect to http://localhost:10350/
---
## Running Tilt on a remote machine
- If Tilt runs remotely, we can't access http://localhost:10350
- Our Tiltfile includes an ngrok tunnel, let's use that
- Start Tilt:
```bash
tilt up
```
- The ngrok URL should appear in the Tilt output
(something like `https://xxxx-aa-bb-cc-dd.ngrok.io/`)
- Open that URL in your browser
*Note: it's also possible to run `tilt up --host=0.0.0.0`.*
---
class: extra-details
## Kubernetes contexts
- Tilt is designed to run in dev environments