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 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
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 namedlicense
that contains thelicense.lic
file we provided you. So the relative path would bemosquitto-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 thesedata
directories. We provide1000
ownership to the data directory of mosquitto servers androot
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 of1000
as mosquitto kubernetes pods uses user id of1000
by default androot
to MMC pods.
- Copy or setup the
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
- For Debian AMD64:
- Depending on your host architecture, navigate to the corresponding folder:
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
- 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:
Start Minikube:
On your local node: Start the minikube setup using the
minikube start
command mentioned below.repoPath
: Replace therepoPath
variable with the path where the foldermosquitto-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 therepoPath
would be/root
or if exists on/home/demo/mosquitto-2.8-mmc-2.8-singlenode-kubernetes
then therepoPath
would be/home/demo
.minikube start --mount-string="<repoPath>/mosquitto-2.8-mmc-2.8-singlenode-kubernetes/:/mnt" --mount
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 namedsinglenode
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.
- 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
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:
- Minikube should be up and running. If you are yet to setup the minikube for single-node deployment, refer Kubernetes Setup.
- You have successfully created the namespace and configmap for your license (i.e
mosquitto-license
).
Helm Installation
Change Directory:
- Navigate to the project directory (i.e single-node).
cd mosquitto-2.8-mmc-2.8-singlenode-kubernetes/kubernetes/single-node
- Navigate to the project directory (i.e single-node).
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 thansinglenode
, 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 issample-release-name
,username
,password
andemail
bedemo-username
,demo-password
anddemo@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
- Use the following
You can monitor the running pods using the
kubectl get pods -o wide -n <namespace>
command. To observe the opened ports usekubectl get svc -n <namespace>
.To uninstall the setup:
helm uninstall <release-name> -n <namespace>
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.