Skip to main content
Version: Mosquitto 2.8

Single Node

To set up a single Mosquitto broker and Management Center using Helm charts, you'll first need a Kubernetes environment. For deploying kubernetes on a single host, Minikube is an excellent choice. Minikube is a lightweight Kubernetes distribution designed for local development and testing (Discussed in Introduction section).

Single node setup would deploy a single Mosquitto broker and a Management-Center pod as a deployment entity.

Recommended Setup

  1. 1 MMC and 1 Mosquitto Broker (single host)

Kubernetes Setup

If you need to set up a Kubernetes setup, you can use our installation script. The installation script installs minikube . You can also install the dependencies on your own as well. The dependencies are given below:

Dependencies and Prerequisites:

  • Docker
  • Minikube
  • Helm
  1. Setup the folder on your local machine:

    • Copy or setup the mosquitto-2.8-mmc-2.8-singlenode-kubernetes repository to your local machine. Also make sure to create a directory inside the repository named license that contains the license.lic file we provided you. So the relative path would be mosquitto-2.8-mmc-2.8-singlenode-kubernetes/license/license.lic.
    • Make sure all the data directories have adequate privileges so that mosquitto kubernetes pods can create additional directories inside these data directories. We provide 1000 ownership to the data directory of mosquitto servers and root ownership to config of management-center. The same ownership are also the default ownership of mosquitto pods and MMC pods.
      • sudo chown -R 1000:1000 /home/<user>/mosquitto-2.8-mmc-2.8-singlenode-kubernetes/mosquitto/data
      • sudo chown -R root:root /home/<user>/mosquitto-2.8-mmc-2.8-singlenode-kubernetes/management-center/config
    • Note: We provide ownership of 1000 as mosquitto kubernetes pods uses user id of 1000 by default and root to MMC pods.
  2. Choose Architecture Folder:

    • Depending on your host architecture, navigate to the corresponding folder:
      • For Debian AMD64:
        cd mosquitto-2.8-mmc-2.8-singlenode-kubernetes/kubernetes/single-node/debian_amd64
      • For Ubuntu AMD64:
        cd mosquitto-2.8-mmc-2.8-singlenode-kubernetes/kubernetes/single-node/ubuntu_amd64
  3. Install Pre-requisites:

    • Run the following command to install the necessary dependencies on the host. This script installs the dependencies like docker, minikube and helm. You can also install the dependencies separately on your own as well. To run the script use the following command:
      bash  install-dependencies.sh
  4. Start Minikube:

    • On your local node: Start the minikube setup using the minikube start command mentioned below.

    • repoPath: Replace the repoPath variable with the path where the folder mosquitto-2.8-mmc-2.8-singlenode-kubernetes resides on your local. For eg if it exists on /root/mosquitto-2.8-mmc-2.8-singlenode-kubernetes therefore the repoPath would be /root or if exists on /home/demo/mosquitto-2.8-mmc-2.8-singlenode-kubernetes then the repoPath would be /home/demo.

      minikube start --mount-string="<repoPath>/mosquitto-2.8-mmc-2.8-singlenode-kubernetes/:/mnt" --mount

  5. Create a namespace

    • On your local node: Create a namespace in which you would want to deploy the application. The deployment folder is pre-configured for the namespace named singlenode. If you want to use the default configuration you can create a namespace named singlenode using the below command:
    • kubectl create namespace singlenode
    • If you want to use a different namespace, use the command: kubectl create namespace <your-custom-namespace>. Replace <your-custom-namespace> with the name of the namespace you want to configure.
  6. Create configmap for your license

    • On your local node: Create a configmap for your license key. You can create the configmap using the following command:
    • kubectl create configmap mosquitto-license -n <namespace> --from-file=<path-to-your-license-file>
    • Make sure the name of the configmap remains the same as mosquitto-license as this is required by the deployment files and statefulsets.
    • A sample configmap creation command would look something like this if the choosen namespace is singlenode and the license file is at the path /home/<user>/mosquitto-2.8-mmc-2.8-singlenode-kubernetes/license/license.lic :
      • kubectl create configmap mosquitto-license -n singlenode --from-file=/home/<user>/mosquitto-2.8-mmc-2.8-singlenode-kubernetes/license/license.lic

Installation

Prerequisites:

  1. Minikube should be up and running. If you are yet to setup the minikube for single-node deployment, refer Kubernetes Setup.
  2. You have successfully created the namespace and configmap for your license (i.e mosquitto-license).

Helm Installation

  1. Change Directory:

    • Navigate to the project directory (i.e single-node). cd mosquitto-2.8-mmc-2.8-singlenode-kubernetes/kubernetes/single-node
  2. Install Helm Chart:

    • Use the following helm install command to deploy the setup to your Kubernetes cluster. Replace <release-name> with the desired name for your Helm release and <namespace> with your chosen Kubernetes namespace:
      helm install <release-name> mosquitto-single-node-0.1.0.tgz   -n <namespace> --set imageCredentials.registry=registry.cedalo.com --set imageCredentials.username=<username> --set imageCredentials.password=<password> --set imageCredentials.email=<email>
    • namespace: Set it to the namespace of your deployment.
    • Note: If you want to deploy the setup in a different namespace other than singlenode, make sure to pass a separate flag --set namespace=<your-custom-namespace> along with the helm installation command.
    • imageCredentials.username: Your docker username provided by Cedalo team.
    • imageCredentials.password: Your docker password provided by Cedalo team.
    • imageCredentials.email: Registered e-mail for accessing docker registry.
    • Sample example: If your name namespace is test-namespace and your arbitrary release name is sample-release-name, username, password and email be demo-username, demo-password and demo@gmail.com then your helm installation command should be:
             helm install sample-release-name  mosquitto-single-node-0.1.0.tgz  -n test-namespace --set namespace=test-namespace --set imageCredentials.registry=registry.cedalo.com --set imageCredentials.username=demo-username --set imageCredentials.password=demo-password --set imageCredentials.email=demo@gmail.com
  3. You can monitor the running pods using the kubectl get pods -o wide -n <namespace> command. To observe the opened ports use kubectl get svc -n <namespace>.

  4. To uninstall the setup: helm uninstall <release-name> -n <namespace>

  5. To delete the minikube setup and delete all config: minikube stop && minikube delete

Your Mosquitto setup is now running with a single mosquitto nodes and the Management Center.

Open Applications: MMC

  • kubectl get nodes -o wide
  • Get the node ip from the above command. This would not same as your host IP as Minikube setups a hypervisor between your host and Kubernetes pods.Usually the IP of minikube is 192.168.49.2, however it is always better to confirm using kubectl get nodes -o wide command.
  • http://<"node-ip">:31021 (Open on your browser )
  • Note: If MMC is not loading then you can following command: minikube service mmc -n <namespace>

Connect to the Mosquitto

  • minikube service mosquitto -n <namespace>
  • To subscribe to SYS topics: mosquitto_sub -h <minikube-node-ip> -p 31028 -u <username> -P <password> -t '$SYS/#'

Further Useful Commands:

  • If you want to change mosquitto.conf, you can do so by uncompressing the helm chart, making the required changes and packaging the helm charts again. The detailed procedure is mentioned below:
    • tar -xzvf mosquitto-single-node-0.1.0.tgz
      • cd mosquitto-single-node/files/
      • Make changes to mosquitto.conf and save it.
      • Go back to the parent directory: cd ../
      • Package the helm chart to its original form using: helm package mosquitto-single-node
      • Uninstall helm package helm uninstall <release-name> -n <namespace>
    • Reinstall the helm package using the same command you used the first time from the mosquitto-2.8-mmc-2.8-singlenode-kubernetes/kubernetes/single-node/ directory.

Usage

Once the installation is complete, you can start using the single-node Mosquitto broker. Be sure to check the Mosquitto documentation for further details on configuring and using the broker.