# Enable Persistence in EMQX Cluster

# Task target

  • How to configure EMQX 4.x cluster persistence through the persistent field.
  • How to configure EMQX 5.x cluster Core node persistence through the volumeClaimTemplates field.

# EMQX Cluster Persistence Configuration

Here are the relevant configurations for EMQX Custom Resource. You can choose the corresponding APIVersion based on the version of EMQX you wish to deploy. For specific compatibility relationships, please refer to EMQX Operator Compatibility:

# Verify Persistence in EMQX Cluster

Verification scheme: 1) Create a test rule through the Dashboard in the old EMQX cluster; 2) Delete the old cluster; 3) Recreate the EMQX cluster, and check whether the previously created rule exists through the Dashboard.

  • Create test rules through Dashboard

Open the browser, enter the IP of the host where the EMQX Pod is located and the port 32016 to log in to the EMQX cluster Dashboard (Dashboard default username: admin, default password: public), enter the Dashboard and click Data Integration → Rules to enter the creation rule page, we first click the Add Action button to 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 the old EMQX cluster

Execute the following command to delete the EMQX cluster:

$ kubectl delete -f emqx.yaml

emqx.apps.emqx.io "emqx" deleted
# emqxenterprise.apps.emqx.io "emqx" deleted
1
2
3
4

emqx.yaml is the YAML file used for the first deployment of the EMQX cluster in this article. This file does not need to be changed.

  • Recreate the EMQX cluster

Execute the following command to recreate the EMQX cluster:

$ kubectl apply -f emqx.yaml

emqx.apps.emqx.io/emqx created
# emqxenterprise.apps.emqx.io/emqx created
1
2
3
4

Wait EMQX cluster is running, and visit 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.