# Change EMQX Configurations

# Task target

How to change EMQX configuration by .spec.bootstrapConfig in EMQX Custom Resource.

# Configure EMQX Cluster

The main configuration file of EMQX is emqx.conf. Starting from version 5.0, EMQX adopts HOCON (opens new window) as the configuration file format.

EMQX CRD supports using the .spec.bootstrapConfig field to configure the EMQX cluster. For bootstrapConfig configuration, please refer to the document: bootstrapConfig (opens new window). This field is only allowed to be configured when creating an EMQX cluster and does not support updating.

TIP

This is only applicable before EMQX is started. If you need to modify the cluster configuration after creating EMQX, please modify it through EMQX Dashboard.

For example, to add a TCP listener on port 1884, you can run the commands below:

apiVersion: apps.emqx.io/v2alpha1
kind: EMQX
metadata:
   name: emqx
spec:
   image: emqx:5.0
   imagePullPolicy: IfNotPresent
   bootstrapConfig: |
    listeners.tcp.test {
       bind = "0.0.0.0:1884"
       max_connections = 1024000
     }
   coreTemplate:
     spec:
       replicas: 3
   replicantTemplate:
     spec:
       replicas: 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

In the .spec.bootstrapConfig field, we have configured a TCP listener for the EMQX cluster. The name of this listener is: test, and the listening port is: 1884.

Save the above content as emqx.yaml and execute the following command to deploy the EMQX cluster:

$ kubectl apply -f emqx.yaml

emqx.apps.emqx.io/emqx created
1
2
3

Check the status of the EMQX cluster and make sure that STATUS is Running, which may take some time to wait for the EMQX cluster to be ready.

$ kubectl get emqx emqx

NAME   IMAGE      STATUS    AGE
emqx   emqx:5.0   Running   10m
1
2
3
4

# Verify the Configuration Change

View EMQX cluster listener information

kubectl exec -it emqx-core-0 -c emqx -- emqx_ctl listeners
1

The output is similar to:

tcp:default
   listen_on: 0.0.0.0:1883
   acceptors: 16
   proxy_protocol : false
   running: true
   current_conn: 0
   max_conns : 1024000
tcp:test
   listen_on: 0.0.0.0:1884
   acceptors: 16
   proxy_protocol : false
   running: true
   current_conn: 0
   max_conns : 1024000
1
2
3
4
5
6
7
8
9
10
11
12
13
14

From the output results, we can see that the listener we configured named test has taken effect.