Skip to content

Commit a4e4444

Browse files
committed
Add tutorial on KinD for local ingress
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent aa876d8 commit a4e4444

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

docs/tutorials/local-kind-ingress.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Use a local Ingress Controller with KinD
2+
3+
Most users will use port-forwarding to access the OpenFaaS gateway, it's the simplest option and works everywhere.
4+
5+
However, in this tutorial, we will show you how to deploy OpenFaaS with ingress-nginx.
6+
7+
When you use an Ingress Controller:
8+
9+
* You can access the gateway on your host machine without port-forwarding
10+
* If you update the gateway, you don't need to restart port-forwarding commands
11+
* OpenFaaS is almost always exposed behind an Ingress Controller in production, so it's good practice to use it locally
12+
13+
Is this tutorial for you?
14+
15+
* If you want to access the local OpenFaaS gateway over the Internet with a TLS certificate, see: [Expose your local OpenFaaS functions to the Internet](https://inlets.dev/blog/2020/10/15/openfaas-public-endpoints.html)
16+
* If you are deploying to a cluster on the public Internet, see: [TLS on Kubernetes](/reference/ssl/kubernetes-with-cert-manager/)
17+
18+
## Prerequisites
19+
20+
You'll need Docker running, plus:
21+
22+
* `kind`
23+
* `kubectl`
24+
* `faas-cli`
25+
26+
You can get the above with [arkade](https://arkade.dev).
27+
28+
Run: `arkade get kind kubectl faas-cli`.
29+
30+
## Create a KinD cluster with ports 80 and 443 exposed
31+
32+
```sh
33+
cat > kind-config.yaml <<EOF
34+
kind: Cluster
35+
apiVersion: kind.x-k8s.io/v1alpha4
36+
nodes:
37+
- role: control-plane
38+
kubeadmConfigPatches:
39+
- |
40+
kind: InitConfiguration
41+
nodeRegistration:
42+
kubeletExtraArgs:
43+
node-labels: "ingress-ready=true"
44+
extraPortMappings:
45+
- containerPort: 80
46+
hostPort: 80
47+
protocol: TCP
48+
- containerPort: 443
49+
hostPort: 443
50+
protocol: TCP
51+
EOF
52+
53+
kind create cluster --name openfaas --config kind-config.yaml
54+
```
55+
56+
## Install the ingress-nginx IngressController
57+
58+
Use arkade, or [install ingress-nginx manually](https://kubernetes.github.io/ingress-nginx/deploy/).
59+
60+
```sh
61+
arkade install ingress-nginx
62+
```
63+
64+
## Install OpenFaaS with local Ingress enabled
65+
66+
Usually, Ingress is used when a cluster has a public IP address, and you want to obtain TLS certificates from Let's Encrypt. In this case, we'll use it to access the OpenFaaS gateway on the host machine.
67+
68+
Create values-ingress.yaml:
69+
70+
```yaml
71+
ingress:
72+
exposeServices: false
73+
enabled: true
74+
75+
hosts:
76+
- host: openfaas.local
77+
serviceName: gateway
78+
servicePort: 8080
79+
path: /
80+
ingressClassName: nginx
81+
annotations:
82+
annotations.kubernetes.io/ingress.class: nginx
83+
```
84+
85+
On Linux, MacOS or WSL2, edit your `/etc/hosts` file and add an entry:
86+
87+
```
88+
127.0.0.1 openfaas.local
89+
```
90+
91+
Now install OpenFaaS via the Helm chart in the usual way, but make sure you also pass `-f values-ingress.yaml`, along with your custom values.yaml file.
92+
93+
## Access OpenFaaS via Ingress
94+
95+
You can now access OpenFaaS via the URL of `http://openfaas.local`.
96+
97+
```sh
98+
export OPENFAAS_URL=http://openfaas.local
99+
100+
faas-cli login
101+
102+
faas-cli store deploy env
103+
104+
faas-cli list
105+
```
106+

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ nav:
203203
- Expanded timeouts: ./tutorials/expanded-timeouts.md
204204
- CLI with Node.js: ./tutorials/CLI-with-node.md
205205
- First Python Function: ./tutorials/first-python-function.md
206+
- Local Ingress with KinD: ./tutorials/local-kind-ingress.md
206207
- Local Registry with KinD: ./tutorials/local-kind-registry.md
207208
- Featured: ./tutorials/featured.md
208209
- Contributing:

0 commit comments

Comments
 (0)