Skip to content

Commit aa35d5b

Browse files
committed
update readme
1 parent 5a21456 commit aa35d5b

18 files changed

+427
-10
lines changed

README.md

Lines changed: 156 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,159 @@
22

33
## Overview
44

5-
Redis Cluster Operator setup a [Redis Cluster](https://redis.io/topics/cluster-spec) atop Kubernetes.
5+
Redis Cluster Operator manages [Redis Cluster](https://redis.io/topics/cluster-spec) atop Kubernetes.
6+
7+
The operator itself is built with the [Operator framework](https://github.com/operator-framework/operator-sdk).
8+
9+
![Redis Cluster atop Kubernetes](/static/redis-cluster.png)
10+
11+
## Prerequisites
12+
13+
* go version v1.12+.
14+
* Access to a Kubernetes v1.13.3 cluster.
15+
16+
## Features
17+
18+
- __Customize the number of master nodes and the number of replica nodes per master__
19+
20+
- __Password__
21+
22+
- __Safely Scaling the Redis Cluster__
23+
24+
- __Backup and Restore__
25+
26+
- __Persistent Volume__
27+
28+
- __Custom Configuration__
29+
30+
- __Prometheus Discovery__
31+
32+
33+
## Quick Start
34+
35+
### Deploy redis cluster operator
36+
37+
Register the DistributedRedisCluster and RedisClusterBackup custom resource definition (CRD).
38+
```
39+
$ kubectl create -f deploy/crds/redis.kun_distributedredisclusters_crd.yaml
40+
$ kubectl create -f deploy/crds/redis.kun_redisclusterbackups_crd.yaml
41+
```
42+
43+
A namespace-scoped operator watches and manages resources in a single namespace, whereas a cluster-scoped operator watches and manages resources cluster-wide.
44+
You can chose run your operator as namespace-scoped or cluster-scoped.
45+
```
46+
// cluster-scoped
47+
$ kubectl create -f deploy/service_account.yaml
48+
$ kubectl create -f deploy/cluster/cluster_role.yaml
49+
$ kubectl create -f deploy/cluster/cluster_role_binding.yaml
50+
$ kubectl create -f deploy/cluster/operator.yaml
51+
52+
// namespace-scoped
53+
$ kubectl create -f deploy/service_account.yaml
54+
$ kubectl create -f deploy/namespace/role.yaml
55+
$ kubectl create -f deploy/namespace/role_binding.yaml
56+
$ kubectl create -f deploy/namespace/operator.yaml
57+
```
58+
59+
Verify that the redis-cluster-operator is up and running:
60+
```
61+
$ kubectl get deployment
62+
NAME READY UP-TO-DATE AVAILABLE AGE
63+
redis-cluster-operator 1/1 1 1 1d
64+
```
65+
66+
#### Deploy a sample Redis Cluster
67+
68+
```
69+
$ kubectl apply -f deploy/example/redis.kun_v1alpha1_distributedrediscluster_cr.yaml
70+
```
71+
72+
Verify that the cluster instances and its components are running.
73+
```
74+
$ kubectl get distributedrediscluster
75+
NAME MASTERSIZE STATUS AGE
76+
example-distributedrediscluster 3 Scaling 11s
77+
78+
$ kubectl get all -l redis.kun/name=example-distributedrediscluster
79+
NAME READY STATUS RESTARTS AGE
80+
pod/drc-example-distributedrediscluster-0 1/1 Running 0 4m5s
81+
pod/drc-example-distributedrediscluster-1 1/1 Running 0 3m31s
82+
pod/drc-example-distributedrediscluster-2 1/1 Running 0 2m54s
83+
pod/drc-example-distributedrediscluster-3 1/1 Running 0 2m20s
84+
pod/drc-example-distributedrediscluster-4 1/1 Running 0 103s
85+
pod/drc-example-distributedrediscluster-5 1/1 Running 0 62s
86+
87+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
88+
service/example-distributedrediscluster ClusterIP None <none> 6379/TCP,16379/TCP 4m5s
89+
90+
NAME READY AGE
91+
statefulset.apps/drc-example-distributedrediscluster 6/6 4m5s
92+
93+
$ kubectl get distributedrediscluster
94+
NAME MASTERSIZE STATUS AGE
95+
example-distributedrediscluster 3 Healthy 4m
96+
```
97+
98+
#### Scaling the Redis Cluster
99+
100+
Increase the masterSize to trigger the scaling.
101+
102+
```
103+
apiVersion: redis.kun/v1alpha1
104+
kind: DistributedRedisCluster
105+
metadata:
106+
name: example-distributedrediscluster
107+
spec:
108+
# Increase the masterSize to trigger the scaling.
109+
masterSize: 4
110+
ClusterReplicas: 1
111+
image: redis:5.0.4-alpine
112+
```
113+
114+
#### Backup and Restore
115+
116+
Backup
117+
```
118+
$ kubectl create -f deploy/example/backup-restore/redisclusterbackup_cr.yaml
119+
```
120+
121+
Restore from backup
122+
```
123+
$ kubectl create -f deploy/example/backup-restore/restore.yaml
124+
```
125+
126+
#### Prometheus Discovery
127+
128+
```
129+
$ kubectl create -f deploy/example/prometheus-exporter.yaml
130+
```
131+
132+
#### Create Redis Cluster with password
133+
134+
```
135+
$ kubectl create -f deploy/example/custom-password.yaml
136+
```
137+
138+
#### Persistent Volume
139+
140+
```
141+
$ kubectl create -f deploy/example/persistent.yaml
142+
```
143+
144+
#### Custom Configuration
145+
146+
```
147+
$ kubectl create -f deploy/example/custom-config.yaml
148+
```
149+
150+
#### Custom Headless Service
151+
152+
```
153+
$ kubectl create -f deploy/example/custom-service.yaml
154+
```
155+
156+
#### Custom Resource
157+
158+
```
159+
$ kubectl create -f deploy/example/custom-resources.yaml
160+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kind: ClusterRoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: redis-cluster-operator
5+
subjects:
6+
- kind: ServiceAccount
7+
name: redis-cluster-operator
8+
namespace: default
9+
roleRef:
10+
kind: ClusterRole
11+
name: redis-cluster-operator
12+
apiGroup: rbac.authorization.k8s.io

deploy/cluster/operator.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: redis-cluster-operator
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
name: redis-cluster-operator
10+
template:
11+
metadata:
12+
labels:
13+
name: redis-cluster-operator
14+
spec:
15+
serviceAccountName: redis-cluster-operator
16+
containers:
17+
- name: redis-cluster-operator
18+
# Replace this with the built image name
19+
image: uhub.service.ucloud.cn/operator/redis-cluster-operator:latest
20+
command:
21+
- redis-cluster-operator
22+
imagePullPolicy: Always
23+
env:
24+
- name: WATCH_NAMESPACE
25+
value: ""
26+
- name: POD_NAME
27+
valueFrom:
28+
fieldRef:
29+
fieldPath: metadata.name
30+
- name: OPERATOR_NAME
31+
value: "redis-cluster-operator"

deploy/crds/redis.kun_v1alpha1_redisclusterbackup_cr.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v1
2+
data:
3+
AWS_ACCESS_KEY_ID: dGVzdA==
4+
AWS_SECRET_ACCESS_KEY: dGVzdA==
5+
kind: Secret
6+
metadata:
7+
name: s3-secret
8+
type: Opaque
9+
---
10+
apiVersion: redis.kun/v1alpha1
11+
kind: RedisClusterBackup
12+
metadata:
13+
name: example-redisclusterbackup
14+
spec:
15+
image: uhub.service.ucloud.cn/operator/redis-tools:5.0.4
16+
redisClusterName: example-distributedrediscluster
17+
storageSecretName: s3-secret
18+
# Replace this with the s3 info
19+
s3:
20+
endpoint: REPLACE_ENDPOINT
21+
bucket: REPLACE_BUCKET
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: redis.kun/v1alpha1
2+
kind: DistributedRedisCluster
3+
metadata:
4+
name: example-restore
5+
spec:
6+
init:
7+
backupSource:
8+
name: example-redisclusterbackup
9+
namespace: default

deploy/example/custom-config.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: redis.kun/v1alpha1
2+
kind: DistributedRedisCluster
3+
metadata:
4+
name: example-distributedrediscluster
5+
spec:
6+
image: uhub.service.ucloud.cn/operator/redis:5.0.4-alpine
7+
masterSize: 3
8+
clusterReplicas: 1
9+
config:
10+
activerehashing: "yes"
11+
appendfsync: everysec
12+
appendonly: "yes"
13+
hash-max-ziplist-entries: "512"
14+
hash-max-ziplist-value: "64"
15+
hll-sparse-max-bytes: "3000"
16+
list-compress-depth: "0"
17+
maxmemory-policy: noeviction
18+
maxmemory-samples: "5"
19+
no-appendfsync-on-rewrite: "no"
20+
notify-keyspace-events: ""
21+
set-max-intset-entries: "512"
22+
slowlog-log-slower-than: "10000"
23+
slowlog-max-len: "128"
24+
stop-writes-on-bgsave-error: "yes"
25+
tcp-keepalive: "0"
26+
timeout: "0"
27+
zset-max-ziplist-entries: "128"
28+
zset-max-ziplist-value: "64"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: mysecret
5+
type: Opaque
6+
data:
7+
password: MWYyZDFlMmU2N2Rm
8+
---
9+
apiVersion: redis.kun/v1alpha1
10+
kind: DistributedRedisCluster
11+
metadata:
12+
name: example-distributedrediscluster
13+
spec:
14+
image: uhub.service.ucloud.cn/operator/redis:5.0.4-alpine
15+
masterSize: 3
16+
clusterReplicas: 1
17+
rootPasswordSecret:
18+
name: mysecret
19+
resources:
20+
limits:
21+
cpu: 200m
22+
memory: 200Mi
23+
requests:
24+
cpu: 200m
25+
memory: 100Mi
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: redis.kun/v1alpha1
2+
kind: DistributedRedisCluster
3+
metadata:
4+
name: example-distributedrediscluster
5+
spec:
6+
image: uhub.service.ucloud.cn/operator/redis:5.0.4-alpine
7+
masterSize: 3
8+
clusterReplicas: 1
9+
resources:
10+
limits:
11+
cpu: 200m
12+
memory: 200Mi
13+
requests:
14+
cpu: 200m
15+
memory: 100Mi

0 commit comments

Comments
 (0)