环境信息:
k8s:
k8s版本:1.23.17
master01:192.168.66.50
master02:192.168.66.55
master03:192.168.66.56
etcd01:192.168.66.58
etcd02:192.168.66.59
etcd03:192.168.66.57
ingress01:192.168.66.52
node01:192.168.66.51
node02:192.168.66.53
存储节点使用nfs存储:
192.168.66.40
redis是有状态的服务,所以我们在k8s部署redis cluster需要statefuset控制器部署,准备部署reids cluster是三主三从的集群
1:部署reids cluster的前期准备:
创建nfs共享存储
在192.168.66.40服务器上部署nfs
yum install nfs-utils rpcbind
创建共享存储目录,存储路径:
mkdir -pv /date/redis{0..5}
ls -lh /data
[root@docker ~]# ls -lh /data
total 0
drwxr-xr-x. 2 root root 59 Jul 24 21:53 redis0
drwxr-xr-x. 2 root root 59 Jul 24 21:54 redis1
drwxr-xr-x. 2 root root 59 Jul 24 21:54 redis2
drwxr-xr-x. 2 root root 59 Jul 24 21:53 redis3
drwxr-xr-x. 2 root root 59 Jul 24 21:54 redis4
drwxr-xr-x. 2 root root 59 Jul 24 21:54 redis5
验证:在k8s上的node节点上测试,是否可以挂在nfs共享盘
# showmount -e 192.168.66.40
2:在k8s上面开始部署redis cluster:
a:创建pv,sc,headless service和comfigmap
pv创建,编写yaml文件,需要创建6个pv,每个redis节点挂在一个pv
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-redis-pv0
spec:
storageClassName: redis-sc
capacity:
storage: 2Gi
accessModes:
- ReadWriteMany
nfs:
server: 192.168.66.40
path: "/data/redis0"
#kubectl apply -f redis-pv.yaml
b:创建sc,即StorageCluster类型存储,之后的pvc就是依赖于StorageCluster创建
[root@master03 redis_cluster_yaml]# vim redis-sc.yaml
apiVersio