[root@nfs ~]# yum install nfs-utils -y
[root@nfs ~]# systemctl restart nfs
[root@nfs ~]# systemctl enable nfs
[root@k8s-master01 ~]# yum install nfs-utils -y
for x in $(seq 1 6);
> do
> mkdir -p /data/redis-cluster/pv${x}
> done
[root@master ~]# vim /etc/exports
/data/redis-cluster/pv1 192.168.158.0/24(rw,no_root_squash)
/data/redis-cluster/pv2 192.168.158.0/24(rw,no_root_squash)
/data/redis-cluster/pv3 192.168.158.0/24(rw,no_root_squash)
/data/redis-cluster/pv4 192.168.158.0/24(rw,no_root_squash)
/data/redis-cluster/pv5 192.168.158.0/24(rw,no_root_squash)
/data/redis-cluster/pv6 192.168.158.0/24(rw,no_root_squash)
3. 创建6个pv,kubectl apply -f redis-pv.yaml,下面为redis-pv.yaml内容:
apiVersion: v1
kind: PersistentVolume # 创建pv
metadata:
name: redis-pv1 # 名称
spec:
capacity:
storage: 3Gi # 3G磁盘空间
accessModes:
- ReadWriteOnce # 权限读写
persistentVolumeReclaimPolicy: Recycle # 回收策略,清除数据
storageClassName: "redis-cluster" # 存储类别为“redis-cluster”,只能允许存储类别相同的pvc使用
nfs:
path: /data/redis-cluster/pv1
server: 192.168.158.136
# ...
# 中间省略一直到redis-pv6 修改metadata:name 和 spec:nfs:path即可。
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: redis-pv6
spec:
capacity:
storage: 3Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: "redis-cluster"
nfs:
path: /data/redis-cluster/pv6
server: 192.168.158.136
[root@master ~]# kubectl apply -f redis-pv.yaml
[root@master ~]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
redis-pv1 3Gi RWO Recycle Bound default/data-redis-cluster-0 redis-cluster 115m
redis-pv2 3Gi RWO Recycle Bound default/data-redis-cluster-2 redis-cluster 115m
redis-pv3 3Gi RWO Recycle Bound default/data-redis-cluster-3 redis-cluster 115m
redis-pv4 3Gi RWO Recycle Bound default/data-redis-cluster-4 redis-cluster 115m
redis-pv5 3Gi RWO Recycle Bound default/data-redis-cluster-1 redis-cluster 115m
redis-pv6 3Gi RWO Recycle Bound default/data-redis-cluster-5 redis-cluster 115m
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-cluster
data:
update-node.sh: |
#!/bin/sh
REDIS_NODES="/data/nodes.conf"
sed -i -e "/myself/ s/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/${POD_IP}/" ${REDIS_NODES}
exec "$@"
redis.conf: |+
cluster-enabled yes
cluster-require-full-coverage no
cluster-node-timeout 15000
cluster-config-file /data/nodes
cluster-migration-barrier 1
Maxmemory 3GB
port 6379
appendonly yes
protected-mode no
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-cluster
spec:
serviceName: redis-cluster
replicas: 6
selector: # 标签选择器
matchLabels:
app: redis-cluster
template: # pod创建模板
metadata:
labels:
app: redis-cluster
spec:
containers:
- name: redis
image: redis:5.0.5-alpine
ports:
- containerPort: 6379
name: client
- containerPort: 16379
name: gossip
command: ["/conf/update-node.sh", "redis-server", "/conf/redis.conf"]
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
volumeMounts:
- name: conf
mountPath: /conf
readOnly: false
- name: data
mountPath: /data
readOnly: false
volumes:
- name: conf
configMap:
name: redis-cluster
defaultMode: 0755
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 3Gi
storageClassName: redis-cluster YAML
[root@master ~]# kubectl apply -f redis-StatefulSets.yaml
# 查看
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-58777cc9fd-cwj77 1/1 Running 1 29h
redis-cluster-0 1/1 Running 0 76m
redis-cluster-1 1/1 Running 0 76m
redis-cluster-2 1/1 Running 0 76m
redis-cluster-3 1/1 Running 0 75m
redis-cluster-4 1/1 Running 0 74m
redis-cluster-5 1/1 Running 0 74m
---
apiVersion: v1
kind: Service
metadata:
name: redis-cluster
spec:
type: ClusterIP # 集群内部机器可访问,如需要集群外部访问,将类型改为NodePort即可
clusterIP: 10.96.97.97 # 不写会自己分配
ports:
- port: 6379
targetPort: 6379
name: client
- port: 16379
targetPort: 16379
name: gossip
selector:
app: redis-cluster
[root@master ~]# kubectl apply -f redis-svc.yaml
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
redis-cluster ClusterIP 10.96.97.97 6379/TCP,16379/TCP 124m
kubectl exec -it redis-cluster-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -l app=redis-cluster -o jsonpath={range.items[*]}{.status.podIP}:6379 )
[root@master ~]# kubectl exec -it redis-cluster-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -l app=redis-cluster -o jsonpath={range.items[*]}{.status.podIP}:6379 )
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 10.244.2.10:6379 to 10.244.2.8:6379
Adding replica 10.244.1.10:6379 to 10.244.1.8:6379
Adding replica 10.244.1.9:6379 to 10.244.2.9:6379
M: aaf12abf3906e40d7c1084fa7228e99a49fc02df 10.244.2.8:6379
slots:[0-5460] (5461 slots) master
M: 547619c817623c71502e52413e46bf33bfb307bc 10.244.1.8:6379
slots:[5461-10922] (5462 slots) master
M: cd3abc406759315a814820dc0a6ce53b93a919a8 10.244.2.9:6379
slots:[10923-16383] (5461 slots) master
S: b0e40a1d30b397bacefd0f4c4d8584246ce52fc6 10.244.1.9:6379
replicates cd3abc406759315a814820dc0a6ce53b93a919a8
S: d8f1a35fc156598c4d9871a607f2639206072782 10.244.2.10:6379
replicates aaf12abf3906e40d7c1084fa7228e99a49fc02df
S: 372b0086cccdcdea81be571df557b958712529a5 10.244.1.10:6379
replicates 547619c817623c71502e52413e46bf33bfb307bc
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 10.244.2.8:6379)
M: aaf12abf3906e40d7c1084fa7228e99a49fc02df 10.244.2.8:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 372b0086cccdcdea81be571df557b958712529a5 10.244.1.10:6379
slots: (0 slots) slave
replicates 547619c817623c71502e52413e46bf33bfb307bc
S: d8f1a35fc156598c4d9871a607f2639206072782 10.244.2.10:6379
slots: (0 slots) slave
replicates aaf12abf3906e40d7c1084fa7228e99a49fc02df
M: 547619c817623c71502e52413e46bf33bfb307bc 10.244.1.8:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: b0e40a1d30b397bacefd0f4c4d8584246ce52fc6 10.244.1.9:6379
slots: (0 slots) slave
replicates cd3abc406759315a814820dc0a6ce53b93a919a8
M: cd3abc406759315a814820dc0a6ce53b93a919a8 10.244.2.9:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@master ~]# kubectl 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:6454
cluster_stats_messages_pong_sent:6664
cluster_stats_messages_sent:13118
cluster_stats_messages_ping_received:6664
cluster_stats_messages_pong_received:6438
cluster_stats_messages_received:13102
[root@master ~]# kubectl delete pods redis-cluster-0
[root@master ~]# kubectl delete pods redis-cluster-1
[root@master ~]# kubectl delete pods redis-cluster-2
[root@master ~]# kubectl delete pods redis-cluster-3
[root@master ~]# kubectl delete pods redis-cluster-4
[root@master ~]# kubectl delete pods redis-cluster-5
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129555.html
摘要:常见的和等都是属于某一个的默认是,而等则不属于任何。其实其的命令和上面都差不多,这里不一一列出了创建查看启动情况是一个定义了一组的策略的抽象,可以理解为抽象到用户层的一个宏观服务。其实这个概念在集群里也有,可以参照理解。 showImg(https://segmentfault.com/img/remote/1460000013229549); 【利用K8S技术栈打造个人私有云系列文...
摘要:常见的和等都是属于某一个的默认是,而等则不属于任何。其实其的命令和上面都差不多,这里不一一列出了创建查看启动情况是一个定义了一组的策略的抽象,可以理解为抽象到用户层的一个宏观服务。其实这个概念在集群里也有,可以参照理解。 showImg(https://segmentfault.com/img/remote/1460000013229549); 【利用K8S技术栈打造个人私有云系列文...
摘要:前言我们一起回顾上一篇文章平台的微服务架构和,一共通过构建了三个镜像数据库,部署前端页面的,和接口。最近阿里云产品春节大促销,我一时没忍住又买了一台服务器,打完折扣还是很贵。是一个非常稳定的,可移植的网络文件系统。 前言 我们一起回顾上一篇文章《Bees平台的微服务架构(1)docker和docker-compose》,一共通过Dockerfile构建了三个docker镜像:mysql...
摘要:本文将讲解如何基于搭建集群,的集群设计包括两个部分主从复制和哈希。至此,集群基本安装成功。后期运维基本命令集群节点槽常见问题把所有的物理节点映射到个哈希槽上,负责维护。 Redis集群概述 Redis作为当前非常热门的内存型数据结构存储,可用于数据存储,缓存和消息代理等。本文将讲解如何基于docker搭建Redis集群,Redis的集群设计包括两个部分:主从复制和哈希Slot。1.1....
阅读 1250·2023-01-11 13:20
阅读 1559·2023-01-11 13:20
阅读 1013·2023-01-11 13:20
阅读 1680·2023-01-11 13:20
阅读 3972·2023-01-11 13:20
阅读 2520·2023-01-11 13:20
阅读 1356·2023-01-11 13:20
阅读 3486·2023-01-11 13:20