A local area network kubernetes cluster for managing and controlling IoT devices.
- Raspberry Pi Imager
- Connect the Pi to your network
- Can be configured from Raspberry Pi Imager in options
- Alternatively this can be done manually by editing the
/etc/netplan/50-cloud-init.yaml
found in Ubuntu- Remember to
netplan apply
- Remember to
4. Login to a dockerhub account
- If you do not already have a dockerhub account, create one since it is needed
- Log in with the
sudo docker login
command - In the dockerhub portal, create a project called
iot-control-center
- Rancher Docs
- Default installation can be done with the following command:
curl -sfL https://get.k3s.io | sh -
- Default installation can be done with the following command:
- Enable cgroups
- Install linux-modules-extra-raspi with:
sudo apt install linux-modules-extra-raspi
- Configure DNS
- Use a text editor to add the following to
/etc/resolv.conf
:
namespace 8.8.8.8 namespace 8.8.4.4
- Then, restart daemon and docker systemctl services
sudo systemctl daemon-reload sudo systemctl restart docker
- Purge the DNS pod in the
kube-system
namespace- Get the DNS pod name with
kubectl get pods --all-namespaces
, e.g.coredns-b96499967-ggsj5
- Delete it
kubectl delete pods coredns-b96499967-ggsj5 --namespace="kube-system"
- Get the DNS pod name with
- Use a text editor to add the following to
-
There are 4 environment variables needed for the build script to work:
MONGO_DB_USERNAME
- Your chosen database username
MONGO_DB_PASSWORD
- Your chosen database password
MONGO_DB_IP
- The IP address of the raspberry pi (which hosts the database)
- This IP address can be found by running
ifconfig
DOCKERHUB_USERNAME
- The username of the dockerhub account logged into in step 4
-
These environment variables can be set by appending the following to your
/etc/environment
file:MONGO_DB_USERNAME="<your chosen database username>" MONGO_DB_PASSWORD="<your chosen database password>" MONGO_DB_IP="<the IP of the pi>" DOCKERHUB_USERNAME="<your dockerhub username>"
cd
into the/Kubernetes
folder of this repo- Execute the
update_cluster.sh
script to build and push all containers with sudo permissions- This may take quite some time on the first go. Depending on your RPi specs, could take anywhere from 5-20 minutes
- Copy the
secrets.yaml
found under/Kubernetes/Secrets
. Rename it tosecrets.yaml
or another name of your choosing - Edit the file with a text editor to add the secrets. You'll need to add:
- A Mongo Database Username and Password
- The address of the Mongo Database (i.e. the address of the current Raspberry Pi. This can be found using
ifconfig
)
- Apply the secrets to your cluster using
kubernetes apply -f secrets.yaml
- Build and bring up the docker container for the database
cd
into/MongoDb
- Run
sudo docker compose up --build -d
- To validate, visit the IP address at port 8081 to validate the mongo express UI appears
- e.g.
http://10.0.0.4:8081
- e.g.
cd
into/Kubernetes
- Run
deploy_cluster.sh
to deploy the cluster - Check your device IP from anywhere on your LAN, you should see the IoT Control Center Home page!