Skip to content

Microservice and Kubernetes based IoT control center. Uses the power of docker, flask, and raspberry pis to provide an IoT control interface.

Notifications You must be signed in to change notification settings

patterson-project/icc-services

Repository files navigation

Iot Control Center

A local area network kubernetes cluster for managing and controlling IoT devices.

Installation

1. Flash an SD card with Ubuntu Server OS Arm64 Architecture

  • 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

2. Boot up the Raspberry Pi and SSH into it

3. Docker and docker-compose Installation

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

5. Install Kubernetes

  • Rancher Docs
    • Default installation can be done with the following command:
      • curl -sfL https://get.k3s.io | sh -
  • 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"

6. Set up your environment variables

  • There are 4 environment variables needed for the build script to work:

    1. MONGO_DB_USERNAME
      • Your chosen database username
    2. MONGO_DB_PASSWORD
      • Your chosen database password
    3. MONGO_DB_IP
      • The IP address of the raspberry pi (which hosts the database)
      • This IP address can be found by running ifconfig
    4. 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>"

7. Clone this Repository

8. Build and push the local docker containers to dockerhub

  • 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

9. Configure your cluster secrets

  • Copy the secrets.yaml found under /Kubernetes/Secrets. Rename it to secrets.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

10. Deploy the Mongo Database

  • 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

11. Deploy the cluster

  • 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!

About

Microservice and Kubernetes based IoT control center. Uses the power of docker, flask, and raspberry pis to provide an IoT control interface.

Topics

Resources

Stars

Watchers

Forks