KinD with inlets.dev
Expose Kubernetes ClusterIP services with inlets.dev
# Linux
sudo curl -Lo /usr/local/bin/kind \
https://github.com/kubernetes-sigs/kind/releases/download/v0.4.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
Create the cluster
kind create cluster
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
We'll deploy a HTTP server that runs the figlet
binary to generate ASCII logos
- Define a service
apiVersion: v1
kind: Service
metadata:
name: openfaas-figlet
labels:
app: openfaas-figlet
spec:
type: ClusterIP
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
app: openfaas-figlet
Define a Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: openfaas-figlet
labels:
app: openfaas-figlet
spec:
replicas: 1
selector:
matchLabels:
app: openfaas-figlet
template:
metadata:
labels:
app: openfaas-figlet
spec:
containers:
- name: openfaas-figlet
image: functions/figlet:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
protocol: TCP
Save both files and create the objects with kubectl create -f
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
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.
Create a secret for the inlets client:
export TOKEN="" # Use the value from earlier
kubectl create secret generic inlets-token --from-literal token=${TOKEN}
Apply the Deployment YAML file, with kubectl apply -f
.
Change the following two parameters:
Use your laptop's IP in place of REMOTE-IP
:
- "--remote=ws://REMOTE-IP"
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:
- "--upstream=http://openfaas-figlet.default:8080"
This is the sample 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
You can now access the service inside the KinD cluster, from the inlets server port and IP.
curl 192.168.1.51:8090 -d "inlets.dev"
_ _ _ _
(_)_ __ | | ___| |_ ___ __| | _____ __
| | '_ \| |/ _ \ __/ __| / _` |/ _ \ \ / /
| | | | | | __/ |_\__ \| (_| | __/\ V /
|_|_| |_|_|\___|\__|___(_)__,_|\___| \_/
You could also use 127.0.0.1:8090
on your local machine.
Run Nginx and expose it:
kubectl run static-web --image nginx --port 80
kubectl expose deploy/static-web --port 80 --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
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"