Installing MQTT Server-EMQX with Helm

This article was last updated on: February 7, 2024 pm

EMQX

ℹ️ Info:

use EMQX

Deploy EMQX 4.0 clusters on Kubernetes via Helm3 EMQ

emqx/deploy/charts/emqx at main-v4.4 · emqx/emqx (github.com)

emqx/values.yaml at main-v4.4 · emqx/emqx (github.com)

emqx/emqx-operator: A Kubernetes Operator for EMQ X Broker (github.com)

Configuration Item | EMQX documentation

EMQX installation

ℹ️ Info:

That is, EMQX server side.

1
2
3
4
5
6
7
8
9
10
11
12
> helm repo add emqx https://repos.emqx.io/charts
"emqx" has been added to your repositories
> helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "emqx" chart repository
Update Complete. ⎈Happy Helming!⎈
> helm search repo emqx
NAME CHART VERSION APP VERSION DESCRIPTION
emqx/emqx 4.4.0 4.4.0 A Helm chart for EMQ X
emqx/emqx-ee 4.4.1 4.4.1 A Helm chart for EMQ X
emqx/emqx-operator 1.0.1 1.1.2 A Helm chart for EMQX Operator Controller
emqx/kuiper 0.9.0 0.9.0 A lightweight IoT edge analytic software

Installation:

vi values.yaml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
replicaCount: 1
image:
repository: emqx/emqx
pullPolicy: IfNotPresent

recreatePods: false

podManagementPolicy: Parallel

extraEnv: []

extraEnvFrom: []

extraArgs: []

extraVolumes: []

extraVolumeMounts: []

persistence:
enabled: true
size: 8Gi
storageClass: "local-path"
accessMode: ReadWriteOnce

resources: {}
# limits:
# cpu: 500m
# memory: 512Mi
# requests:
# cpu: 500m
# memory: 512Mi

# Containers that run before the creation of EMQ X containers. They can contain utilities or setup scripts.
initContainers: {}
# - name: mysql-probe
# image: alpine
# command: ["sh", "-c", "for i in $(seq 1 300); do nc -zvw1 mysql 3306 && exit 0 || sleep 3; done; exit 1"]

## EMQ X configuration item, see the documentation (https://hub.docker.com/r/emqx/emqx)
emqxConfig:
EMQX_NAME: "{{ .Release.Name }}"
## Cluster discovery by k8s
EMQX_CLUSTER__DISCOVERY: "k8s"
EMQX_CLUSTER__K8S__APP_NAME: "{{ .Release.Name }}"
EMQX_CLUSTER__K8S__APISERVER: "https://kubernetes.default.svc:443"
EMQX_CLUSTER__K8S__SERVICE_NAME: "{{ .Release.Name }}-headless"
EMQX_CLUSTER__K8S__NAMESPACE: "{{ .Release.Namespace }}"
EMQX_CLUSTER__K8S__ADDRESS_TYPE: "hostname"
EMQX_CLUSTER__K8S__SUFFIX: "svc.cluster.local"

emqxAclConfig: >
{allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
{allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
{deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
{allow, all}.

emqxLoadedPlugins: >
{emqx_management, true}.
{emqx_recon, true}.
{emqx_retainer, true}.
{emqx_dashboard, true}.
{emqx_telemetry, true}.
{emqx_rule_engine, true}.
{emqx_bridge_mqtt, false}.

emqxLoadedModules: >
{emqx_mod_acl_internal, true}.
{emqx_mod_presence, true}.
{emqx_mod_trace, false}.
{emqx_mod_st_statistics, false}.
{emqx_mod_delayed, false}.
{emqx_mod_rewrite, false}.
{emqx_mod_subscription, false}.
{emqx_mod_topic_metrics, false}.

service:
type: LoadBalancer
mqtt: 1883
mqttssl: 8883
mgmt: 8081
ws: 8083
wss: 8084
dashboard: 18083

podSecurityContext:
enabled: true
fsGroup: 1000
fsGroupChangePolicy: Always
runAsUser: 1000
supplementalGroups:
- 1000

containerSecurityContext:
enabled: true
runAsNonRoot: true
runAsUser: 1000
1
helm install emqx emqx/emqx --namespace emqx --create-namespace -f ./values.yaml --wait

Installation output:

1
2
3
4
5
6
NAME: emqx
LAST DEPLOYED: Sat Feb 19 20:48:49 2022
NAMESPACE: emqx
STATUS: deployed
REVISION: 1
TEST SUITE: None

EMQX verification

View the EMQX cluster after installation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# kubectl -n emqx get pods
NAME READY STATUS RESTARTS AGE
svclb-emqx-kbl22 6/6 Running 0 41s
emqx-0 1/1 Running 0 41s

# kubectl -n emqx exec -it emqx-0 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
['[email protected]'],
stopped_nodes => []}

# kubectl -n emqx get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
emqx-headless ClusterIP None <none> 1883/TCP,8883/TCP,8081/TCP,8083/TCP,8084/TCP,18083/TCP,4370/TCP 86s
emqx LoadBalancer 10.43.193.192 10.<none> .245 1883:31558/TCP,8883:31122/TCP,8081:31592/TCP,8083:30322/TCP,8084:31095/TCP,18083:32427/TCP 86s

To access the console:

visit URL:18083, enter the default user name:admin, default password:public, log in to the EMQX dashboard.

image-20220219205441661

MQTT message validation:

Can pass MQTT X: Cross-platform MQTT 5.0 Desktop Client Connect and verify the sending and receiving.

🎉 At this point, the installation of EMQX (that is, MQTT server-side) is completed.

EMQX uninstalls

First uninstall all EMQX resources except storage via Helm:

1
helm uninstall emqx --namespace emqx

Then delete the storage via the Rancher UI or kubectl command:

1
kubectl delete -n emqx pvc emqx-data-emqx-0

EMQX Edge

ℹ️ Info:

That is, the EMQX Edge side version

The resources on the edge side are small, and the storage space can be set to a lower level. As:size: 5Gi

Deploy EMQX Edge cluster designation image.repository=emqx/emqx-edge, other settings are consistent with deploying EMQX clusters

1
2
3
4
5
6
7
8
...
image:
repository: emqx/emqx-edge
...
persistence:
...
size: 8Gi
...

🎉 At this point, the installation of EMQX Edge (that is, MQTT Edge Server) is completed.

EMQX Edge offline installation

Pull the EMQX container image to the corresponding image repository through the operating machine (which can be connected to the Internet or through the proxy):

1
ctr -n k8s.io images push --plain-http --platform=linux/arm64/v8 <local-registry>:5000/emqx/emqx-edge:4.4.0

Then install it normally:

🔥 Tip:

The premise is that the image repository is installed locally, and the local docker or other container runtime has configured a mirror with the local image repository address <docker.io>

1
helm install emqx emqx/emqx --namespace emqx --create-namespace -f ./values.yaml --wait

🎉 At this point, the offline installation of EMQX Edge (that is, MQTT Edge Server) has been completed.

summary

MQTT

  1. MQTT Server is installed through Helm Chart EMQX and is installed on the server/edge side of K3S emqx namespace;
    1. Installation mode: Single node
    2. EMQX version: 4.4.0
    3. EMQX instance: 1
    4. EMQX data is persisted, and container data is located at:/opt/emqx/data/mnesia, the persisted data is located at:/data/rancher/k3s/storage
  2. EMQX UI is:<locabalaner-ip>:18083, the account password defaults:admin and public
  3. The MQTT address is:<locabalaner-ip>:1883

Installing MQTT Server-EMQX with Helm
https://e-whisper.com/posts/50528/
Author
east4ming
Posted on
February 20, 2022
Licensed under