Skip to content

Change EMQX Configuration

Objective

Change the EMQX configuration using the .spec.config.data field in the EMQX Custom Resource.

Configure EMQX Cluster

The EMQX CRD apps.emqx.io/v2beta1 supports configuring the EMQX cluster through the .spec.config.data field. Refer to the Configuration Manual for the complete configuration reference.

EMQX uses HOCON as the configuration file format.

  1. Save the following as a YAML file and deploy it using kubectl apply:

    yaml
    apiVersion: apps.emqx.io/v2beta1
    kind: EMQX
    metadata:
       name: emqx
    spec:
       image: emqx/emqx:6.0.1
       imagePullPolicy: IfNotPresent
       config:
          # Configure a TCP listener named `test` listening on port 1884:
          data: |
             listeners.tcp.test {
                bind = "0.0.0.0:1884"
                max_connections = 1024000
             }
             license {
               key = "..."
             }
       listenersServiceTemplate:
          spec:
             type: LoadBalancer
       dashboardServiceTemplate:
          spec:
             type: LoadBalancer

    TIP

    The content of the .spec.config.data field is supplied as emqx.conf configuration file to the EMQX container.

  2. Wait for the EMQX cluster to become ready.

Check the status of the EMQX cluster using kubectl get, and make sure that STATUS is Ready. This may take some time.

bash
$ kubectl get emqx emqx
NAME   STATUS   AGE
emqx   Ready    10m

Verify Configuration

View the EMQX listeners' status.

bash
$ kubectl exec -it emqx-core-0 -c emqx -- emqx ctl listeners
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

Here we can see that the new listener on port 1884 is running.