我想在 kubernetes 中创建 6 个节点的 redis 集群。我正在使用 Minikube 运行kubernetes。
下面是我创建 6 节点集群的实现。
kind: StatefulSet
metadata:
generation: 1
labels:
app: demo-app
name: demo-app
namespace: default
spec:
podManagementPolicy: OrderedReady
replicas: 6
revisionHistoryLimit: 10
selector:
matchLabels:
app: demo-app
serviceName: ""
template:
metadata:
creationTimestamp: null
labels:
app: demo-app
spec:
containers:
- command:
- redis-server
- --port 6379
- --cluster-enabled yes
- --cluster-node-timeout 5000
- --appendonly yes
- --appendfilename appendonly-6379.aof
image: redis:latest
imagePullPolicy: Always
name: demo-app
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- name: redis-pvc
mountPath: /var
- image: nginx:1.12
imagePullPolicy: IfNotPresent
name: redis-exporter
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
volumeClaimTemplates:
- metadata:
name: redis-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
创建有状态集后,我正在从其中一个 pod 中执行 redis create cluster 命令。
redis-cli --cluster create 172.17.0.4:6379 172.17.0.5:6379 172.17.0.6:6379 172.17.0.7:6379 172.17.0.8:6379 172.17.0.9:6379 --cluster-replicas 1
这些都是 pod 的 ips。有了这个我可以启动我的集群。但是一旦我使用手动删除单个 pod
kubernetes delete pod <podname>
例如删除IP地址为:172.17.0.6:6379的redis节点,它应该是master。删除后redis集群状态为:
127.0.0.1:6379> cluster nodes
1c8c238c58d99181018b37af44c2ebfe049e4564 172.17.0.9:6379@16379 slave 4b75e95772887e76eb3d0c9518d13def097ce5fd 0 1579496695000 6 connected
96e6be88d29d847aed9111410cb0f790db068d0e 172.17.0.8:6379@16379 slave 0db23edf54bb57f7db1e2c9eb182ce956229d16e 0 1579496696596 5 connected
c8be98b16a8fa7c1c9c2d43109abafefc803d345 172.17.0.7:6379@16379 master - 0 1579496695991 7 connected 10923-16383
0db23edf54bb57f7db1e2c9eb182ce956229d16e 172.17.0.4:6379@16379 myself,master - 0 1579496694000 1 connected 0-5460
4daae1051e6a72f2ffc0675649e9e2dad9430fc4 172.17.0.6:6379@16379 master,fail - 1579496680825 1579496679000 3 disconnected
4b75e95772887e76eb3d0c9518d13def097ce5fd 172.17.0.5:6379@16379 master - 0 1579496695000 2 connected 5461-10922
一段时间后它变为:
127.0.0.1:6379> cluster nodes
1c8c238c58d99181018b37af44c2ebfe049e4564 172.17.0.9:6379@16379 slave 4b75e95772887e76eb3d0c9518d13def097ce5fd 0 1579496697529 6 connected
96e6be88d29d847aed9111410cb0f790db068d0e 172.17.0.8:6379@16379 slave 0db23edf54bb57f7db1e2c9eb182ce956229d16e 0 1579496696596 5 connected
c8be98b16a8fa7c1c9c2d43109abafefc803d345 172.17.0.7:6379@16379 master - 0 1579496698031 7 connected 10923-16383
0db23edf54bb57f7db1e2c9eb182ce956229d16e 172.17.0.4:6379@16379 myself,master - 0 1579496697000 1 connected 0-5460
4daae1051e6a72f2ffc0675649e9e2dad9430fc4 :0@0 master,fail,noaddr - 1579496680825 1579496679000 3 disconnected
4b75e95772887e76eb3d0c9518d13def097ce5fd 172.17.0.5:6379@16379 master - 0 1579496697028 2 connected 5461-10922
由于 redis 集群提供了自动故障转移,但 pod 的 redis 无法自动加入集群?
或者我应该手动将该 pod 加入集群吗?