Skip to content

Commit 7f83230

Browse files
committed
Add --watch and local-run to local registry tutorial
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 9a65485 commit 7f83230

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

docs/tutorials/local-kind-registry.md

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# Use a local registry with KinD
22

3+
> Note: This feature is included for [OpenFaaS Standard & For Enterprises](https://openfaas.com/pricing/) customers.
4+
35
Whilst a remote registry is the easiest way to get started when developing functions, a local registry can be faster for development and testing.
46

57
Using a local registry is an optimisation, which requires some additional tooling and configuration.
68

7-
> Note: This feature is included for [OpenFaaS Standard & For Enterprises](https://openfaas.com/pricing/) customers.
9+
You can also test your functions using Docker without deploying them to OpenFaaS via the `local-run` command, learn more: [The faster way to iterate on your OpenFaaS functions](https://www.openfaas.com/blog/develop-functions-locally).
10+
11+
12+
You can find similar solutions for other local Kubernetes distributions:
13+
14+
* [k3d](https://k3d.io/v5.6.3/usage/registries/#using-a-local-registry) - local registries
15+
* [minikube](https://minikube.sigs.k8s.io/docs/handbook/registry/) - registry add-on
16+
* [microk8s](https://microk8s.io/docs/registry-built-in) - built-in registry
817

9-
## Prerequisite:
18+
## Prerequisites:
1019

1120
You need to have **Docker** installed on your machine, arkade is also recommended for installing the necessary tools, however you can install them manually if you prefer.
1221

@@ -46,6 +55,8 @@ These instructions are adapted from the KinD documentation. Our goal is to run K
4655

4756
The example below was copied from the [KinD documentation](https://kind.sigs.k8s.io/docs/user/local-registry/).
4857

58+
Save as `kind-with-registry.sh`:
59+
4960
```bash
5061
#!/bin/sh
5162
set -o errexit
@@ -117,35 +128,15 @@ EOF
117128
118129
---
119130

120-
### Note:
121-
122-
You can find similar solutions for other local Kubernetes distributions:
123-
124-
* [k3d](https://k3d.io/v5.4.4/usage/registries/#using-a-local-registry) - local registries
125-
* [minikube](https://minikube.sigs.k8s.io/docs/handbook/registry/) - registry add-on
126-
* [microk8s](https://microk8s.io/docs/registry-built-in) - built-in registry
127-
---
128-
129-
Make the script executable:
130-
131-
```bash
132-
$ chmod +x kind-with-registry.sh
133-
```
134-
135-
Run it to create your local cluster with registry:
131+
The below will create a cluster named `kind` using the script from above, with a registry pre-installed:
136132

137133
```bash
134+
$ chmod +x ./kind-with-registry.sh
138135
$ ./kind-with-registry.sh
139136
```
140137

141138
Make sure the `kubectl` context is set to the newly created cluster:
142139

143-
```bash
144-
$ kubectl config current-context
145-
```
146-
147-
If the result is not `kind-kind` then execute:
148-
149140
```bash
150141
$ kubectl config use kind-kind
151142
```
@@ -170,12 +161,14 @@ Deploy one of the OpenFaaS Pro editions along with faas-cli:
170161
$ arkade get faas-cli
171162
```
172163

164+
Follow the documentation to install [OpenFaaS Pro](https://docs.openfaas.com/deployment/pro/) with helm.
165+
166+
Or you can use arkade:
167+
173168
```bash
174169
$ arkade install openfaas --license-file ~/.openfaas/LICENSE
175170
```
176171

177-
Alternatively, install [OpenFaaS Pro](https://docs.openfaas.com/deployment/pro/) with helm, creating the required `openfaas-license` secret, and setting `openfaasPro: true`.
178-
179172
Then log in and port-forward OpenFaaS using the instructions given, or run `arkade info openfaas` to get them a second time.
180173

181174
### Create a Function
@@ -193,7 +186,7 @@ We will be using the [python3-flask-debian](https://github.com/openfaas-incubato
193186
Setup your `OPENFAAS_PREFIX` variable to configure the address of your registry:
194187

195188
```bash
196-
export OPENFAAS_PREFIX=localhost:5000
189+
export OPENFAAS_PREFIX=localhost:5001
197190
```
198191

199192
> Note: Docker for Mac users may need to change "localhost" to the IP address of their LAN or WiFi adapter as shown on `ifconfig` such as `192.168.0.14`
@@ -212,8 +205,10 @@ This will create a directory for your function and a YAML config file with the f
212205

213206
Add dependency to the `pydict/requirements.txt` file:
214207

215-
```txt
208+
```bash
209+
cat <<EOF > pydict/requirements.txt
216210
PyDictionary
211+
EOF
217212
```
218213

219214
Update `handler.py` with the following code.
@@ -231,7 +226,7 @@ Our minimal function is complete.
231226

232227
### Stack file
233228

234-
You will see that the OpenFaaS stack YAML file `pydict.yml` has `localhost:5000` in its image destination.
229+
You will see that the OpenFaaS stack YAML file `pydict.yml` has `localhost:5001` in its image destination.
235230

236231
```yaml
237232
version: 1.0
@@ -242,7 +237,7 @@ functions:
242237
pydict:
243238
lang: python3-flask-debian
244239
handler: ./pydict
245-
image: localhost:5000/pydict:latest
240+
image: localhost:5001/pydict:latest
246241
```
247242
248243
## Build Push Deploy
@@ -263,6 +258,16 @@ $ echo "advocate" | faas-cli invoke pydict
263258
{"Noun":["a person who pleads for a cause or propounds an idea","a lawyer who pleads cases in court"],"Verb":["push for something","speak, plead, or argue in favor of"]}
264259
```
265260

261+
## Watch for changes
262+
263+
You can also watch for changes in the function's source-code and automatically rebuild and deploy the function.
264+
265+
```bash
266+
faas-cli up -f pydict.yml --watch --tag=digest
267+
```
268+
269+
Now edit the source code for the function, and watch it get rebuilt and deployed automatically.
270+
266271
### Wrapping Up
267272

268273
Now that you have a local registry, you can speed up your local development of functions by keeping the container images within your local computer.

0 commit comments

Comments
 (0)