Skip to main content
Version: 5.17

Tutorial: Restore a cluster from cloud storage

Learn how to back up data in Hazelcast maps to cloud storage and restore a cluster from that backup data.

Overview​

In this tutorial, you'll do the following:

  • Deploy Hazelcast with persistence enabled.
  • Create a Hazelcast map that has persistence enabled.
  • Back up all map entries to external storage in the cloud.
  • Restart the Hazelcast cluster and restore the backup map entries from the cloud.

The tutorial should take approximately 20 minutes to complete.

Prerequisites​

Before you begin, make sure that you have:

Start the Hazelcast cluster​

  1. Create a secret with your Hazelcast Enterprise License.

    shell
    kubectl create secret generic hazelcast-license-key --from-literal=license-key=<hz-license-key>
  2. Create a Hazelcast cluster with Persistence enabled:

    shell
    kubectl apply -f - <<EOF
    apiVersion: hazelcast.com/v1alpha1
    kind: Hazelcast
    metadata:
    name: my-hazelcast
    spec:
    clusterSize: 3
    licenseKeySecretName: hazelcast-license-key
    persistence:
    pvc:
    accessModes: ["ReadWriteOnce"]
    requestStorage: 8Gi
    exposeExternally:
    type: Unisocket
    discoveryServiceType: LoadBalancer
    EOF
  3. Check the cluster status:

    shell
    kubectl get hazelcast my-hazelcast
    NAME STATUS MEMBERS
    my-hazelcast Running 3/3
    shell
    kubectl get pods -l app.kubernetes.io/instance=my-hazelcast
    NAME READY STATUS RESTARTS AGE
    my-hazelcast-0 2/2 Running 0 3m43s
    my-hazelcast-1 2/2 Running 0 3m16s
    my-hazelcast-2 2/2 Running 0 2m50s

    As you can see from the pod states, the agent container will be deployed with the Hazelcast container in the same Pod. The agent is responsible for backing data up into the external storage.

  4. After verifying that the cluster is Running and all the members are ready, find the discovery address:

    shell
    kubectl get hazelcastendpoint my-hazelcast
    NAME TYPE ADDRESS
    my-hazelcast Discovery 198.51.100.128:5701

    The ADDRESS column displays the external address of your Hazelcast cluster.

Create persistent map and put data​

  1. Create a Map resource with persistence enabled:

    shell
    kubectl apply -f - <<EOF
    apiVersion: hazelcast.com/v1alpha1
    kind: Map
    metadata:
    name: persistent-map
    spec:
    hazelcastResourceName: my-hazelcast
    persistenceEnabled: true
    EOF
  2. Check the status of the map configuration:

    bash
    kubectl get map persistent-map

    The status of the map is displayed in the output.

    bash
    NAME STATUS
    persistent-map Success
  3. Configure the Hazelcast client to connect to the cluster.

    Open the examples folder to access all sample clients:

    shell
    cd hazelcast-platform-operator-external-backup-restore

    The sample code for this tutorial is in the docs/modules/ROOT/examples/operator-external-backup directory.

    note

    CLC must be installed in your system. See the CLC installation instructions.

    Add the cluster configuration to CLC:

    bash
    clc config add hz cluster.name=dev cluster.address=<EXTERNAL-IP>
  4. Start the client to fill the map.

    Fill a map:

    bash
    for i in {1..10};
    do
    clc -c hz map set --name persistent-map key-$i value-$i;
    done

    Check the map size:

    bash
    clc -c hz map size --name persistent-map

Trigger an external backup​

To trigger a backup, you need a bucketURI where backup data will be stored and a secret with credentials for accessing the bucket URI.

  1. Run one of the following commands to create the secret according to the cloud provider you want to back up:

    bash
    kubectl create secret generic <external-bucket-secret-name> --from-literal=region=<region> \
    --from-literal=access-key-id=<access-key-id> \
    --from-literal=secret-access-key=<secret-access-key>
  2. Trigger a backup:

    shell
    kubectl apply -f - <<EOF
    apiVersion: hazelcast.com/v1alpha1
    kind: HotBackup
    metadata:
    name: hot-backup
    spec:
    hazelcastResourceName: my-hazelcast
    bucketURI: "s3://operator-backup"
    secret: "br-secret-s3"
    EOF

    Example URI → "s3://operator-backup?prefix=hazelcast/2022-06-08-17-01-20/"

  3. Check the status of the backup:

    bash
    kubectl get hotbackup hot-backup

    The status of the backup is displayed in the output.

    bash
    NAME STATUS
    hot-backup Success

Restore from an external backup​

  1. Delete the Hazelcast cluster:

    bash
    kubectl delete hazelcast my-hazelcast
  2. Delete the PersistentVolumeClaims.

    The data is restored from external buckets, so you don't keep persistent volumes during a restore operation.

    List PVCs that were created for the Hazelcast cluster:

    bash
    kubectl get pvc -l "app.kubernetes.io/managed-by=hazelcast-platform-operator"
    NAME STATUS VOLUME CAPACITY
    persistence-my-hazelcast-0 Bound pvc-a77fcd6e-e64d-4aeb-9708-835d66b4c5b9 8Gi
    persistence-my-hazelcast-1 Bound pvc-8548a4a5-fa8e-45bd-9909-8e6bb6a6c3e8 8Gi
    persistence-my-hazelcast-2 Bound pvc-c94edb25-5a72-482a-bf4e-84a99319d509 8Gi

    Delete the PVCs:

    bash
    kubectl delete pvc -l "app.kubernetes.io/managed-by=hazelcast-platform-operator"
  3. Create a new Hazelcast cluster.

    For restoring, you will use the HotBackup resource you have created.

    Create the Hazelcast cluster. Before the Hazelcast cluster is started, Operator starts the agent (as InitContainer), which restores the backup data from the external bucket.

    shell
    kubectl apply -f - <<EOF
    apiVersion: hazelcast.com/v1alpha1
    kind: Hazelcast
    metadata:
    name: my-hazelcast
    spec:
    clusterSize: 3
    licenseKeySecretName: hazelcast-license-key
    persistence:
    pvc:
    accessModes: ["ReadWriteOnce"]
    requestStorage: 8Gi
    restore:
    hotBackupResourceName: hot-backup
    exposeExternally:
    type: Unisocket
    discoveryServiceType: LoadBalancer
    EOF

    As you may see, the agent configuration is not set. Operator therefore uses the latest stable version of the agent.

  4. Check the cluster status:

    shell
    kubectl get hazelcast my-hazelcast
    NAME STATUS MEMBERS
    my-hazelcast Running 3/3

    After verifying that the cluster is Running and all the members are ready, find the discovery address:

    shell
    kubectl get hazelcastendpoint my-hazelcast
    NAME TYPE ADDRESS
    my-hazelcast Discovery 34.28.159.226:5701

    Since we recreated the Hazelcast cluster, services are also recreated. The ADDRESS may change.

  5. Check the map size.

    Configure the Hazelcast client to connect to the cluster external address as you did in Configure the Hazelcast Client.

    Start the client to check the map size and check the restore is successful.

    bash
    clc -c hz map size --name persistent-map

Clean up​

To clean up the created resources, remove all Custom Resources and PVCs.

shell
kubectl delete secret <external-bucket-secret-name>
kubectl delete secret hazelcast-license-key
kubectl delete $(kubectl get hazelcast,hotbackup -o name)
kubectl delete pvc -l "app.kubernetes.io/managed-by=hazelcast-platform-operator"

Summary​

In this tutorial, you learned how to:

  • Deploy Hazelcast with persistence enabled.
  • Create a Hazelcast map that has persistence enabled.
  • Back up all map entries to external storage in the cloud.
  • Restart the Hazelcast cluster and restore the backup map entries from the cloud.

Next steps​

See also: