[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. 創(chuàng)建6個pv,kubectl apply -f redis-pv.yaml,下面為redis-pv.yaml內容:
apiVersion: v1
kind: PersistentVolume # 創(chuàng)建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創(chuàng)建模板
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
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規(guī)行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/129555.html
摘要:常見的和等都是屬于某一個的默認是,而等則不屬于任何。其實其的命令和上面都差不多,這里不一一列出了創(chuàng)建查看啟動情況是一個定義了一組的策略的抽象,可以理解為抽象到用戶層的一個宏觀服務。其實這個概念在集群里也有,可以參照理解。 showImg(https://segmentfault.com/img/remote/1460000013229549); 【利用K8S技術棧打造個人私有云系列文...
摘要:常見的和等都是屬于某一個的默認是,而等則不屬于任何。其實其的命令和上面都差不多,這里不一一列出了創(chuàng)建查看啟動情況是一個定義了一組的策略的抽象,可以理解為抽象到用戶層的一個宏觀服務。其實這個概念在集群里也有,可以參照理解。 showImg(https://segmentfault.com/img/remote/1460000013229549); 【利用K8S技術棧打造個人私有云系列文...
摘要:前言我們一起回顧上一篇文章平臺的微服務架構和,一共通過構建了三個鏡像數據庫,部署前端頁面的,和接口。最近阿里云產品春節(jié)大促銷,我一時沒忍住又買了一臺服務器,打完折扣還是很貴。是一個非常穩(wěn)定的,可移植的網絡文件系統。 前言 我們一起回顧上一篇文章《Bees平臺的微服務架構(1)docker和docker-compose》,一共通過Dockerfile構建了三個docker鏡像:mysql...
摘要:本文將講解如何基于搭建集群,的集群設計包括兩個部分主從復制和哈希。至此,集群基本安裝成功。后期運維基本命令集群節(jié)點槽常見問題把所有的物理節(jié)點映射到個哈希槽上,負責維護。 Redis集群概述 Redis作為當前非常熱門的內存型數據結構存儲,可用于數據存儲,緩存和消息代理等。本文將講解如何基于docker搭建Redis集群,Redis的集群設計包括兩個部分:主從復制和哈希Slot。1.1....
閱讀 1346·2023-01-11 13:20
閱讀 1684·2023-01-11 13:20
閱讀 1132·2023-01-11 13:20
閱讀 1858·2023-01-11 13:20
閱讀 4100·2023-01-11 13:20
閱讀 2704·2023-01-11 13:20
閱讀 1385·2023-01-11 13:20
閱讀 3597·2023-01-11 13:20