• Stars
    star
    381
  • Rank 112,502 (Top 3 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Redis Cluster Operator creates and manages Redis Clusters atop Kubernetes.

redis-cluster-operator

Overview

Redis Cluster Operator manages Redis Cluster atop Kubernetes.

The operator itself is built with the Operator framework.

Redis Cluster atop Kubernetes

Each master node and its slave nodes is managed by a statefulSet, create a headless svc for each statefulSet, and create a clusterIP service for all nodes.

Each statefulset uses PodAntiAffinity to ensure that the master and slaves are dispersed on different nodes. At the same time, when the operator selects the master in each statefulset, it preferentially select the pod with different k8s nodes as master.

Table of Contents

Prerequisites

  • go version v1.13+.
  • Access to a Kubernetes v1.13.10 cluster.

Features

  • Customize the number of master nodes and the number of replica nodes per master

  • Password

  • Safely Scaling the Redis Cluster

  • Backup and Restore

  • Persistent Volume

  • Custom Configuration

  • Prometheus Discovery

Quick Start

Deploy redis cluster operator

Install Step by step

Register the DistributedRedisCluster and RedisClusterBackup custom resource definition (CRD).

$ kubectl create -f deploy/crds/redis.kun_distributedredisclusters_crd.yaml
$ kubectl create -f deploy/crds/redis.kun_redisclusterbackups_crd.yaml

A namespace-scoped operator watches and manages resources in a single namespace, whereas a cluster-scoped operator watches and manages resources cluster-wide. You can chose run your operator as namespace-scoped or cluster-scoped.

// cluster-scoped
$ kubectl create -f deploy/service_account.yaml
$ kubectl create -f deploy/cluster/cluster_role.yaml
$ kubectl create -f deploy/cluster/cluster_role_binding.yaml
$ kubectl create -f deploy/cluster/operator.yaml

// namespace-scoped
$ kubectl create -f deploy/service_account.yaml
$ kubectl create -f deploy/namespace/role.yaml
$ kubectl create -f deploy/namespace/role_binding.yaml
$ kubectl create -f deploy/namespace/operator.yaml

Install using helm chart

Add Helm repository

helm repo add ucloud-operator https://ucloud.github.io/redis-cluster-operator/
helm repo update

Install chart

helm install --generate-name ucloud-operator/redis-cluster-operator

Verify that the redis-cluster-operator is up and running:

$ kubectl get deployment
NAME                     READY   UP-TO-DATE   AVAILABLE   AGE
redis-cluster-operator   1/1     1            1           1d

Usage

Deploy a sample Redis Cluster

NOTE: Only the redis cluster that use persistent storage(pvc) can recover after accidental deletion or rolling update.Even if you do not use persistence(like rdb or aof), you need to set pvc for redis.

$ kubectl apply -f deploy/example/redis.kun_v1alpha1_distributedrediscluster_cr.yaml

Verify that the cluster instances and its components are running.

$ kubectl get distributedrediscluster
NAME                              MASTERSIZE   STATUS    AGE
example-distributedrediscluster   3            Scaling   11s

$ kubectl get all -l redis.kun/name=example-distributedrediscluster
NAME                                          READY   STATUS    RESTARTS   AGE
pod/drc-example-distributedrediscluster-0-0   1/1     Running   0          2m48s
pod/drc-example-distributedrediscluster-0-1   1/1     Running   0          2m8s
pod/drc-example-distributedrediscluster-1-0   1/1     Running   0          2m48s
pod/drc-example-distributedrediscluster-1-1   1/1     Running   0          2m13s
pod/drc-example-distributedrediscluster-2-0   1/1     Running   0          2m48s
pod/drc-example-distributedrediscluster-2-1   1/1     Running   0          2m15s

NAME                                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
service/example-distributedrediscluster     ClusterIP   172.17.132.71   <none>        6379/TCP,16379/TCP   2m48s
service/example-distributedrediscluster-0   ClusterIP   None            <none>        6379/TCP,16379/TCP   2m48s
service/example-distributedrediscluster-1   ClusterIP   None            <none>        6379/TCP,16379/TCP   2m48s
service/example-distributedrediscluster-2   ClusterIP   None            <none>        6379/TCP,16379/TCP   2m48s

NAME                                                     READY   AGE
statefulset.apps/drc-example-distributedrediscluster-0   2/2     2m48s
statefulset.apps/drc-example-distributedrediscluster-1   2/2     2m48s
statefulset.apps/drc-example-distributedrediscluster-2   2/2     2m48s

$ kubectl get distributedrediscluster
NAME                              MASTERSIZE   STATUS    AGE
example-distributedrediscluster   3            Healthy   4m

Scaling Up the Redis Cluster

Increase the masterSize to trigger the scaling up.

apiVersion: redis.kun/v1alpha1
kind: DistributedRedisCluster
metadata:
  annotations:
    # if your operator run as cluster-scoped, add this annotations
    redis.kun/scope: cluster-scoped
  name: example-distributedrediscluster
spec:
  # Increase the masterSize to trigger the scaling.
  masterSize: 4
  ClusterReplicas: 1
  image: redis:5.0.4-alpine

Scaling Down the Redis Cluster

Decrease the masterSize to trigger the scaling down.

apiVersion: redis.kun/v1alpha1
kind: DistributedRedisCluster
metadata:
  annotations:
    # if your operator run as cluster-scoped, add this annotations
    redis.kun/scope: cluster-scoped
  name: example-distributedrediscluster
spec:
  # Increase the masterSize to trigger the scaling.
  masterSize: 3
  ClusterReplicas: 1
  image: redis:5.0.4-alpine

Backup and Restore

NOTE: Only Ceph S3 object storage and PVC is supported now

Backup

$ kubectl create -f deploy/example/backup-restore/redisclusterbackup_cr.yaml

Restore from backup

$ kubectl create -f deploy/example/backup-restore/restore.yaml

Prometheus Discovery

$ kubectl create -f deploy/example/prometheus-exporter.yaml

Create Redis Cluster with password

$ kubectl create -f deploy/example/custom-password.yaml

Persistent Volume

$ kubectl create -f deploy/example/persistent.yaml

Custom Configuration

$ kubectl create -f deploy/example/custom-config.yaml

Custom Service

$ kubectl create -f deploy/example/custom-service.yaml

Custom Resource

$ kubectl create -f deploy/example/custom-resources.yaml

ValidatingWebhook

see ValidatingWebhook

End to end tests

see e2e

More Repositories

1

redis-operator

Redis operator build a Highly Available Redis cluster with Sentinel atop Kubernetes
Go
214
star
2

ucloud-cli

UCloud Command Line Interface
Go
98
star
3

ucloud-sdk-go

UCloud SDK for Golang
Go
83
star
4

terraform-provider-ucloud

Terraform is an awesome tool to implement Infrastructure as Code and GitOps
Go
68
star
5

netanalysis-sdk-android

UCloud NetAnalysis SDK for Android
Java
42
star
6

ucloud-sdk-python3

UCloud SDK for Python
Python
37
star
7

uai-sdk

UCloud AI SDK
Python
33
star
8

ufile-sdk-java

UCloud 对象存储官方 SDK
Java
29
star
9

netanalysis-sdk-ios

UCloud NetAnalysis SDK for iOS
Objective-C
28
star
10

ucloud-sdk-python

[DEPRICATED] python sdk for ucloud api
Python
27
star
11

ucloud-toa

A kernel module to obtain source IPv4 address in the TCP option section.
C
21
star
12

ufile-sdk-python

This is an UFile(OSS) SDK for Python from UCloud
Python
20
star
13

ucloud-sdk-java

UCloud SDK for Java
Java
19
star
14

ucloud-sdk-python2

Python
18
star
15

urtc-android-demo

urtc android 端demo
Java
14
star
16

terraform-provider-ucloud-old

(Deprecated) Please see official repository https://github.com/terraform-providers/terraform-provider-ucloud
Go
12
star
17

urtc-sdk-web

URTC(UCloud实时音视频)web SDK
11
star
18

docker-machine-ucloud

docker machine driver for UCloud
Go
10
star
19

ucloud-developer-tools

The landscape of UCloud Developer Tools
9
star
20

ufile-sdk-ios

UCloud 对象存储官方 SDK
Objective-C
8
star
21

ucloud-sdk-php

UCloud SDK for PHP
PHP
8
star
22

urtc-js-demo

urtc js 端demo,demo网址:https://demo.urtc.com.cn/
JavaScript
7
star
23

ufile-sdk-android

UCloud 对象存储官方 SDK
Java
7
star
24

urtc-ios-demo

urtc ios 端demo
HTML
7
star
25

ucloud-iot-rtthread-package

基于RT-Thread操作系统用于快速连接uiot-core的软件包
C
6
star
26

mutualaid

JavaScript
6
star
27

packer-plugin-ucloud

Packer plugin for UCloud Image Builder
Go
6
star
28

ucloud-iot-device-sdk-c

UCloud UIoT-Core设备端C-SDK
C
5
star
29

uk8s-cni-vpc

The underlay container networking plugin for UK8S based on UVPC.
Go
5
star
30

uai-saas-sdk

UCloud AI SaaS SDK
Python
4
star
31

ufile-sdk-auth-server

Java
4
star
32

pulumi-ucloud

Pulumi is a cloud-native development kit to implement Infrastructure as Software
Python
4
star
33

stepflow-stepo

UCloud StepFlow function template
Python
4
star
34

uk8s-demo

3
star
35

urtc-electron-demo

urtc electron demo
C++
3
star
36

uma

JavaScript
3
star
37

urtc-web-demo

JavaScript
3
star
38

ugc-sdk

sdk for ucloud ugc
C++
2
star
39

urtc-win-demo

urtc windows 端demo
C++
2
star
40

urtc-linux-demo

C++
2
star
41

httpdns-sdk-android

Java
1
star
42

ucloud-developer-examples

The examples for developer
Go
1
star
43

ubox-auto-sdk-web

Web SDK for use ubox auto
TypeScript
1
star
44

umon_webhook

HTML
1
star
45

uiotedge-driver-sdk-c

C
1
star
46

uphone-android-sdk

1
star
47

uai-sdk-httpserver

Http Server designed for UAI-SDK task based on Flask
Python
1
star
48

urtc-mac-demo

HTML
1
star
49

ularm-monitor-subscribe-demo

Go
1
star
50

urtc-edu-demo

JavaScript
1
star
51

ubox-publisher

RTMP stream publisher with hardware accel
C
1
star
52

unvs-android-sdk

Java
1
star
53

iotstack-driver-sdk-c

C
1
star
54

go-lockfile

A Linux go library to lock cooperating processes based on syscall `flock`
Go
1
star
55

ucloud-sdk-python-3.0

ucloud-sdk-python-3.0
Python
1
star
56

ucloud-sdk-js

UCloud SDK for Node.js
TypeScript
1
star