A modern Kubernetes operator for KeyDB, the high-performance Redis alternative, built with the Operator SDK in Go.
- Multi-Master Mode: Deploy KeyDB in multi-master configuration with active replication
- Cluster Mode: Deploy KeyDB cluster with automatic sharding and high availability
- Declarative Configuration: Kubernetes-native resource management
- Automatic Scaling: Support for horizontal scaling operations
- TLS Encryption: Full TLS support for client and inter-node communication
- Authentication: Password-based authentication with secret management
- Pod Disruption Budgets: Ensure cluster availability during maintenance
- Configuration Validation: Comprehensive validation to prevent misconfigurations
- Prometheus Metrics: Built-in Redis exporter for comprehensive monitoring
- Health Monitoring: Advanced health checks with replication lag monitoring
- Status Reporting: Detailed cluster status and individual node health
- ServiceMonitor: Automatic Prometheus ServiceMonitor creation
- Rolling Upgrades: Safe, automated rolling upgrades with validation
- Split-brain Recovery: Automatic detection and recovery from network partitions
- Persistent Storage: Configurable persistent volumes with storage classes
- Custom Configuration: Support for custom KeyDB configuration parameters
- Multiple KeyDB instances that can all accept reads and writes
- Active replication between all masters
- Automatic conflict resolution (last-write-wins)
- Ideal for high-write workloads and geographic distribution
- Automatic data sharding across multiple nodes using hash slots
- Master-replica topology for high availability
- Automatic failover and cluster healing
- Supports up to 1000 nodes with 16384 hash slots
- Kubernetes 1.19+
- kubectl configured to access your cluster
- Install the CRDs:
kubectl apply -f https://raw.githubusercontent.com/opendi/keydb-operator/main/config/crd/bases/keydb.io_keydbclusters.yaml- Install the operator:
kubectl apply -f https://github.com/opendi/keydb-operator/releases/latest/download/keydb-operator.yamlAlternatively, you can install a specific version:
kubectl apply -f https://github.com/opendi/keydb-operator/releases/download/v0.1.0/keydb-operator.yaml- Create a KeyDB cluster:
kubectl apply -f - <<EOF
apiVersion: keydb.io/v1alpha1
kind: KeyDBCluster
metadata:
name: keydb-sample
namespace: default
spec:
mode: multi-master
replicas: 3
image: eqalpha/keydb:latest
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "1000m"
storage:
size: "10Gi"
EOF- Check the cluster status:
kubectl get keydbcluster keydb-sample
kubectl get pods -l app=keydb-sampleapiVersion: keydb.io/v1alpha1
kind: KeyDBCluster
metadata:
name: keydb-multimaster
spec:
mode: multi-master
replicas: 3
image: eqalpha/keydb:latest
multiMaster:
activeReplica: true
config:
maxMemory: "2gb"
persistence: true
requirePass:
secretRef:
name: keydb-auth
key: password
tls:
enabled: true
secretName: keydb-tls-certs
requireClientCerts: false
customConfig:
tcp-keepalive: "300"
maxclients: "10000"
resources:
requests:
memory: "2Gi"
cpu: "1000m"
storage:
size: "20Gi"
storageClass: "fast-ssd"
monitoring:
enabled: true
port: 9121
serviceMonitorLabels:
prometheus: "kube-prometheus"
upgrade:
strategy: "RollingUpdate"
maxUnavailable: 1
validationTimeoutSeconds: 300
podDisruptionBudget:
maxUnavailable: 1apiVersion: keydb.io/v1alpha1
kind: KeyDBCluster
metadata:
name: keydb-cluster
spec:
mode: cluster
cluster:
shards: 3
replicasPerShard: 1
image: eqalpha/keydb:latest
config:
maxMemory: "1gb"
persistence: true
resources:
requests:
memory: "1Gi"
cpu: "500m"
storage:
size: "10Gi"| Field | Type | Description |
|---|---|---|
mode |
string | Deployment mode: multi-master or cluster |
replicas |
int | Number of KeyDB instances (multi-master mode) |
image |
string | KeyDB container image |
multiMaster |
object | Multi-master specific configuration |
cluster |
object | Cluster mode specific configuration |
config |
object | KeyDB configuration options |
resources |
object | Resource requirements |
storage |
object | Storage configuration |
service |
object | Service configuration |
monitoring |
object | Monitoring and metrics configuration |
upgrade |
object | Rolling upgrade strategy configuration |
podDisruptionBudget |
object | Pod disruption budget settings |
| Field | Type | Description |
|---|---|---|
maxMemory |
string | Maximum memory usage (e.g., "1gb", "512mb") |
persistence |
bool | Enable persistence (default: true) |
requirePass |
object | Password authentication configuration |
tls |
object | TLS encryption configuration |
customConfig |
map | Custom KeyDB configuration parameters |
| Field | Type | Description |
|---|---|---|
enabled |
bool | Enable TLS encryption |
secretName |
string | Secret containing TLS certificates |
requireClientCerts |
bool | Require client certificates |
| Field | Type | Description |
|---|---|---|
enabled |
bool | Enable Prometheus metrics (default: true) |
port |
int | Metrics port (default: 9121) |
serviceMonitorLabels |
map | Labels for ServiceMonitor creation |
| Field | Type | Description |
|---|---|---|
phase |
string | Current phase: Pending, Running, Failed |
replicas |
int | Total number of replicas |
readyReplicas |
int | Number of ready replicas |
conditions |
[]object | Detailed status conditions |
nodes |
[]object | Individual node status |
currentImage |
string | Current image version being used |
upgradeStatus |
object | Rolling upgrade progress |
health |
object | Cluster health metrics |
| Field | Type | Description |
|---|---|---|
status |
string | Overall health: Healthy, Warning, Degraded, Critical |
memoryUsagePercent |
float | Average memory usage across nodes |
replicationLagSeconds |
int | Maximum replication lag in seconds |
connectedClients |
int | Total connected clients |
lastCheckTime |
time | Last health check timestamp |
- Go 1.24+
- Docker
- kubectl
git clone https://github.com/opendi/keydb-operator.git
cd keydb-operator
make buildmake install runmake test- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- All KeyDB instances can accept both reads and writes
- Active replication between all masters using
active-replica yesandmulti-master yes - Automatic conflict resolution with last-write-wins semantics
- Ideal for geographically distributed deployments
- Data automatically sharded across multiple KeyDB nodes using hash slots
- Master-replica topology for high availability
- Automatic failover when masters become unavailable
- Supports up to 1000 nodes with 16384 hash slots
- Declarative Management: Define desired state via Kubernetes custom resources
- Automatic Configuration: Generates optimized KeyDB configuration based on deployment mode
- Advanced Health Monitoring: Real-time health checks with replication lag and memory monitoring
- Safe Scaling: Intelligent scaling with proper data rebalancing and validation
- Persistent Storage: Configurable persistent volumes with storage classes
- Production Security: Full TLS encryption, authentication, and certificate management
- Rolling Upgrades: Zero-downtime upgrades with automatic validation and rollback
- Split-brain Recovery: Automatic detection and recovery from network partitions
- Prometheus Integration: Built-in metrics collection and ServiceMonitor creation
- Configuration Validation: Comprehensive validation to prevent invalid configurations
The operator defines a KeyDBCluster custom resource with the following key features:
- Mode selection (multi-master or cluster)
- Resource requirements and limits
- Storage configuration
- Service configuration
- KeyDB-specific settings
The controller implements a comprehensive reconciliation loop that:
- Configuration Validation: Validates the KeyDBCluster specification against best practices
- Resource Management: Creates/updates ConfigMaps, StatefulSets, Services, and PodDisruptionBudgets
- Rolling Upgrades: Manages safe rolling upgrades with pod-by-pod validation
- Health Monitoring: Performs continuous health checks and replication monitoring
- TLS Management: Configures TLS encryption and certificate handling
- Metrics Collection: Sets up Prometheus monitoring and ServiceMonitors
- Scaling Operations: Handles intelligent scaling with data safety validation
- Status Reporting: Provides detailed cluster status and health metrics
- StatefulSets: Provides stable network identities and persistent storage with rolling update support
- Services: Headless service for StatefulSet discovery, client service for external access, and metrics endpoints
- ConfigMaps: Dynamic KeyDB configuration generation with TLS and custom parameter support
- Secrets: Secure password and TLS certificate management
- PodDisruptionBudgets: Ensures cluster availability during maintenance operations
- ServiceMonitors: Automatic Prometheus monitoring configuration
config:
tls:
enabled: true
secretName: keydb-tls-certs
requireClientCerts: falseupgrade:
strategy: "RollingUpdate"
maxUnavailable: 1
validationTimeoutSeconds: 300monitoring:
enabled: true
port: 9121
serviceMonitorLabels:
prometheus: "kube-prometheus"podDisruptionBudget:
maxUnavailable: 1
# OR
minAvailable: 2config:
customConfig:
tcp-keepalive: "300"
maxclients: "10000"
timeout: "0"# Create TLS certificates (example using cert-manager)
kubectl apply -f - <<EOF
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: keydb-tls
spec:
secretName: keydb-tls-certs
issuerRef:
name: ca-issuer
kind: ClusterIssuer
dnsNames:
- "*.keydb-headless.default.svc.cluster.local"
- "keydb.default.svc.cluster.local"
EOF# Ensure Prometheus operator is installed
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/bundle.yaml
# Deploy KeyDB cluster with monitoring
kubectl apply -f https://raw.githubusercontent.com/opendi/keydb-operator/main/config/samples/keydb_v1alpha1_keydbcluster_multimaster.yaml# Example backup using persistent volume snapshots
kubectl patch keydbcluster keydb-sample --type='merge' -p='{"spec":{"config":{"persistence":true}}}'- Pods not starting: Check resource limits and storage class availability
- TLS connection issues: Verify certificate validity and DNS names
- Replication lag: Monitor memory usage and network connectivity
- Upgrade failures: Check validation timeout and pod readiness
# Check cluster status
kubectl get keydbcluster -o wide
# View detailed status
kubectl describe keydbcluster keydb-sample
# Check pod logs
kubectl logs -l app=keydb -c keydb
# Monitor health metrics
kubectl get keydbcluster keydb-sample -o jsonpath='{.status.health}'- KeyDB - The high-performance Redis alternative
- Operator SDK - Framework for building Kubernetes operators
- krestomatio/keydb-operator - Inspiration from the Ansible-based operator