Packet Labs IoT workshop
This workshop deploys compute, storage, networking, and an IoT application to Packet.com.
Conceptual architecture
Diagram:
Private components:
- Kubernetes - provisioned with Terraform
- TLS termination - via cert-manager
- MQTT Connector - openfaas-incubator/mqtt-connector
- Database/storage - Postgresql
- Docker registry - deployed externally, i.e. the Docker Hub.
Components exposed with TLS / Ingress or NodePort:
- Ingress Controller - Traefik v1 (HostPort 80/443)
- Serverless compute platform - OpenFaaS
- MQTT Broker - emitter.io (NodePort) - 30080/30443
- Business intelligence - Metabase (Ingress/TLS)
- Metrics visualization - Grafana (Ingress/TLS)
Getting started
Before you begin using this repo you will need a Packet account.
Everything else you need to deploy this workshop is available in this repository.
Note: This repository is designed to be used with your own domain name and a number of DNS records. This enables TLS termination (HTTPS) to be used for exposed services. If you are working in development, you can skip the domain and TLS steps.
You can register for a domain at Google Domains or Namecheap.com for a few dollars. You can also configure your domain there, after purchase.
1) Clone the repo
git clone https://github.com/packet-labs/iot
2) Create a bare-metal Kubernetes cluster
You will need to install Terraform for this step.
-
Set your Packet API and project ID in a terraform.tfvar file in
/k8s
. -
Enter the
k8s
folder and apply the terraform plan. -
Find the IP of one of the nodes in the cluster from your Packet dashboard or the state file in /k8s/
Create four DNS A records (replace example.com
with your domain):
- A
gateway.example.com
- IP - A
grafana.example.com
- IP - A
metabase.example.com
- IP - A
emitter.example.com
- IP
Some commands will be run from your laptop, so make sure you install Kubectl
3) Install Postgres via KubeDB and helm
You will need to install helm for this step.
- Install postgresql
4) Install OpenFaaS
-
Install openfaas to provide compute and events
-
Deploy the OpenFaaS services for the application
You will also deploy the schema.sql at this time for drone_position
and drone_event
.
65 TLS for OpenFaaS
-
Install cert-manager
k3sup app install cert-manager
-
Install an Ingress record for your OpenFaaS gateway
k3sup app install openfaas-ingress \ --domain gateway.example.com \ --email openfaas@example.com \ --ingress-class traefik
-
Add TLS for Grafana
Edit
./openfaas/grafana-ingress.yaml
and editgrafana.example.com
replacingexample.com
with your domain.Now run:
kubectl apply -f ./openfaas/grafana-ingress.yaml
6) Add the MQTT Broker (Emitter.io)
- Install emitter
7) Add the OpenFaaS MQTT-Connector
The MQTT-Connector is used to trigger functions and services in response to messages generated by the event source. It runs inside the Kubernetes cluster and is private with no ingress.
- Install OpenFaaS MQTT-Connector
8) Add Grafana for function/service visualization
Grafana packages a pre-compiled dashboard for OpenFaaS to show metrics like throughput and latency.
9) Send Drone Data
You can now send data to emitter from your drone clients. Use the drone simulator to generate realistic data for use with visualization tools.