dragonflydb/dragonfly-operator
About
A Kubernetes operator to install and manage Dragonfly instances.
Systems & InfrastructureMeasured star growth
- in 24h
- +1
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalDragonfly Operator is a Kubernetes operator used to deploy and manage Dragonfly instances inside your Kubernetes clusters. Main features include:
- Automatic failover
- Scaling horizontally and vertically with custom rollout strategy
- Authentication and server TLS
- Automatic snapshots to PVCs and S3
- Monitoring with Prometheus and Grafana
- Comprehensive configuration options
You can find more information about Dragonfly in the official documentation. There is also a dedicated Dragonfly Operator section that contains more details and examples on how to use the operator.
Installation
Make sure to have your Kubernetes cluster up and running. Dragonfly Operator can be installed by running
# Install the CRD and Operator
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
Creating a Dragonfly instance
To create a sample Dragonfly instance, you can run the following command:
kubectl apply -f https://raw.githubusercontent.com/dragonflydb/dragonfly-operator/main/config/samples/v1alpha1_dragonfly.yaml
This will create a Dragonfly instance with 2 replicas. You can check the status of the instance by running
kubectl describe dragonflies.dragonflydb.io dragonfly-sample
A service of the form <dragonfly-name>.<namespace>.svc.cluster.local will be created, that selects the master instance. You can use this service to connect to the cluster. As pods are added/removed, the service will automatically update to point to the new master.
Connecting with redis-cli
To connect to the cluster using redis-cli, you can run:
kubectl run -it --rm --restart=Never redis-cli --image=redis:7.0.10 -- redis-cli -h dragonfly-sample.default
This will create a temporary pod that runs redis-cli and connects to the cluster. After pressing shift + R, You can then run Redis commands as
usual. For example, to set a key and get it back, you can run
If you don't see a command prompt, try pressing enter.
dragonfly-sample.default:6379> GET 1
(nil)
dragonfly-sample.default:6379> SET 1 2
OK
dragonfly-sample.default:6379> GET 1
"2"
dragonfly-sample.default:6379> exit
pod "redis-cli" deleted
Scaling up/down the number of replicas
To scale up/down the number of replicas, you can edit the spec.replicas field in the Dragonfly instance. For example, to scale up to 5 replicas, you can run
kubectl patch dragonfly dragonfly-sample --type merge -p '{"spec":{"replicas":5}}'
Starting pods in parallel
The StatefulSet uses OrderedReady by default, so pods start and stop one at a time. A pod that cannot start, for example because its node is drained, blocks every later pod. Set spec.podManagementPolicy to Parallel to start and stop pods together:
apiVersion: dragonflydb.io/v1alpha1
kind: Dragonfly
metadata:
name: dragonfly-sample
spec:
replicas: 3
podManagementPolicy: Parallel
podManagementPolicy is immutable. The API server rejects a change on an existing instance, so delete and recreate the Dragonfly instance to switch policies. With Parallel, scaling down terminates pods at the same time rather than one at a time.
Vertically scaling the instance
To vertically scale the instance, you can edit the spec.resources field in the Dragonfly instance. For example, to increase the memory limit to 2GiB, you can run
kubectl patch dragonfly dragonfly-sample --type merge -p '{"spec":{"resources":{"requests":{"memory":"1Gi"},"limits":{"memory":"2Gi"}}}}'
Configuring instance authentication
To add authentication to the dragonfly pods, you either set the DFLY_requirepass environment variable, or add the --requirepass argument.
LDAP authentication
Set spec.authentication.ldap to authenticate clients against an LDAP directory. The operator adds an auth sidecar container to every Dragonfly pod and starts Dragonfly with --auth_validate, so each AUTH is checked by the sidecar, which searches the directory for the user and binds as the entry it finds.
apiVersion: dragonflydb.io/v1alpha1
kind: Dragonfly
metadata:
name: dragonfly-sample
spec:
replicas: 2
aclFromSecret:
name: dragonfly-acl
key: acl
authentication:
ldap:
servers:
- ldaps://ldap.example.org:636
searchBindDN: cn=admin,dc=example,dc=org
searchBindPasswordFromSecret:
name: dragonfly-ldap-bind
key: password
userSearchBaseDN: ou=people,dc=example,dc=org
imageis optional. It defaults toghcr.io/dragonflydb/operator-auth-sidecar, tagged with the operator version, which every operator release publishes.- The Dragonfly image must support the
--auth_validateand--auth_validate_urlflags. - The authenticated username must name an active Dragonfly ACL user, so define the users with
spec.aclFromSecret. Passwords in the ACL file are not used whileAUTHis delegated. serverstakes exactly one URL for now.userSearchFilter,userSearchAttribute,userSearchDNAttributeanduserSearchScopetune the user search.useStartTLS,tlsCACertSecret,tlsCertSecretandtlsKeySecretconfigure TLS to the LDAP server. The client certificate and key must be set together.timeoutConnectionandtimeoutLDAPOperationbound the LDAP calls, andhttpsets the timeouts of the sidecar's HTTP server (readHeaderTimeout,readTimeout,writeTimeout,idleTimeout,shutdownTimeout).resourcessets the sidecar's resource limits.- The sidecar listens on port 8080.
To authenticate by LDAP group instead of by username, set groupMappings. The sidecar then looks up the groups of the user and authenticates it as the aclUser of the first mapping whose group the user is a member of, so aclUser is what must name an ACL user. Users without a mapped group are rejected.
authentication:
ldap:
# ...
groupSearchBaseDN: ou=groups,dc=example,dc=org
groupSearchFilter: (objectClass=groupOfNames)
groupMappings:
- groupDN: cn=admins,ou=groups,dc=example,dc=org
aclUser: admin
- groupDN: cn=readers,ou=groups,dc=example,dc=org
aclUser: reader
groupSearchBaseDN is required with groupMappings, while groupSearchFilter, groupSearchAttribute, groupSearchDNAttribute and groupSearchScope are optional.
See config/samples/v1alpha1_dragonfly_ldap.yaml for a full example.
Customising health-check probe scripts
The operator generates default liveness, readiness, and startup probe scripts and mounts them via ConfigMaps. You can replace any probe with your own script using the custom*ProbeConfigMap fields.
Scripts run inside the Dragonfly container and have access to HEALTHCHECK_PORT (admin port 9999 — no TLS, no auth).
apiVersion: v1
kind: ConfigMap
metadata:
name: dragonfly-sample-probes
namespace: default
data:
liveness-check.sh: |
#!/bin/sh
RESPONSE=$(timeout 4 redis-cli -h localhost -p ${HEALTHCHECK_PORT:-9999} PING 2>/dev/null)
case "$RESPONSE" in
PONG|*LOADING*) exit 0 ;;
*) exit 1 ;;
esac
---
apiVersion: dragonflydb.io/v1alpha1
kind: Dragonfly
metadata:
name: dragonfly-sample
spec:
replicas: 1
customLivenessProbeConfigMap:
name: dragonfly-sample-probes
Override precedence:
spec.additionalVolumeswith a matching volume name (liveness-probe,readiness-probe,startup-probe) takes precedence overcustom*ProbeConfigMap. Do not use both for the same probe.
Deleting a Dragonfly instance
To delete a Dragonfly instance, you can run
kubectl delete dragonfly dragonfly-sample
This will automatically delete all the resources (i.e pods and services) associated with the instance.
Uninstalling the operator
To uninstall the operator, you can run
kubectl delete -f https://raw.githubusercontent.com/dragonflydb/dragonfly-operator/main/manifests/dragonfly-operator.yaml
Note regarding ipv6 only support
You need to add those args in the dragonfly instance declaration in order to bind on ipv6.
...
- "--bind=::"
- "--admin_bind=::"
...
License
Copyright 2023 DragonflyDB authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Explore related projects
Loading…