EMQX CRD supports using .spec.dashboardServiceTemplate to configure EMQX cluster Dashboard Service, using .spec.listenersServiceTemplate to configure EMQX cluster listener Service, its documentation can refer to: Service(opens new window).
NOTE: By default, EMQX will open an MQTT TCP listener tcp-default corresponding to port 1883 and Dashboard listener dashboard-listeners-http-bind corresponding to port 18083. Users can add new listeners through .spec.bootstrapConfig field or EMQX Dashboard. EMQX Operator will automatically inject the default listener information into the Service when creating the Service, but when there is a conflict between the Service configured by the user and the listener configured by EMQX (name or port fields are repeated), EMQX Operator will use the user's configuration prevail.
The corresponding CRD of EMQX Enterprise Edition in EMQX Operator is EmqxEnterprise, and EmqxEnterprise supports configuring EMQX cluster Service through .spec.serviceTemplate field. For the specific description of the serviceTemplate field, please refer to: serviceTemplate(opens new window).
NOTE: EMQX will open 6 listeners by default, namely: mqtt-ssl-8883 corresponds to port 8883, mqtt-tcp-1883 corresponds to port 1883, http-dashboard-18083 corresponds to port 18083, http-management-8081 corresponds to port 8081,mqtt-ws-8083 corresponds to port 8083 and mqtt-wss-8084 corresponds to port 8084. EMQX Operator will automatically inject the default listener information into the Service when creating the Service, but when there is a conflict between the Service configured by the user and the listener configured by EMQX (the name or port field is repeated), EMQX Operator will use the user's configuration prevail.
The corresponding CRD of EMQX Enterprise Edition in EMQX Operator is EmqxEnterprise, and EmqxEnterprise supports configuration of cluster Service through .spec.emqxTemplate.serviceTemplate field. The description of the serviceTemplate field can refer to the document: serviceTemplate(opens new window)
NOTE: EMQX will open 6 listeners by default, namely: mqtt-ssl-8883 corresponds to port 8883, mqtt-tcp-1883 corresponds to port 1883, http-dashboard-18083 corresponds to port 18083, http-management-8081 corresponds to port 8081, mqtt-ws-8083 corresponds to port 8083 and mqtt-wss-8084 corresponds to port 8084. EMQX Operator will automatically inject the default listener information into the Service when creating the Service, but when there is a conflict between the Service configured by the user and the listener configured by EMQX (the name or port field is repeated), EMQX Operator will use the user's configuration prevail.
Save the above content as: emqx-service.yaml, and execute the following command to deploy the EMQX cluster:
kubectl apply -f emqx-service.yaml
1
The output is similar to:
emqx.apps.emqx.io/emqx created
1
Check whether the EMQX cluster is ready
kubectl get emqx emqx -o json | jq ".status.emqxNodes"
NOTE: node represents the unique identifier of the EMQX node in the cluster. node_status indicates the status of EMQX nodes. otp_release indicates the version of Erlang used by EMQX. role represents the EMQX node role type. version indicates the EMQX version. EMQX Operator creates an EMQX cluster with three core nodes and three replicant nodes by default, so when the cluster is running normally, you can see information about three running core nodes and three replicant nodes. If you configure the .spec.coreTemplate.spec.replicas field, when the cluster is running normally, the number of running core nodes displayed in the output should be equal to the value of this replicas. If you configure the .spec.replicantTemplate.spec.replicas field, when the cluster is running normally, the number of running replicant nodes displayed in the output should be equal to the replicas value.
kubectl get emqxenterprise emqx-ee -o json | jq ".status.emqxNodes"
NOTE: node represents the unique identifier of the EMQX node in the cluster. node_status indicates the status of EMQX nodes. otp_release indicates the version of Erlang used by EMQX. version indicates the EMQX version. EMQX Operator will pull up the EMQX cluster with three nodes by default, so when the cluster is running normally, you can see the information of the three running nodes. If you configure the .spec.replicas field, when the cluster is running normally, the number of running nodes displayed in the output should be equal to the value of replicas.
kubectl get emqxenterprise emqx-ee -o json | jq ".status.emqxNodes"
NOTE: node represents the unique identifier of the EMQX node in the cluster. node_status indicates the status of EMQX nodes. otp_release indicates the version of Erlang used by EMQX. version indicates the EMQX version. EMQX Operator will pull up the EMQX cluster with three nodes by default, so when the cluster is running normally, you can see the information of the three running nodes. If you configure the .spec.replicas field, when the cluster is running normally, the number of running nodes displayed in the output should be equal to the value of replicas.
Use the command line to view the EMQX cluster Service
kubectl get svc -l apps.emqx.io/instance=emqx
1
The output is similar to:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
emqx-dashboard NodePort 10.101.225.238 <none> 18083:32012/TCP 32s
emqx-listeners NodePort 10.97.59.150 <none> 1883:32010/TCP,14567:32011/UDP 10s
1 2 3
Use MQTT X to connect to the EMQX cluster to send messages
Click the button to create a new connection on the MQTT X page, and configure the EMQX cluster node information as shown in the figure. After configuring the connection information, click the connect button to connect to the EMQX cluster:
Then click the Subscribe button to create a new subscription, as shown in the figure, MQTT X has successfully connected to the EMQX cluster and successfully created the subscription:
After successfully connecting to the EMQX cluster and creating a subscription, we can send messages to the EMQX cluster, as shown in the following figure:
Add new listeners through EMQX Dashboard
Open the browser, enter the host IP and port 32012 where the EMQX Pod is located, log in to the EMQX cluster Dashboard (Dashboard default user name: admin, default password: public), enter the Dashboard and click Configuration → Listeners to enter the listener page, We first click the Add Listener button to add a listener named test and port 1884, as shown in the figure below:
Then click the Add button to create the listener, as shown in the following figure:
As can be seen from the figure, the test listener we created has taken effect.
Check whether the newly added listener is injected into the Service
kubectl get svc -l apps.emqx.io/instance=emqx
1
The output is similar to:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
emqx-dashboard NodePort 10.105.110.235 <none> 18083:32012/TCP 13m
emqx-listeners NodePort 10.106.1.58 <none> 1883:32010/TCP,14567:32011/UDP,1884:30763/TCP 12m
1 2 3
From the output results, we can see that the newly added listener 1884 has been injected into the emqx-listeners Service.