falkordb

by apecloud

Helm chartv1.2.0-alpha.0App 4.12.5Verified publisher

FalkorDB is an in-memory graph database based on Redis.

About this chart

FalkorDB

FalkorDB is an open source (SSPL licensed) in-memory graph database based on Redis. This example shows how it can be managed in Kubernetes with KubeBlocks.

Features In KubeBlocks

Lifecycle Management

TopologyHorizontalscalingVertical scalingExpandvolumeRestartStop/StartConfigureExposeSwitchover
replicationYesYesYesYesYesYesYesYes
standaloneYesYesYesYesYesYesYesN/A
shardingYesYesYesYesYesYesYesYes

Backup and Restore

FeatureMethodDescription
Full Backupdatafileuses redis-cli BGSAVE command to backup data
Continuous Backupaofcontinuously perform incremental backups by archiving Append-Only Files (AOF)

Versions

Major VersionsDescription
4.04.12.5

Prerequisites

  • Kubernetes cluster >= v1.21

  • kubectl installed, refer to K8s Install Tools

  • Helm, refer to Installing Helm

  • KubeBlocks installed and running, refer to Install Kubeblocks

  • FalkorDB Addon Enabled, refer to Install Addons

  • Create K8s Namespace demo, to keep resources created in this tutorial isolated:

    kubectl create ns demo
    

Examples

Create

Create a FalkorDB replication cluster with two components, one for FalkorDB, and one for Sentinel[^1].

For optimal reliability, you should run at least three Sentinel replicas. Having three or more Sentinels ensures a quorum can be reached during failover decisions, maintaining the high availability of your FalkorDB deployment.

# cat examples/falkordb/cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: falkordb-replication
  namespace: demo
spec:
  # Specifies the behavior when a Cluster is deleted.
  # Valid options are: [DoNotTerminate, Delete, WipeOut] (`Halt` is deprecated since KB 0.9)
  # - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
  # - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
  # - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
  terminationPolicy: Delete
  # Specifies the name of the ClusterDefinition to use when creating a Cluster.
  # Note: DO NOT UPDATE THIS FIELD
  # The value must be `postgresql` to create a PostgreSQL Cluster
  clusterDef: falkordb
  # Specifies the name of the ClusterTopology to be used when creating the
  # Cluster.
  topology: replication
  # Specifies a list of ClusterComponentSpec objects used to define the
  # individual Components that make up a Cluster.
  # This field allows for detailed configuration of each Component within the Cluster
  componentSpecs:
    - name: falkordb
      # ServiceVersion specifies the version of the Service expected to be
      # provisioned by this Component.
      # Valid options are: [4.12.5]
      serviceVersion: "4.12.5"
      # Determines whether metrics exporter information is annotated on the
      # Component's headless Service.
      # Valid options are [true, false]
      disableExporter: false
      # Specifies the desired number of replicas in the Component
      replicas: 2
      # Specifies the resources required by the Component.
      resources:
        limits:
          cpu: '0.5'
          memory: 0.5Gi
        requests:
          cpu: '0.5'
          memory: 0.5Gi
      # Specifies a list of PersistentVolumeClaim templates that define the storage
      # requirements for the Component.
      volumeClaimTemplates:
        # Refers to the name of a volumeMount defined in
        # `componentDefinition.spec.runtime.containers[*].volumeMounts
        - name: data
          spec:
            # The name of the StorageClass required by the claim.
            # If not specified, the StorageClass annotated with
            # `storageclass.kubernetes.io/is-default-class=true` will be used by default
            storageClassName: ""
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                # Set the storage size as needed
                storage: 20Gi
    - name: falkordb-sent
      serviceVersion: "4.12.5"
      replicas: 3
      resources:
        limits:
          cpu: '0.5'
          memory: 0.5Gi
        requests:
          cpu: '0.5'
          memory: 0.5Gi
      # Specifies a list of PersistentVolumeClaim templates that define the storage
      # requirements for the Component.
      volumeClaimTemplates:
        # Refers to the name of a volumeMount defined in
        # `componentDefinition.spec.runtime.containers[*].volumeMounts
        - name: data
          spec:
            # The name of the StorageClass required by the claim.
            # If not specified, the StorageClass annotated with
            # `storageclass.kubernetes.io/is-default-class=true` will be used by default
            storageClassName: ""
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                # Set the storage size as needed
                storage: 20Gi

kubectl apply -f examples/falkordb/cluster.yaml

A cluster named falkordb-replication will be created with 1 primary pod, 1 secondary pod, and 3 sentinel pods.

kubectl get -n demo cluster falkordb-replication # get cluster info
kubectl get pod -n demo -l app.kubernetes.io/instance=falkordb-replication # get all pods of the cluster

[!NOTE] If all Pods are running, but the cluster status is still Creating, you may need to wait for a while until all FalkorDB Pods are ready with corresponding Roles.

To check the role of each FalkorDB pod, you can use the following command:

# replace `falkordb-replication` with your cluster name
kubectl get po -n demo -l app.kubernetes.io/instance=falkordb-replication,apps.kubeblocks.io/component-name=falkordb -L kubeblocks.io/role

Why the Sentinel starts first?

The Sentinel (based on the Redis Sentinel) is a high availability solution for FalkorDB (Redis). It provides monitoring, notifications, and automatic failover for FalkorDB instances.

Each FalkorDB replica, from the FalkorDB component, upon startup, will connect to the Sentinel instances to get the current leader and follower information. It needs to determine:

  • Whether it should act as the primary (master) node.
  • If not, which node is the current primary to replicate from.

In more detail, each FalkorDB replica will:

  1. Check for Existing Primary Node
    • Queries the Sentinel to find out if a primary node is already elected.
    • Retrieve the primary's address and port.
  2. Initialize as Primary if Necessary
    • If no primary is found (e.g., during initial cluster setup), it configures the current FalkorDB instance to become the primary.
    • Updates FalkorDB configuration to disable replication.
  3. Configure as Replica if Primary Exists
    • If a primary is found, it sets up the current FalkorDB instance as a replica.
    • Updates the FalkorDB configuration with the replicaof directive pointing to the primary's address and port.
    • Initiates replication to synchronize data from the primary.

KubeBlocks ensures that the Sentinel starts first to provide the necessary information for the FalkorDB replicas to initialize correctly. Such dependency is well-expressed in the KubeBlocks CRD ClusterDefinition ensuring the correct startup order.

More details on how components for the replication topology are started, upgraded can be found in:

kubectl get cd falkordb -oyaml | yq '.spec.topologies[] | select(.name=="replication") | .orders'

Horizontal scaling

Scale-out

Horizontal scaling out FalkorDB component by adding ONE more replica:

# cat examples/falkordb/scale-out.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: falkordb-scale-out
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: falkordb-replication
  type: HorizontalScaling
  # Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
  horizontalScaling:
    # Specifies the name of the Component.
  - componentName: falkordb
    # Specifies the replica changes for scaling in components
    scaleOut:
      # Specifies the replica changes for the component.
      # add one more replica to current component
      replicaChanges: 1

kubectl apply -f examples/falkordb/scale-out.yaml

After applying the operation, you will see a new pod created and the cluster status goes from Updating to Running, and the newly created pod has a new role secondary.

And you can check the progress of the scaling operation with following command:

kubectl describe -n demo ops falkordb-scale-out

Scale-in

Horizontal scaling in FalkorDB component by removing ONE replica:

# cat examples/falkordb/scale-in.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: falkordb-scale-in
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: falkordb-replication
  type: HorizontalScaling
  # Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
  horizontalScaling:
    # Specifies the name of the Component.
  - componentName: falkordb
    # Specifies the replica changes for scaling in components
    scaleIn:
      # Specifies the replica changes for the component.
      # add one more replica to current component
      replicaChanges: 1
kubectl apply -f examples/falkordb/scale-in.yaml

Scale-in/out using Cluster API

Alternatively, you can update the replicas field in the spec.componentSpecs.replicas section to your desired non-zero number.

# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  componentSpecs:
    - name: falkordb
      serviceVersion: "4.12.5"
      replicas: 2 # decrease `replicas` for scaling in, and increase for scaling out
      disableExporter: false

Vertical scaling

Vertical scaling involves increasing or decreasing resources to an existing database cluster. Resources that can be scaled include:, CPU cores/processing power and Memory (RAM).

Vertical scaling up or down requests and limits cpu or memory resource for FalkorDB component:

# cat examples/falkordb/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: falkordb-verticalscaling
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: falkordb-replication
  type: VerticalScaling
  # Lists VerticalScaling objects, each specifying a component and its desired compute resources for vertical scaling.
  verticalScaling:
  - componentName: falkordb
    # VerticalScaling refers to the process of adjusting the compute resources (e.g., CPU, memory) allocated to a Component. It defines the parameters required for the operation.
    requests:
      cpu: '1'
      memory: 1Gi
    limits:
      cpu: '1'
      memory: 1Gi

kubectl apply -f examples/falkordb/verticalscale.yaml

You will observe that the follower pods are recreated first, followed by the leader pod, to ensure the availability of the cluster.

Scale-up/down using Cluster API

Alternatively, you may update spec.componentSpecs.resources field to the desired resources for vertical scale.

# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  componentSpecs:
    - name: falkordb
      serviceVersion: "4.12.5"
      replicas: 2 # decrease `replicas` for scaling in, and increase for scaling out
      resources:
        requests:
          cpu: "1"       # Update the resources to your need.
          memory: "2Gi"  # Update the resources to your need.
        limits:
          cpu: "2"       # Update the resources to your need.
          memory: "4Gi"  # Update the resources to your need.

Expand volume

Volume expansion is the ability to increase the size of a Persistent Volume Claim (PVC) after it's created. It is introduced in Kubernetes v1.11 and goes GA in Kubernetes v1.24. It allows Kubernetes users to simply edit their PersistentVolumeClaim objects without requiring any downtime at all if possible.

[!NOTE] Make sure the storage class you use supports volume expansion.

Check the storage class with following command:

kubectl get storageclass

If the ALLOWVOLUMEEXPANSION column is true, the storage class supports volume expansion.

If you don't have a storage class that supports volume expansion, you can create a new one. Please refer to [CSI driv

Deploy falkordb with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has falkordb on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartfalkordb is pinned at v1.2.0-alpha.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply