# Configure EMQX persistence

# 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

  • Configure EMQX cluster

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

kubectl apply -f emqx-persistent.yaml
1

The output is similar to:

emqx.apps.emqx.io/emqx created
1
  • Check whether the EMQX cluster is ready

# Verify whether the EMQX cluster persistence is in effect

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-persistent.yaml
1

NOTE: emqx-persistent.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.

The output is similar to:

emqx.apps.emqx.io "emqx" deleted
1

Execute the following command to check whether the EMQX cluster is deleted:

kubectl get emqx emqx -o json | jq ".status.emqxNodes"
1

The output is similar to:

Error from server (NotFound): emqxes.apps.emqx.io "emqx" not found
1
  • Recreate the EMQX cluster

Execute the following command to recreate the EMQX cluster:

kubectl apply -f emqx-persistent.yaml
1

The output is similar to:

emqx.apps.emqx.io/emqx created
1

Next, execute the following command to check whether the EMQX cluster is ready:

kubectl get emqx emqx -o json | jq ".status.emqxNodes"
1

The output is similar to:

[
   {
     "node": "emqx@emqx-core-0.emqx-headless.default.svc.cluster.local",
     "node_status": "running",
     "otp_release": "24.2.1-1/12.2.1",
     "role": "core",
     "version": "5.0.9"
   },
   {
     "node": "emqx@emqx-core-1.emqx-headless.default.svc.cluster.local",
     "node_status": "running",
     "otp_release": "24.2.1-1/12.2.1",
     "role": "core",
     "version": "5.0.9"
   },
   {
     "node": "emqx@emqx-core-2.emqx-headless.default.svc.cluster.local",
     "node_status": "running",
     "otp_release": "24.2.1-1/12.2.1",
     "role": "core",
     "version": "5.0.9"
   }
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

Finally, 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.