部署环境:
centos7.7 yum update到最新,kubeadm为1.16.3
安装步骤:
1、安装NFS
# yum install nfs-common nfs-utils -y
创建pv目录
# mkdir -p /redis/pv{1..10}
# vim /etc/exports
/redis/pv1 *(rw,all_squash)
/redis/pv2 *(rw,all_squash)
/redis/pv3 *(rw,all_squash)
/redis/pv4 *(rw,all_squash)
/redis/pv5 *(rw,all_squash)
/redis/pv6 *(rw,all_squash)
/redis/pv7 *(rw,all_squash)
/redis/pv8 *(rw,all_squash)
/redis/pv9 *(rw,all_squash)
/redis/pv10 *(rw,all_squash)
# chmod 777 /redis/pv{1..10}
# systemctl enable nfs && systemctl enable rpcbind
# systemctl start nfs && systemctl start rpcbind
# showmount -e # 查看可挂载,如果显示那么就没问题
Export list for master:
/redis/pv10 *
/redis/pv9 *
/redis/pv8 *
/redis/pv7 *
/redis/pv6 *
/redis/pv5 *
/redis/pv4 *
/redis/pv3 *
/redis/pv2 *
/redis/pv1 *
2、创建PV
# vim redis-pv.yaml # 写redis-pv.yaml文件,写10个PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv1
spec:
capacity:
storage: 500M
accessModes:
- ReadWriteMany
nfs:
server: 127.0.0.1
path: "/redis/pv1"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv2
spec:
capacity:
storage: 500M
accessModes:
- ReadWriteMany
nfs:
server: 127.0.0.1
path: "/redis/pv2"
---
......
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv9
spec:
capacity:
storage: 500M
accessModes:
- ReadWriteMany
nfs:
server: 127.0.0.1
path: "/redis/pv9"
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv10
spec:
capacity:
storage: 500M
accessModes:
- ReadWriteMany
nfs:
server: 127.0.0.1
path: "/redis/pv10"
apiVersion: v1
# kubectl create -f redis-pv.yaml # 创建PV

3、创建comfigmap来存放redis.conf配置文件
# cat redis.conf
appendonly yes cluster-enabled yes cluster-config-file /var/lib/redis/nodes.conf cluster-node-timeout 1000 dir /var/lib/redis port 6379
# kubectl create configmap redis-conf –from-file=redis.conf
# kubectl get cm

4、创建headless service
# vim redis-headless-service.yml
apiVersion: v1
kind: Service
metadata:
name: redis-service
labels:
app: redis
spec:
ports:
- name: redis-port
port: 6379
clusterIP: None
selector:
app: redis
appCluster: redis-cluster
# kubectl apply -f redis-headless-service.yml
# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE redis-service ClusterIP None 6379/TCP 2s
5、创建集群
# vim redis.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-app
spec:
serviceName: "redis-service"
replicas: 10
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
appCluster: redis-cluster
spec:
terminationGracePeriodSeconds: 20
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- redis
topologyKey: kubernetes.io/hostname
containers:
- name: redis
image: "redis:latest"
command:
- "redis-server"
args:
- "/etc/redis/redis.conf"
- "--protected-mode"
- "no"
resources:
requests:
cpu: "100m"
memory: "100Mi"
ports:
- name: redis
containerPort: 6379
protocol: "TCP"
- name: cluster
containerPort: 16379
protocol: "TCP"
volumeMounts:
- name: "redis-conf"
mountPath: "/etc/redis"
- name: "redis-data"
mountPath: "/var/lib/redis"
volumes:
- name: redis-conf
configMap:
name: redis-conf
items:
- key: redis.conf
path: redis.conf
volumeClaimTemplates:
- metadata:
name: redis-data
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 200M
# kubectl apply -f redis.yaml
然后去冲杯咖啡,多等一会儿,然后来一波三连

6、创建centos为初始化redis集群做准备
# kubectl run -i –tty redistrib –image=centos:7 /bin/bash
# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# yum install redis-trib bind-utils -y
7、初始化集群
创建一主一从集群节点
[root@ redistrib-56dcc745c6-rz85n /]# redis-trib create --replicas 1 \dig +short redis-app-0.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-1.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-2.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-3.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-4.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-5.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-6.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-7.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-8.redis-service.default.svc.cluster.local:6379 \dig +short redis-app-9.redis-service.default.svc.cluster.local:6379

输入YES开始创建集群

最后一句:[OK] All 16384 slots covered. 表示集群搞的没啥问题
连接随意一个节点验证集群

8、创建redis-svc
# cat redis-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-server
labels:
app: redis
spec:
ports:
- port: 6379
protocol: TCP
targetPort: 6379
selector:
app: redis
appCluster: redis-cluster
# kubectl apply -f redis-svc.yaml

集群部署完成
I have been exploring for a little bit for any high quality
articles or blog posts on this sort of space .
Exploring in Yahoo I eventually stumbled upon this
site. Reading this info So i’m glad to show that I have a very just
right uncanny feeling I came upon just what I needed.
I most definitely will make sure to don?t forget this web site and give it a glance on a relentless basis.
Wonderful goods from you, man. I have consider
your stuff prior to and you’re simply too wonderful. I really
like what you’ve bought right here, really like what you are stating and the way wherein you
are saying it. You’re making it entertaining and you still care for
to keep it wise. I cant wait to learn far more
from you. This is actually a terrific site.
Way cool! Some extremely valid points! I appreciate you penning this write-up plus the rest of the website is
really good.