Skip to content

Commit fd51fbd

Browse files
committed
Convert from broken Ngrok to inlets
Fixes: #196 Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent fd3dd49 commit fd51fbd

File tree

3 files changed

+69
-35
lines changed

3 files changed

+69
-35
lines changed

lab5.md

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ We're going to use OpenFaaS functions to create a GitHub bot named `issue-bot`.
1313

1414
The job of issue-bot is to triage new issues by analysing the sentiment of the "description" field, it will then apply a label of *positive* or *review*. This will help the maintainers with their busy schedule so they can prioritize which issues to look at first.
1515

16-
![](./diagram/issue-bot.png)
16+
![Diagram of the issue bot](./diagram/issue-bot.png)
1717

1818
## Get a GitHub account
1919

@@ -23,58 +23,92 @@ The job of issue-bot is to triage new issues by analysing the sentiment of the "
2323

2424
Note: we will only use this repository as a testing ground for creating Issues. You don't need to commit any code there.
2525

26-
## Set up a tunnel with ngrok
26+
## Set up a tunnel with inlets
2727

28-
You will need to receive incoming webhooks from GitHub. In production you will have a clear route for incoming traffic but within the constraints of a workshop we have to be creative.
28+
You will need to receive incoming webhooks from GitHub. Fortunately, inlets makes this very quick and simple. It's available on a monthly or annual subscription, so if you are not sure if you are going to need it all year, you can just pay for a single month.
2929

30-
Open a new Terminal and type in:
30+
inlets has a Kubernetes integration called the inlets-operator. You can use it to setup LoadBalancers or Ingress with TLS. It works by creating a cloud VM for you and running a tunnel server there, it then runs a tunnel client as a Pod for you and you get incoming traffic.
3131

32+
Create a write access token under the API page of your preferred cloud provider, such as DigitalOcean, then save the contents to `digital-ocean-api-token.txt`.
33+
34+
After setting your subscription, save your key to `$HOME/.inlets/LICENSE` and run the following:
35+
36+
```bash
37+
arkade install inlets-operator \
38+
--provider digitalocean \
39+
--region lon1 \
40+
--token-file $HOME/digital-ocean-api-token.txt
3241
```
33-
$ kubectl -n openfaas run \
34-
--image=alexellis2/ngrok-admin \
35-
--port=4040 \
36-
ngrok -- http gateway:8080
3742

38-
$ kubectl -n openfaas expose deployment ngrok \
39-
--type=NodePort \
40-
--name=ngrok
43+
This will deploy the inlets-operator and instruct it to provision new hosts on DigitalOcean into the London region for your tunnel servers. Other providers and regions are available, [see the docs for more](https://docs.inlets.dev/reference/inlets-operator/).
44+
45+
## Log into your gateway with the Gateway's public IP
46+
47+
Retrieve your gateway password with the message from:
4148

42-
$ kubectl port-forward deployment/ngrok 4040:4040 -n openfaas
49+
```bash
50+
arkade info openfaas
4351
```
4452

45-
Use the built-in UI of `ngrok` at http://127.0.0.1:4040 to find your HTTP URL. You will be given a URL that you can access over the Internet, it will connect directly to your OpenFaaS API Gateway.
53+
The public IP for the LoadBalancer will take around 10-30 seconds to appear:
4654

47-
> Note: `ngrok` also provides a JSON API at `http://127.0.0.1:4040/api/tunnels`
55+
```bash
56+
kubectl get svc -n openfaas gateway-external
57+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
58+
gateway-external LoadBalancer 10.96.29.46 <pending> 8080:32278/TCP 5h56m
59+
gateway-external LoadBalancer 10.96.29.46 165.227.233.227 8080:32278/TCP 5h56m
60+
```
4861

49-
## Log into the gateway with the ngrok address
62+
Then save it into an environment variable:
5063

51-
Since we now have a new URL for ngrok let's save login details for the new URL:
64+
```bash
65+
export OPENFAAS_URL=http://165.227.233.227:8080
66+
```
5267

53-
* Retrieve your password using the [troubleshooting guide](https://docs.openfaas.com/deployment/troubleshooting/#i-forgot-my-gateway-password)
68+
Log in with the password you were given to the public IP:
5469

55-
* Run `export PASSWORD="value-here"
70+
```bash
71+
echo $PASSWORD | faas-cli login --password-stdin
72+
```
5673

57-
* Run `export NGROK_ADDRESS=https://fuh83fhfj.ngrok.io`
74+
Finally test the remote URL such as http://165.227.233.227:8080
5875

59-
* Now log in: `echo $PASSWORD | faas-cli login -g $NGROK_ADDRESS --username=admin --password-stdin`
76+
You can run commands against the remote gateway by setting the `OPENFAAS_URL` environment variable or by using the `--gateway` flag.
6077

61-
Finally * test the remote URL such as https://fuh83fhfj.ngrok.io
78+
If you'd like to expose OpenFaaS with a TLS certificate and a custom domain, you can follow these instructions instead:
6279

80+
```bash
81+
arkade install ingress-nginx
82+
arkade install cert-manager
83+
arkade install openfaas
84+
arkade install openfaas-ingress \
85+
86+
--domain openfaas.example.com
6387
```
64-
$ faas-cli list --gateway https://fuh83fhfj.ngrok.io/
88+
89+
Then create a DNS A record pointing at the IP address of ingress-nginx:
90+
91+
```bash
92+
kubectl get svc ingress-nginx-controller
93+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
94+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
95+
ingress-nginx-controller LoadBalancer 10.96.179.20 <pending> 80:30319/TCP,443:31591/TCP 20s
96+
ingress-nginx-controller LoadBalancer 10.96.179.20 209.97.135.63 80:30319/TCP,443:31591/TCP 52s
6597
```
6698

67-
> Note: you will notice that because we used the HTTPS url, that the warning about using an insecure certificate disappeared. The OpenFaaS documentation shows [how to setup Ingress with TLS for OpenFaaS](https://docs.openfaas.com/reference/ssl/kubernetes-with-cert-manager/). If you're using a remote cluster then you can try this after completing all the labs.
99+
That'll now give you a custom TLS record for `https://openfaas.example.com`
68100

69101
## Create a webhook receiver `issue-bot`
70102

71-
```
72-
$ faas-cli new --lang python3 issue-bot --prefix="<your-docker-username-here>"
103+
```bash
104+
export OPENFAAS_PREFIX="docker.io/your-username"
105+
$ faas-cli new --lang python3 \
106+
issue-bot
73107
```
74108

75109
Now edit the function's YAML file `issue-bot.yml` and add an environmental variable of `write_debug: true`:
76110

77-
```
111+
```yaml
78112
provider:
79113
name: openfaas
80114
gateway: http://127.0.0.1:8080
@@ -83,14 +117,14 @@ functions:
83117
issue-bot:
84118
lang: python3
85119
handler: ./issue-bot
86-
image: <user-name>/issue-bot
120+
image: docker.io/your-username/issue-bot
87121
environment:
88122
write_debug: true
89123
```
90124
91125
* Build, push and deploy the function with
92126
93-
```
127+
```bash
94128
$ faas-cli up -f ./issue-bot.yml
95129
```
96130

@@ -100,15 +134,15 @@ Log back into GitHub and navigate to your repository *bot-tester*
100134

101135
Click *Settings* -> *Webhooks* -> *Add Webhook*
102136

103-
![](./screenshot/add_github_webhook.png)
137+
![Adding the webhook](./screenshot/add_github_webhook.png)
104138

105-
Now enter the URL you were given from `ngrok` adding `/function/issue-bot` to the end, for example:
139+
Now enter the URL you were given from inlets or your custom domain adding `/function/issue-bot` to the end, for example:
106140

107141
```
108-
http://fuh83fhfj.ngrok.io/function/issue-bot
142+
https://openfaas.example.com
109143
```
110144

111-
![](./screenshot/WebhookURLSettings.png)
145+
![Adding the webhook](./screenshot/issue-bot-webhook.png)
112146

113147
For *Content-type* select: *application/json*
114148

@@ -118,7 +152,7 @@ And select "Let me select individual events"
118152

119153
For events select **Issues** and **Issue comment**
120154

121-
![](./screenshot/WebhookEventsSettings.png)
155+
![Setting the events](./screenshot/WebhookEventsSettings.png)
122156

123157
## Check it worked
124158

@@ -138,7 +172,7 @@ You can see the payload sent via GitHub by typing in `docker service logs -f iss
138172

139173
The GitHub Webhooks page will also show every message sent under "Recent Deliveries", you can replay a message here and see the response returned by your function.
140174

141-
![](./screenshot/github_replay.png)
175+
![Replaying an event](./screenshot/github_replay.png)
142176

143177
### Deploy SentimentAnalysis function
144178

@@ -214,7 +248,7 @@ Use the CLI to build and deploy the function:
214248
$ faas-cli up -f issue-bot.yml
215249
```
216250

217-
Now create a new issue in the `bot-tester` repository. GitHub will respond by sending a JSON payload to your function via the Ngrok tunnel we set up at the start.
251+
Now create a new issue in the `bot-tester` repository. GitHub will respond by sending a JSON payload to your function via the Inlets tunnel we configured earlier.
218252

219253
You can view the request/response directly on GitHub - navigate to *Settings* -> *Webhook* as below:
220254

screenshot/github_replay.png

-3.8 KB
Loading

screenshot/issue-bot-webhook.png

44.9 KB
Loading

0 commit comments

Comments
 (0)