Skip to content
/ m7o Public

Kubernetes Operator to deploy MQTT broker Mosquitto

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

elmarx/m7o

Repository files navigation

m7o — mosquitto mqtt operator for Kubernetes

An operator to deploy and manage mosquitto mqtt broker.

Features

  • MosquittoBroker CRD to deploy broker
  • MosquittoUser to create users (and store credentials to specified secret)
  • MosquittoAcl to control access
  • MosquittoBridge to mirror topics from/to other brokers

Installation

helm install --create-namespace --namespace m7o m7o oci://ghcr.io/elmarx/charts/m7o

Usage

Define a MosquittoBroker resource:

apiVersion: m7o.athmer.cloud/v1alpha1
kind: MqttBroker
metadata:
  name: homassistant
  namespace: my-namespace
spec:
  desc: "Home Assistant Broker"
  service:
    type: LoadBalancer

define user(s) for the broker:

apiVersion: m7o.athmer.cloud/v1alpha1
kind: MqttUser
metadata:
  name: my-user
  namespace: my-namespace
spec:
  brokerRef:
    name: homassistant
  username: my-user

use the generated password

Find the user's credentials in secret $BROKER_NAME-$USERNAME (e.g. "homassistant-my-user")

Development

Local testing with minikube

minikube start
# generate and install CRDs
cargo run --bin crdgen | kubectl --context {{ context }} apply -f -
# install sample broker
kubectl apply -f examples/manifests
# run m7o operator
cargo run
# make minikube loadbalancers available
minikube tunnel 
# get the broker's external IP
IP=$(kubectl get svc mosquitto -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
# get the generated password
PASSWORD=$(kubectl get secrets mosquitto-elmar -o jsonpath="{.data.password}" | base64 -d)  
# sub to a topic
mosquitto_sub -h $IP -u elmar -P $PASSWORD -t "m7o"
# publish a message
mosquitto_pub -h $IP -u elmar -P $PASSWORD -t "m7o" -m "Hello, m7o!"

Debugging

Check if CRD/sample is installed

kubectl get crd mqttbrokers.m7o.athmer.cloud
kubectl get mqttbrokers -n default

Check if the Controller/service-account/current user has permissions

kubectl auth can-i list mqttbrokers.m7o.athmer.cloud
kubectl auth can-i watch mqttbrokers.m7o.athmer.cloud

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Kubernetes Operator to deploy MQTT broker Mosquitto

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages