Install Dragonfly Kubernetes Operator

Dragonfly Operator is a Kubernetes operator used to deploy and manage Dragonfly instances in your Kubernetes clusters.

The main features include:

  • Automatic Failover
  • Scaling Horizontally and Vertically (with Custom Rollout Strategy)
  • Custom Configuration Options
  • Authentication and Server TLS
  • Snapshots to Persistent Volume Claims (PVCs) and S3-Compatible Cloud Storage
  • Monitoring with Prometheus and Grafana

Prerequisites

  • A working Kubernetes cluster (tested with Kubernetes 1.19+)
  • kubectl installed and configured to connect to your cluster

Installation

Make sure your Kubernetes cluster is up and running. To install Dragonfly Operator, run:

  1. # Install the CRD and Operator
  2. kubectl apply -f https://raw.githubusercontent.com/dragonflydb/dragonfly-operator/main/manifests/dragonfly-operator.yaml

By default, the operator will be installed in the dragonfly-operator-system namespace.

Usage

Create a Dragonfly instance with replicas

  1. To create a sample Dragonfly instance with a master and three replicas, run the this command:

    1. kubectl apply -f https://raw.githubusercontent.com/dragonflydb/dragonfly-operator/main/config/samples/v1alpha1_dragonfly.yaml
  2. To check the status of the instance, run:

    1. kubectl describe dragonflies.dragonflydb.io dragonfly-sample
  3. Connect to the master instance of the service at:
    <dragonfly-name>.<namespace>.svc.cluster.local.

    As pods are added or removed, the service automatically updates to point to the new master.

Connect with redis-cli

To connect to the instance using redis-cli, run:

  1. kubectl run -it --rm --restart=Never redis-cli --image=redis:7.0.10 -- redis-cli -h dragonfly-sample.default

The command creates a temporary pod that runs the redis-cli and connects to the instance. To run Redis commands, press shift + R and then enter the Redis commands. For example, to set and retrieve a key, you can run:

  1. If you don't see a command prompt, try pressing enter.
  2. dragonfly-sample.default:6379> GET 1
  3. (nil)
  4. dragonfly-sample.default:6379> SET 1 2
  5. OK
  6. dragonfly-sample.default:6379> GET 1
  7. "2"
  8. dragonfly-sample.default:6379> exit
  9. pod "redis-cli" deleted

Change the number of replica instances

To change the number of replica instances, edit the spec.replicas field in the Dragonfly instance. For example, to scale up to 5 replicas run:

  1. kubectl patch dragonfly dragonfly-sample --type merge -p '{"spec":{"replicas":5}}'

Pass custom Dragonfly arguments

To pass custom arguments to Dragonfly, edit the spec.args field in the Dragonfly instance. For example, to configure Dragonfly to require a password run:

  1. kubectl patch dragonfly dragonfly-sample --type merge -p '{"spec":{"args":["--requirepass=supersecret"]}}'

Vertically scale the instance

To vertically scale the instance, edit the spec.resources field in the Dragonfly instance. For example, to increase the CPU requests to 2 cores run:

  1. kubectl patch dragonfly dragonfly-sample --type merge -p '{"spec":{"resources":{"requests":{"cpu":"2"}}}}'

To understand how to configure High Availability, please refer to the High Availability section.