K8S部署Redis Cluster集群
参考文档:K8S部署Redis Cluster集群vim redis-configmap.yamlapiVersion: v1kind: ConfigMapmetadata:name: redis-clusternamespace: middlewaredata:fix-ip.sh: |#!/bin/shCLUSTER_CONFIG="/data/nodes.conf"if [ -f ${CLUS
·
参考文档:K8S部署Redis Cluster集群
未完待续。。。请查看参考文档。
cat redis-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-cluster
namespace: middleware
data:
fix-ip.sh: |
#!/bin/sh
CLUSTER_CONFIG="/data/nodes.conf"
if [ -f ${CLUSTER_CONFIG} ]; then
if [ -z "${POD_IP}" ]; then
echo "Unable to determine Pod IP address!"
exit 1
fi
echo "Updating my IP to ${POD_IP} in ${CLUSTER_CONFIG}"
sed -i.bak -e '/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/'${POD_IP}'/' ${CLUSTER_CONFIG}
fi
exec "$@"
redis.conf: |
cluster-enabled yes
cluster-config-file /data/nodes.conf
cluster-node-timeout 10000
protected-mode no
daemonize no
pidfile /var/run/redis.pid
port 6379
tcp-backlog 511
bind 0.0.0.0
timeout 3600
tcp-keepalive 1
loglevel verbose
logfile /data/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data
#requirepass yl123456
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 20000
slowlog-log-slower-than 10000
slowlog-max-len 128
#rename-command FLUSHALL ""
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
cat redis-cluster.yml
---
apiVersion: v1
kind: Service
metadata:
namespace: middleware
name: redis-cluster
spec:
clusterIP: None
ports:
- port: 6379
targetPort: 6379
name: client
- port: 16379
targetPort: 16379
name: gossip
selector:
app: redis-cluster
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: middleware
name: redis-cluster
spec:
serviceName: redis-cluster
podManagementPolicy: OrderedReady
replicas: 6
selector:
matchLabels:
app: redis-cluster
template:
metadata:
labels:
app: redis-cluster
spec:
containers:
- name: redis
image: redis:6.0.10
ports:
- containerPort: 6379
name: client
- containerPort: 16379
name: gossip
command: ["/etc/redis/fix-ip.sh", "redis-server", "/etc/redis/redis.conf"]
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
volumeMounts:
- name: conf
mountPath: /etc/redis/
readOnly: false
volumes:
- name: conf
configMap:
name: redis-cluster
defaultMode: 0755
# 创建cluster集群
kubectlola-dev exec -it redis-cluster-0 -n middleware -- redis-cli -p 6379 --cluster create --cluster-replicas 1 $(kubectlola-dev get pods -l app=redis-cluster -n middleware -o jsonpath='{range.items[*]}{.status.podIP}:6379 ' |awk 'OFS=" " {$NF="" ;print $0}')
# 查看集群信息
kubectlola-dev exec -it redis-cluster-0 -n middleware -- redis-cli cluster info
# 检查集群
for x in $(seq 0 5); do echo "redis-cluster-$x"; kubectlola-dev exec redis-cluster-$x -n middleware -- redis-cli role; echo; done
更多推荐
已为社区贡献14条内容
所有评论(0)