黄东旭解析 TiDB 的核心优势
1526
2023-05-27
Kubernetes生产实践之Redis-cluster
方案一 自定义yaml文件安装redis cluster
背景
在Kubernetes中部署Redis集群面临挑战,因为每个Redis实例都依赖于一个配置文件,该文件可以跟踪其他集群实例及其角色。为此,需要结合使用Kubernetes StatefulSets和PersistentVolumes实现。
redis cluster架构示意图:
创建StatefulSet yaml文件
注释:
cluster-migration-barrier 那些分配后仍然剩余migration barrier个从节点的主节点才会触发节点分配,而不是分配前有migration barrier个从节点的主节点就会触发节点分配,默认是1,生产环境建议维持默认值 protected-mode no 参数是为了禁止外网访问redis,如果启用了,则只能够通过lookback ip(127.0.0.1)访问Redis,如果外网访问redis,会报出异常。 apiVersion: apps.kruise.io/v1beta1 控制器这里使用kruise提供的Advanced StatefulSet,如果集群没有安装kruise,可以使用 apps/v1
安装redis-cluster
[root@qd01-stop-k8s-master001 redis]# kubectl apply -f install-redis.yaml configmap/redis-cluster created statefulset.apps.kruise.io/redis-cluster created [root@qd01-stop-k8s-master001 redis]# kubectl get po -n op NAME READY STATUS RESTARTS AGE redis-cluster-0 1/1 Running 0 3m26s redis-cluster-1 1/1 Running 0 3m14s redis-cluster-2 1/1 Running 0 2m54s redis-cluster-3 1/1 Running 0 2m23s redis-cluster-4 1/1 Running 0 2m14s redis-cluster-5 1/1 Running 0 114s
创建redis-cluster service
--- apiVersion: v1 kind: Service metadata: name: redis-cluster namespace: op spec: type: ClusterIP ports: - port: 6379 targetPort: 6379 name: client - port: 16379 targetPort: 16379 name: gossip selector: app: redis-cluster
[root@qd01-stop-k8s-master001 redis]# kubectl apply -f redis-svc.yml service/redis-cluster created [root@qd01-stop-k8s-master001 redis]# kubectl get svc -n op NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE redis-cluster ClusterIP 10.97.197.224
初始化redis-cluster
执行如下命令,获取到pod IP,然后使用redis-cli --cluster创建集群
[root@qd01-stop-k8s-master001 redis]# kubectl -n op exec -it redis-cluster-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl -n op get pods -l app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379 {end}') >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 100.88.43.67:6379 to 100.64.147.152:6379 Adding replica 100.113.170.5:6379 to 100.98.174.217:6379 Adding replica 100.64.147.153:6379 to 100.80.158.227:6379 M: b47b27a3dbddf3fc1370cbe14ae753f4fce20b04 100.64.147.152:6379 slots:[0-5460] (5461 slots) master M: 09543217c903350e963fc4fdf4acb73f8a1b7f8b 100.98.174.217:6379 slots:[5461-10922] (5462 slots) master M: 5389ace495b68eeac85370d6783648dff68f2fb6 100.80.158.227:6379 slots:[10923-16383] (5461 slots) master S: b1f39714c006ae55b12b18e6537303d7a00e1704 100.64.147.153:6379 replicates 5389ace495b68eeac85370d6783648dff68f2fb6 S: 0113f4668ec2f3ca2e9470c44bd5faab532b0936 100.88.43.67:6379 replicates b47b27a3dbddf3fc1370cbe14ae753f4fce20b04 S: e1e2f18ae66c79f1943390beabb59613abbad38a 100.113.170.5:6379 replicates 09543217c903350e963fc4fdf4acb73f8a1b7f8b Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join .. >>> Performing Cluster Check (using node 100.64.147.152:6379) M: b47b27a3dbddf3fc1370cbe14ae753f4fce20b04 100.64.147.152:6379 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 0113f4668ec2f3ca2e9470c44bd5faab532b0936 100.88.43.67:6379 slots: (0 slots) slave replicates b47b27a3dbddf3fc1370cbe14ae753f4fce20b04 M: 09543217c903350e963fc4fdf4acb73f8a1b7f8b 100.98.174.217:6379 slots:[5461-10922] (5462 slots) master 1 additional replica(s) M: 5389ace495b68eeac85370d6783648dff68f2fb6 100.80.158.227:6379 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: e1e2f18ae66c79f1943390beabb59613abbad38a 100.113.170.5:6379 slots: (0 slots) slave replicates 09543217c903350e963fc4fdf4acb73f8a1b7f8b S: b1f39714c006ae55b12b18e6537303d7a00e1704 100.64.147.153:6379 slots: (0 slots) slave replicates 5389ace495b68eeac85370d6783648dff68f2fb6 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
验证集群信息
[root@qd01-stop-k8s-master001 redis]# kubectl -n op exec -it redis-cluster-0 -- redis-cli cluster info cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_ping_sent:178 cluster_stats_messages_pong_sent:181 cluster_stats_messages_sent:359 cluster_stats_messages_ping_received:176 cluster_stats_messages_pong_received:178 cluster_stats_messages_meet_received:5 cluster_stats_messages_received:359 [root@qd01-stop-k8s-master001 redis]# kubectl -n op exec -it redis-cluster-0 -- redis-cli cluster nodes 0113f4668ec2f3ca2e9470c44bd5faab532b0936 100.88.43.67:6379@16379 slave b47b27a3dbddf3fc1370cbe14ae753f4fce20b04 0 1615348311156 1 connected 09543217c903350e963fc4fdf4acb73f8a1b7f8b 100.98.174.217:6379@16379 master - 0 1615348314162 2 connected 5461-10922 b47b27a3dbddf3fc1370cbe14ae753f4fce20b04 100.64.147.152:6379@16379 myself,master - 0 1615348312000 1 connected 0-5460 5389ace495b68eeac85370d6783648dff68f2fb6 100.80.158.227:6379@16379 master - 0 1615348312000 3 connected 10923-16383 e1e2f18ae66c79f1943390beabb59613abbad38a 100.113.170.5:6379@16379 slave 09543217c903350e963fc4fdf4acb73f8a1b7f8b 0 1615348313160 2 connected b1f39714c006ae55b12b18e6537303d7a00e1704 100.64.147.153:6379@16379 slave 5389ace495b68eeac85370d6783648dff68f2fb6 0 1615348312158 3 connected
从输出可以看到,集群总共6个节点,三主三从
方案二 使用kubeDB安装redis
安装kubeDB
1、安装KubeDB
获取AppsCode License
下载KubeDB charts
2、使用helm安装
3、安装KubeDB Catalog
同样,先下载
[root@qd01-stop-k8s-master001 kubedb-catalog]# tar -zxf kubedb-catalog-v0.16.2.tgz [root@qd01-stop-k8s-master001 kubedb-catalog]# cd kubedb-catalog [root@qd01-stop-k8s-master001 kubedb-catalog]# ls -al total 24 drwxr-xr-x 3 root root 148 Mar 10 15:48 . drwxr-xr-x 3 root root 28 Mar 10 15:48 .. -rw-r--r-- 1 root root 321 Jan 26 20:08 Chart.yaml -rw-r--r-- 1 root root 467 Jan 26 20:08 doc.yaml -rw-r--r-- 1 root root 353 Jan 26 20:08 .helmignore -rw-r--r-- 1 root root 3195 Jan 26 20:08 README.md drwxr-xr-x 12 root root 188 Mar 10 15:48 templates -rw-r--r-- 1 root root 744 Jan 26 20:08 values.openapiv3_schema.yaml -rw-r--r-- 1 root root 1070 Jan 26 20:08 values.yaml [root@qd01-stop-k8s-master001 kubedb-catalog]# helm install kubedb-catalog --namespace kube-system -f values.yaml . NAME: kubedb-catalog LAST DEPLOYED: Wed Mar 10 15:50:50 2021 NAMESPACE: kube-system STATUS: deployed REVISION: 1 TEST SUITE: None
使用kubedb安装redis
1、先看下官方给的redis生命周期示意图
kubedb安装redis支持如下特性
Features Availability Clustering ✓ Instant Backup ✗ Scheduled Backup ✗ Persistent Volume ✓ Initialize using Snapshot ✗ Initialize using Script ✗ Custom Configuration ✓ Using Custom docker image ✓ Builtin Prometheus Discovery ✓ Using Prometheus operator ✓
2、查看支持的版本
[root@qd01-stop-k8s-master001 kubedb-catalog]# kubectl get redisversions NAME VERSION DB_IMAGE DEPRECATED AGE 4.0.11 4.0.11 kubedb/redis:4.0.11 15m 4.0.6-v2 4.0.6 kubedb/redis:4.0.6-v2 15m 5.0.3-v1 5.0.3 kubedb/redis:5.0.3-v1 15m 6.0.6 6.0.6 kubedb/redis:6.0.6 15m
3、编辑yaml安装文件
可以参照
这里选择安装6.0.6这个版本,我的集群storageClassName: "rbd",请根据实际修改
如果想自定义redis.conf,请参考
执行安装
4、验证集群
【编辑推荐】
凉凉,老板叫我开发一个简单的工作流引擎...Windows10将迎来翻天覆地变化!今年第一个更新来了2021年将迎来六大网络安全趋势Windows 10近年最大改进!Windows10 21H2新特性抢先看小爱同学竟然推出了PC版?带你体验电脑版小爱
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。