一、Operator
https://github.com/operator-framework/awesome-operators
二、安装Redis集群的operator
# git clone https://github.com/ucloud/redis-cluster-operator.git # kubectl create -f deploy/crds/redis.kun_distributedredisclusters_crd.yaml # kubectl create -f deploy/crds/redis.kun_redisclusterbackups_crd.yaml
以集群模式安装
# 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.yam
可以在service_account和 operator后面加-n 参数指定namespace
三、创建redis集群
kubectl apply -f deploy/example/redis.kun_v1alpha1_distributedrediscluster_cr.yaml
这个yaml文件中使用的资源较高,测试环境可能起不来,可以换一个
kubectl create -f deploy/example/custom-resources.yaml
查看Pod
# kubectl get pods NAME READY STATUS RESTARTS AGE drc-example-distributedrediscluster-0-0 1/1 Running 0 3m33s drc-example-distributedrediscluster-0-1 1/1 Running 0 2m59s drc-example-distributedrediscluster-1-0 1/1 Running 0 3m33s drc-example-distributedrediscluster-1-1 1/1 Running 0 2m54s drc-example-distributedrediscluster-2-0 1/1 Running 0 3m33s drc-example-distributedrediscluster-2-1 1/1 Running 0 2m59s
通过节点 亲和性,确保redis分布在不同节点上
查看service
# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE example-distributedrediscluster ClusterIP 10.106.160.212 <none> 6379/TCP,16379/TCP 4m14s example-distributedrediscluster-0 ClusterIP None <none> 6379/TCP,16379/TCP 4m15s example-distributedrediscluster-1 ClusterIP None <none> 6379/TCP,16379/TCP 4m15s example-distributedrediscluster-2 ClusterIP None <none> 6379/TCP,16379/TCP 4m15s
应用程序
四、自定义Redis集群配置
custom-redis.yaml
apiVersion: v1
kind: Secret
metadata:
annotations:
# if your operator run as cluster-scoped, add this annotations
redis.kun/scope: cluster-scoped
name: mysecret
type: Opaque
data:
password: MWYyZDFlMmU2N2Rm
---
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:
image: redis:5.0.4-alpine
masterSize: 3
clusterReplicas: 1
passwordSecret:
name: mysecret
resources:
limits:
cpu: 200m
memory: 200Mi
requests:
cpu: 200m
memory: 100Mi
storage:
type: persistent-claim
size: 1Gi
class: rook-ceph-block
deleteClaim: true
修改时区
# kubectl get sts NAME READY AGE drc-example-distributedrediscluster-0 2/2 80m drc-example-distributedrediscluster-1 2/2 80m drc-example-distributedrediscluster-2 2/2 80m
修改statefulset,volumeMounts和volumes
省略其他配置信息
volumeMounts:
- mountPath: /usr/share/zoneinfo/Asia/Shanghai
name: tz-config
- mountPath: /etc/localtime
name: tz-config
volumes:
- hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
type: ""
name: tz-config
查看
kubectl exec -it drc-example-distributedrediscluster-0-1 -- date Thu Oct 29 16:45:50 CST 2020 redis-cli -a 1f2d1e2e67df