# Edge deployment on Kubernetes ⏱️ **Time:** installation within 35min 💻 **Environment:** tested on Kubernetes `1.28`, `1.29`, `1.30` and `1.31` [``](https://github.com/kerberos-io/deployment/actions/workflows/kind.yaml) --- Kubernetes is an open-source platform for automating the deployment, scaling, and management of containerized applications. It provides features like automated deployment, self-healing, service discovery, and storage orchestration. Kubernetes is essential for modern cloud-native application development and operations. In this tutorial, we will guide you through the installation of the Kerberos.io edge stack, which includes the Agent, Kerberos Vault, and the Data Filtering Service. This setup enables the storage of recordings from multiple cameras at the edge, facilitating local data processing and ensuring secure and efficient management of video streams. ## Install Kubernetes on Ubuntu with kubeadm Kubernetes can be installed on various Linux distributions. This tutorial specifically focuses on the installation process for Ubuntu using the `kubeadm` method. For the most up-to-date installation guide, we recommend referring to [the official Kubernetes documentation](https://kubernetes.io/docs/setup/production-environment/) and [`kubeadm` documentation](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/). Let's prepare the system and install the relevant packages. ```bash apt-get update -y apt-get install -y apt-transport-https ca-certificates curl gpg curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list apt-get update apt-get install -y kubelet kubeadm kubectl apt-mark hold kubelet kubeadm kubectl systemctl enable --now kubelet ``` Enable ip forwarding. ```bash # sysctl params required by setup, params persist across reboots cat < value: "yourmongodbpassword" ``` Create the `kerberos-vault` namespace. ```bash kubectl create namespace kerberos-vault ``` Apply the manifests, so the Kerberos Vault application is deployed and knows how to connect to the MongoDB. ```bash kubectl apply -f ./mongodb-configmap.yaml -n kerberos-vault kubectl apply -f ./kerberos-vault-deployment.yaml -n kerberos-vault kubectl apply -f ./kerberos-vault-service.yaml -n kerberos-vault ``` Verify if the pod is running ```bash kubectl get po -w -A ``` #### Access the UI If you have opted for the `NodePort` configuration, you can access the Kerberos Vault via the `http://localhost:30080` endpoint in your browser. For server installations without a GUI, consider setting up a reverse proxy to enable browser access from your local machine. Alternatively, you may utilize a `LoadBalancer` if one is available or if you are deploying on a managed Kubernetes service. ```bash ssh -L 8080:localhost:30080 user@server-ip -p 22 ``` #### Configure the Kerberos Vault With the Kerberos Vault installed, we can proceed to configure the various components. Currently, this must be done through the Kerberos Vault UI, but we plan to make it configurable via environment variables, eliminating the need for manual UI configurations. ![Configure Vault](./assets/images/configure-vault.gif) - Navigate to the `Storage Providers` menu and select the (+ Add Storage Provider) button. A modal will appear where you can input the required details. After entering the information, click the "Verify" button to ensure the configuration is valid. Once you receive a "Configuration is valid and working" message, click the "Add Storage Provider" button to complete the process. - Minio - Enabled: true - Provider name: minio - Bucket name: mybucket - Region: na - Hostname: myminio-hl.minio-tenant:9000 - Access key: minio - Secret key: minio123 - Navigate to the `Integrations` menu and select the (+ Add Integration) button. A modal will appear where you can input the required details. After entering the information, click the "Verify" button to ensure the configuration is valid. Once you receive a "Configuration is valid and working" message, click the "Add Integration" button to complete the process. - RabbitMQ - Enabled: true - Integration name: rabbitmq - Broker: rabbitmq.rabbitmq:5672 - Exchange: `` - Queue: data-filtering - Username: yourusername - Password: yourpassword - Navigate to the `Accounts` menu and click the (+ Add Account) button. A modal will appear where you can input the required details. After entering the information, click the "Add Account" button to complete the process. - Enabled: true - Account name: myaccount - Main provider: minio - Day limit: 30 - Integration: rabbitmq - Directory: \* - Access key: XJoi2@bgSOvOYBy# (or generate new keys, but don't forget to update them in the next steps) - Secret key: OGGqat4lXRpL@9XBYc8FUaId@5 (or generate new keys, but don't forget to update them in the next steps) ### Create an Agent After deploying the Kerberos Vault and configuring the necessary services for storage, database, and integration, you can proceed to deploy the Agent with the appropriate configuration. Review the `kerberos-agent-deployment.yaml` file and adjust the relevant settings, such as the RTSP URL, to ensure proper functionality. As mentioned below note that you can opt for the [Factory](https://github.com/kerberos-io/factory/tree/master/kubernetes) which gives you a UI to manage the creation of Agents. **_(Please note if you generated new the keys in the previous Kerberos Vault account creation, you need to update those in the Agent deployment)_** ```bash kubectl apply -f kerberos-agent-deployment.yaml ``` Review the creation of the Agent and review the logs of the container to validate the Agent is able to connect to the IP camera, and if a recording is being created and transferred to the Kerberos Vault ```bash kubectl get po -w -A kubectl logs -f kerberos-agent... ``` To validate the Kerberos Vault and review any stored recordings, access the user interface at `http://localhost:30080` (after establishing the reverse tunnel). ### Create Agents through Factory Managing Agents through seperate configuration files might feel cumbersome, especially for non-technical users. This is where Factory comes into the picture. Factory provides a visual view that allows you to rapidly connect cameras through a user interface, which allows users without any technical background about cameras and kubernetes create Agents. Factory also requires a mongodb, just like Kerberos Vault. Luckily you can reuse the mongodb installation we have deployed earlier, the only thing we'll need to do is to create another `configmap.yaml` in the `kerberos-factory` namespace. Create the `kerberos-factory` namespace. ```bash kubectl create namespace kerberos-factory ``` Apply the manifests, so the Factory application is deployed and knows how to connect to the MongoDB. ```bash kubectl apply -f ./mongodb-configmap.yaml -n kerberos-factory kubectl apply -f ./kerberos-factory-deployment.yaml -n kerberos-factory kubectl apply -f ./kerberos-factory-service.yaml -n kerberos-factory ``` To allow our Factory to create Kubernetes resources we will need to apply an additional cluster role. This will allow our Factory deployment to read and write resources to our Kubernetes cluster. ```bash kubectl apply -f ./kerberos-factory-clusterrole.yaml -n kerberos-factory ``` Verify if the pod is running ```bash kubectl get po -w -A ``` ### Optimized Data Filtering for Enhanced Bandwidth Efficiency and Relevance Once your Agents are properly connected and all recordings are stored in the Kerberos Vault, you may encounter additional challenges such as bandwidth limitations, storage constraints, and the need to efficiently locate relevant data. To accomplish this, we can configure an integration to filter the recordings, ensuring that only the relevant ones are retained. Assuming all configurations are correctly set and all Kubernetes deployments are operational, you can apply the `data-filtering-deployment.yaml` deployment. This deployment will schedule a pod that listens to the configured integration in Kerberos Vault and runs a YOLOv8 model to evaluate the recordings and match them against specified conditions. Please note that if you do not have a GPU on the device, you will need to disable the resource limit of the nvidia/gpu. Once done the filtering will run on the CPU. ```bash sed -e '/resources/ s/^#*/#/' -i ./data-filtering-deployment.yaml sed -e '/limits/ s/^#*/#/' -i ./data-filtering-deployment.yaml sed -e '/nvidia/ s/^#*/#/' -i ./data-filtering-deployment.yaml ``` Let's deploy the data filtering pod (with or without GPU support). ```bash kubectl apply -f data-filtering-deployment.yaml ``` Each time a recording is stored in the Kerberos Vault, the `data-filtering` pod will receive a notification and execute the specified model (YOLOv8 by default). Based on the defined conditions, the `data-filtering` pod may forward the recording to a remote Kerberos Vault, trigger alerts, or send notifications. Ensure that the `data-filtering` workload is actively running, receiving messages from the integration, and performing the necessary processing tasks. ```bash kubectl get po -w -A kubectl logs -f data... ``` You might see something like below, whereas the `data-filtering` pod is iterating over recordings and frames, looking for a person. Once it finds the person it will try to `forward` the recording to a remote Kerberos Vault. ```bash Persons: 0, Cars: 0, Trucks: 0 Condition not met, not forwarding video to remote vault Persons: 0, Cars: 0, Trucks: 0 Condition not met, not forwarding video to remote vault Persons: 1, Cars: 0, Trucks: 0 Condition met, forwarding video to remote vault Condition met, stopping the video loop, and forwarding video to remote vault Something went wrong while forwarding media Delete media from http://vault-lb.kerberos-vault/api - Classification took: 22.4 seconds, @ 3 fps. - 0.15s for preprocessing and initialisation - 22.25s for processing of which: - 0.99s for class prediction - 21.26s for other processing - 0s for postprocessing - Original video: 31.5 seconds, @ 30.0 fps @ 1920x1080. File size of 2.1 MB 8) Releasing video writer and closing video capture ``` As indicated by the logs `Something went wrong while forwarding media`, the forwarding process failed due to the absence of an integration between the two `Kerberos Vaults`. Currently, only one `Kerberos Vault` is available. To enable this feature, you will need to [install a second `Kerberos Vault` in the cloud](./README.k8s-managed.md) with access to cloud storage. ### Add forwarding integration If you have setup a secondary Kerberos Vault in the cloud, attached cloud Object storage to it, we can continue and add an additional integration through the UI. ```bash ssh -L 8080:localhost:30080 user@server-ip -p 22 ``` Navigate to the `Kerberos Vault` application in your browser, access the `Integration` section, and add a new integration. This integration will connect your local Kerberos Vault to the remote Kerberos Vault, and will tell the system to set recordings in a `forwarding state`. - Add an integration - Kerberos Vault - Enabled: true - Integration name: remote-vault - Forwarding mode: continuous - Url: http(s)://yourvault.com/api - Provider: The name of the remote storage provider - Access Key: The access key of the account you have created on the remote Kerberos Vault - Secret Access Key: The secret access key of the account you have created on the remote Kerberos Vault If the integration is functioning correctly, you should observe that recordings are initially marked in gray as "To be forwarded." After a short period, some recordings will be updated to green, indicating they have been "Forwarded by." ## Cleanup If you consider to remove the Kerberos.io stack you might just disable the microk8s installation ```bash microk8s reset sudo snap remove microk8s ``` or if you want to keep the microk8s installation you can also delete the individual deployments. ```bash kubectl delete -f data-filtering-deployment.yaml kubectl delete -f kerberos-agent-deployment.yaml kubectl delete -f ./kerberos-vault-deployment.yaml -n kerberos-vault kubectl delete -f ./mongodb-config.yaml -n kerberos-vault helm del rabbitmq -n rabbitmq helm del mongodb -n mongodb git clone --depth 1 --branch v6.0.1 https://github.com/minio/operator.git && kubectl delete -k operator/ ``` You can confirm all the workloads were removed from your system. ```bash kubectl get po -w -A ```