ot-container-kit/redis-operator

repository·main·Indexed 23 days ago

https://github.com/ot-container-kit/redis-operator

A Golang-based Kubernetes operator designed to automate the deployment and management of Redis in Standalone, Cluster, Replication, and Sentinel modes. It provides Helm charts for the operator itself and for deploying Redis clusters and replications, featuring support for cert-manager webhook integration, TLS configuration, and production best practices for memory management and persistence.

Tokens
29.5K
Snippets
75
Records
152
Agent score
80%

What's inside redis-operator

  1. Overview of Redis Operator

    main

    Redis Operator is a Golang-based Kubernetes operator designed to automate the deployment and management of Redis instances. It supports multiple deployment modes including Standalone, Cluster, Replication, and Sentinel, ensuring best practices for both Cloud and Bare-metal environments.

    Supported Redis Modes:

    • Redis Cluster
    • Redis Standalone
    • Redis Replication
    • Redis Sentinel

    Important Version Constraint: This operator only supports Redis versions =>6.

  2. Overview of Redis Operator features and capabilities

    main

    The Redis Operator is a Golang-based Kubernetes operator designed to manage Redis workloads using production-ready best practices. It supports multiple deployment modes, including:

    • Standalone: Single instance Redis.
    • Cluster: Redis Cluster mode with failover and recovery capabilities.
    • Replication: Master-slave setup.
    • Sentinel: High availability using Redis Sentinel.

    Key Security and Networking Features:

    • Password and password-less authentication.
    • TLS support for enhanced security.
    • Support for both IPv4 and IPv6.
    • In-built monitoring via redis-exporter.
  3. What is Redis Sentinel and how does it work?

    main

    Redis Sentinel is a tool that provides automatic failover and monitoring for Redis nodes. It runs separate processes that communicate with each other and with Redis nodes to:

    1. Detect failures.
    2. Elect a new master node.
    3. Configure other nodes to replicate from the new master.

    It can also perform additional tasks such as sending notifications and managing configuration changes, making it a robust solution for implementing high availability in Redis.

  4. How Redis Cluster architecture works

    main

    A Redis cluster uses a data sharding strategy to automatically partition data across multiple Redis nodes, providing distributed storage and preventing a single point of failure.

    In this architecture, if a Redis node fails, a follower pod is automatically promoted to a leader. When the failed node returns online, it resumes its role as a follower.

    A sharded cluster with a leader-only architecture requires a minimum of 3 nodes. If followers are included for high availability, the deployment will consist of at least 6 pods/processes.

  5. Understand the Redis Operator project structure

    main

    The Redis Operator codebase is organized into several key directories:

    • api/: Contains the interface and structure for Custom Resource Definition (CRD) definitions (e.g., v1beta2).
    • controllers/: Contains the watch controllers responsible for creating, updating, and deleting resources.
    • k8sutils/: Contains the codebase for Kubernetes resources such as StatefulSets and Services.
    • config/: Contains configuration for certmanager, crd (bases and patches), rbac, prometheus, and samples.
    • bin/: Binary files.
    • hack/: Internal scripts/tools.
  6. Key features of Redis Operator

    main

    The Redis Operator provides a production-ready interface for managing Redis on Kubernetes with the following capabilities:

    • Deployment Modes: Setup for Redis cluster, replication, and standalone modes.
    • High Availability: Automated failover and recovery for Redis cluster and replication setups.
    • Security: Supports both password and password-less configurations, as well as TLS support for an additional security layer.
    • Networking: Support for both IPv4 and IPv6.
    • Monitoring: Built-in monitoring using redis-exporter and detailed Grafana dashboards.
  7. Handle immutable StatefulSet updates in Redis Standalone

    main
    When updating a Redis Standalone deployment, certain fields in the underlying Kubernetes StatefulSet (such as volumeClaimTemplates) are immutable. If you need to change these fields, set redisStandalone.recreateStatefulSetOnUpdateInvalid to true. This instructs the operator to delete the existing StatefulSet and recreate it to apply the changes. The default value is false.
  8. Understand Redis deployment models: Sharding vs Replication

    main

    The Redis Operator supports two primary deployment models: Standalone and Cluster. When using Cluster mode, the operator currently focuses on Sharded Cluster setups.

    Replication (Mirroring)

    In a replication model, data is mirrored from a leader node to follower nodes. Every node in the replication set contains a copy of the same data.

    Sharding (Partitioning)

    In a sharding model, data is split across multiple nodes based on keys. For example, Node A might hold keys 1 and 2, while Node B holds keys 3 and 4. This allows for horizontal scaling by distributing the data load across multiple machines.

  9. Available Redis Custom Resource Types

    main

    The Redis Operator extends the Kubernetes API using Custom Resource Definitions (CRDs). Once the operator is installed, you can manage Redis instances by creating resources under the API group redis.redis.opstreelabs.in/v1beta2.

    The following four object types are available for deployment and management:

    • Redis: For standalone Redis instances.
    • Redis Cluster: For Redis Cluster mode.
    • Redis Replication: For master-slave replication setups.
    • Redis Sentinel: For high-availability setups using Redis Sentinel.
  10. Configure monitoring with Prometheus

    main

    The operator provides built-in monitoring using redis-exporter. It uses the Prometheus service discovery pattern by applying specific annotations to the pods.

    To ensure Prometheus can scrape the metrics, the following annotations are used:

    • redis.opstreelabs.in: "true"
    • prometheus.io/scrape: "true"
    • prometheus.io/port: "9121"

    If you are using the Prometheus Operator, you can also deploy a ServiceMonitor for each Redis installation by configuring the appropriate values in your Helm values file.

      annotations:
        redis.opstreelabs.in: "true"
        prometheus.io/scrape: "true"
        prometheus.io/port: "9121"