|NO.Z.00261|——————————|CloudNative|——|KuberNetes&中间件容器化及helm.V08|——|中间件.v08|redis.v5.0.4|redis指定后端存储|

一、为redis集群指定后端存储
### --- 指定后端存储,持久化数据
~~~     修改后端存储配置文件

[root@k8s-master01 redis-cluster-operator]# more deploy/example/persistent.yaml 
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
  storage:
    type: persistent-claim
    size: 1Gi
    class: csi-rbd-sc           // 写storageclassname的名称即可
    deleteClaim: true
### --- 可以通过这个文件来建立持久化存储,建立后端存储
~~~     可以利用ceph或者外部存储系统即可

[root@k8s-master01 redis-cluster-operator]# kubectl create -f deploy/example/persistent.yaml
二、验证后端存储是否可以调用
### --- 准备redis集群的service

[root@k8s-master01 redis-cluster-operator]#  kubectl get svc
NAME                                TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)                      AGE
example-distributedrediscluster     ClusterIP      10.100.56.42     <none>          6379/TCP,16379/TCP           3m34s
example-distributedrediscluster-0   ClusterIP      None             <none>          6379/TCP,16379/TCP           3m34s
example-distributedrediscluster-1   ClusterIP      None             <none>          6379/TCP,16379/TCP           3m34s
example-distributedrediscluster-2   ClusterIP      None             <none>          6379/TCP,16379/TCP           3m34s
### --- 进入容器中
~~~     集群是有分片机制的,单节点创建的话直接可以创建,
~~~     但是集群是有分片机制的,会告诉你连接到那个实例上去创建

[root@k8s-master01 redis-cluster-operator]# kubectl exec -ti drc-example-distributedrediscluster-0-0 -- sh
/data # redis-cli -h example-distributedrediscluster
example-distributedrediscluster:6379> set a b
OK
example-distributedrediscluster:6379> get a
"b"
### --- 若是提示需要连接到那个实例上去创建,直接登录实例创建即可

~~~     注:假设应用程序是Java,或者go,或者PHP开发的,都有对应的redis集群的客户端工具,它会自动帮你去路由。
~~~     注:这里我们使用的是redis自己的客户端,需要手动的找到对应的片代码,然后连接到片的实例上,才能去创建这个key
~~~     注:查看的时候也需要找到对应的实例,然后才可以查看对应的value是值 
/data # redis-cli -h example-distributedrediscluster
example-distributedrediscluster:6379> set a b
(error) MOVED 15495 172.25.244.238:6379
/data # redis-cli -h 172.25.244.238
172.25.244.238:6379> set a b
OK
172.25.244.238:6379> get a
"b"

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on 2022-03-31 13:27  yanqi_vip  阅读(49)  评论(0)    收藏  举报

导航