Skip to content

Enable Persistence In EMQX Cluster

Task Target

  • Configure EMQX 4.x cluster persistence through persistent field.
  • Configure EMQX 5.x cluster Core node persistence through volumeClaimTemplates field.

Configure EMQX Cluster Persistence

The following is the relevant configuration of EMQX Custom Resource. You can choose the corresponding APIVersion according to the version of EMQX you want to deploy. For the specific compatibility relationship, please refer to EMQX Operator Compatibility:

Verify EMQX Cluster Persistence

TIP

The screenshots of the Dashboard below are from EMQX 5, EMQX 4 Dashboard also supports the corresponding function, please operate by yourself.

Verification scheme: 1) Passed in the old EMQX Dashboard creates a test rule; 2) Deletes the old cluster; 3) Recreates the EMQX cluster,and checks whether the previously created rule exists through the Dashboard.

  • Access EMQX Dashboard through browser to create test rules

    Login EMQX Dashboard by accessing http://${external_ip}:18083, and click Data Integration → Rules to enter the page for creating rules. Let’s first click the button to add an action Add a response action for this rule, and then click Create to generate a rule, as shown in the following figure:

    When our rule is successfully created, a rule record will appear on the page with the rule ID: emqx-persistent-test, as shown in the figure below:

  • delete old EMQX cluster

    Execute the following command to delete the EMQX cluster:

    bash
    $ kubectl delete -f emqx.yaml
    
    emqx.apps.emqx.io "emqx" deleted
    # emqxenterprise.apps.emqx.io "emqx" deleted

    emqx-persistent.yaml is the YAML file used to deploy the EMQX cluster for the first time in this article, and this file does not need to be changed.

  • Recreate the EMQX cluster

    Execute the following command to recreate the EMQX cluster:

    bash
    $ kubectl apply -f emqx.yaml
    
    emqx.apps.emqx.io/emqx created
    # emqxenterprise.apps.emqx.io/emqx created

    Wait for the EMQX cluster to be ready, and then access the EMQX Dashboard through the browser to check whether the previously created rules exist, as shown in the following figure:

    It can be seen from the figure that the rule emqx-persistent-test created in the old cluster still exists in the new cluster, which means that the persistence we configured is in effect.