Skip to content
Permalink
Browse files

Update KinD tutorial

This becomes much simpler with kfwd

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Nov 29, 2019
1 parent 2ee7339 commit d63b9f1b17736ceb86263499eafafeb528c4f283
Showing with 36 additions and 117 deletions.
  1. +36 −117 docs/kubernetes.md
@@ -183,37 +183,40 @@ Note: this can now be simplified with `inletsctl kfwd` - [go and check it out](h

### Get KinD:

* Download a binary release:

```sh
# Linux
sudo curl -Lo /usr/local/bin/kind \
https://github.com/kubernetes-sigs/kind/releases/download/v0.4.0/kind-linux-amd64
https://github.com/kubernetes-sigs/kind/releases/download/v0.6.0/kind-linux-amd64
# MacOS
sudo curl -Lo /usr/local/bin/kind \
https://github.com/kubernetes-sigs/kind/releases/download/v0.4.0/kind-darwin-amd64
https://github.com/kubernetes-sigs/kind/releases/download/v0.6.0/kind-darwin-amd64
```

Create the cluster
* Create the cluster

```
```sh
kind create cluster
```

### Switch to the `kind` cluster with `kubectl`
* Now switch to the `kind` cluster with `kubectl`:

```sh
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
```

### Create a sample service

We'll deploy a HTTP server that runs the `figlet` binary to generate ASCII logos
We'll deploy a HTTP server that runs the `figlet` binary to generate ASCII logos.

* Define a service
* Define a service by running the below:

```yaml
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
@@ -228,11 +231,13 @@ spec:
targetPort: 8080
selector:
app: openfaas-figlet
EOF
```

Define a Deployment:
* Define a Deployment by running the following:

```yaml
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -256,139 +261,53 @@ spec:
ports:
- containerPort: 8080
protocol: TCP
EOF
```

Save both files and create the objects with `kubectl create -f`

### Now get inlets

```sh
cd /tmp/
# Download to local directory
curl -sLS https://get.inlets.dev | sh
chmod +x ./inlets
sudo mv inlets /usr/local/bin/
inlets --version
Version: 2.1.0
Git Commit: c23f6993892a1b4e398e8acf61e3dc7bfcb7c6ed
```

### Start an exit-node on your laptop (inlets server)

Our Kubernetes cluster will connect to this server.

```
export token=$(head -c 16 /dev/urandom | shasum | cut -d" " -f1)
inlets server --port=8090 --token="$token" --print-token=true
```

Note your `token` when the server starts up.
Save both files and create the objects with `kubectl create -f filename.yaml`

### Run the inlets client as a Kubernetes Deployment
### Now get inlets and inletsctl

Create a secret for the inlets client:
If you don't like running `sh` as `sudo`, then remove `sudo` and simply move the resulting binaries into your `/usr/local/bin/` folder manually after the download.

```sh
export TOKEN="" # Use the value from earlier
kubectl create secret generic inlets-token --from-literal token=${TOKEN}
curl -sLSf https://get.inlets.dev | sudo sh
curl -sLSf https://raw.githubusercontent.com/inlets/inletsctl/master/get.sh | sudo sh
```

Apply the Deployment YAML file, with `kubectl apply -f`.

Change the following two parameters:
### Start an exit-node on your laptop (inlets server)

Use your laptop's IP in place of `REMOTE-IP`:
Find the IP of your Ethernet or WiFi connection via `ifconfig`, mine was `192.168.0.14`

```sh
- "--remote=ws://REMOTE-IP"
inletsctl kfwd --if 192.168.0.14 --from openfaas-figlet:8080
```

My IP for my WiFi interface is `192.168.1.51`.

> Note: your "exit-node" could be any PC that has reachability including a VPS with a public IPv4 address.
Specify the service, or services which you want to expose:
That's it, you can now access the figlet microservice via `http://192.168.0.14:8080` or `http://127.0.0.1:8080`

```
- "--upstream=http://openfaas-figlet.default:8080"
curl -d "inlets" 192.168.0.14:8080
_ _ _
(_)_ __ | | ___| |_ ___
| | '_ \| |/ _ \ __/ __|
| | | | | | __/ |_\__ \
|_|_| |_|_|\___|\__|___/
```

This is the sample YAML:
If you need more flexibility or if want to forward more than one service you can deploy an `inlets client` Deployment manually or edit the one created by `kfwd`.

```yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: inlets
spec:
replicas: 1
template:
metadata:
labels:
app: inlets
spec:
containers:
- name: inlets
image: alexellis2/inlets:2.1.0
imagePullPolicy: Always
command: ["inlets"]
args:
- "client"
- "--remote=ws://REMOTE-IP"
- "--upstream=http://openfaas-figlet:8080"
- "--token-from=/var/inlets/token"
volumeMounts:
- name: inlets-token-volume
mountPath: /var/inlets/
volumes:
- name: inlets-token-volume
secret:
secretName: inlets-token
```

### Access your service

You can now access the service inside the KinD cluster, from the inlets server port and IP.

```sh
curl 192.168.1.51:8090 -d "inlets.dev"
_ _ _ _
(_)_ __ | | ___| |_ ___ __| | _____ __
| | '_ \| |/ _ \ __/ __| / _` |/ _ \ \ / /
| | | | | | __/ |_\__ \| (_| | __/\ V /
|_|_| |_|_|\___|\__|___(_)__,_|\___| \_/
```
You could also use `127.0.0.1:8090` on your local machine.
### Access multiple services
* Now try another service

Run Nginx and expose it:

```
kubectl run static-web --image nginx --port 80
kubectl expose deploy/static-web --port 80 --target-port 80
kubectl expose deploy/static-web --port 8080 --target-port 80
```

Edit the upstream parameter (`kubectl edit deploy/inlets`):
```
- "--upstream=openfaas-figlet.local=http://openfaas-figlet:8080,static-web.local=http://static-web:80"
```
Now setup two hosts file entries in `/etc/hosts`:
```
127.0.0.1 openfaas-figlet.local
127.0.0.1 static-web.local
```sh
inletsctl kfwd --if 192.168.0.14 --from static-web:8080
```

Now access either:
```
curl -d hi http://127.0.0.1:8090 -H "Host: openfaas-figlet.local"
curl http://127.0.0.1:8090 -H "Host: static-web.local"
```
View the site with the URL printed or at `http://127.0.0.1:8080`.

0 comments on commit d63b9f1

Please sign in to comment.
You can’t perform that action at this time.