K8S 部署redis cluster分片集群 —— 筑梦之路
2023-09-14 09:09:35 时间
环境说明:
redis版本: 5.0
部署所需的yaml文件内容:
apiVersion: v1
kind: Service
metadata:
namespace: test
name: redis-service
labels:
app: redis
spec:
ports:
- name: redis
port: 6379
targetPort: 6379
protocol: TCP
nodePort: 26379
- name: cluster
port: 16379
targetPort: 16379
protocol: TCP
#clusterIP: None
type: NodePort
selector:
app: redis
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
namespace: test
name: redis-cluster
spec:
serviceName: redis-service
selector:
matchLabels:
app: redis
replicas: 6
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:5.0
ports:
- name: redis
containerPort: 6379
protocol: TCP
- name: cluster
containerPort: 16379
protocol: TCP
command: ["/etc/redis/fix-ip.sh", "redis-server", "/etc/redis/redis.conf"]
volumeMounts:
- name: redis-conf
mountPath: /etc/redis
- name: redis-data
mountPath: /data
resources:
limits:
cpu: 0.5
memory: 1Gi
requests:
cpu: 0.1
memory: 1Gi
volumes:
- name: redis-conf
configMap:
name: redis-cluster-conf
items:
- key: redis.conf
path: redis.conf
- key: fix-ip.sh
path: fix-ip.sh
defaultMode: 0755
volumeClaimTemplates:
- metadata:
name: redis-data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: managed-nfs-storage
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: ConfigMap
metadata:
namespace: test
labels:
name: redis
name: redis-cluster-conf
# maxmemory 设置为 limit.memory 80%
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: |
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
repl-ping-slave-period 10
repl-timeout 60
cluster-node-timeout 15000
maxmemory 966367641
maxmemory-policy noeviction
appendonly yes
appendfsync everysec
tcp-keepalive 60
protected-mode no
requirepass admin123
masterauth admin123
镜像使用官方的就行
相关文章
- Redis sort 排序命令详解
- Redis集群的部署
- redis
- redis 简单整理——内存的管理[二十六]
- Redis缓存穿透、缓存雪崩、redis并发问题 并发竞争key的解决方案 (阿里)
- 【云原生 | Kubernetes 系列】Redis单机和Redis-cluster的K8S实现
- 【云原生之kubernetes实战】在k8s下部署Redis集群
- redis hash学习
- redis面试题汇总
- python中,用Redis构建分布式锁
- Redis Cluster部署、管理和测试
- redis sentinel 高可用(HA)方案部署,及python应用示例
- Redis进阶学习10---redis最佳实践
- 全面分析redis持久化机制
- redis 相关网址