> 文章列表 > K8S 部署redis cluster分片集群 —— 筑梦之路

K8S 部署redis cluster分片集群 —— 筑梦之路

K8S 部署redis cluster分片集群 —— 筑梦之路

环境说明:

redis版本: 5.0

部署所需的yaml文件内容:

apiVersion: v1
kind: Service
metadata:namespace: testname: redis-servicelabels:app: redis
spec:ports:- name: redisport: 6379targetPort: 6379protocol: TCPnodePort: 26379- name: clusterport: 16379targetPort: 16379protocol: TCP#clusterIP: Nonetype: NodePortselector:app: redis
---
apiVersion: apps/v1
kind: StatefulSet
metadata:namespace: testname: redis-cluster
spec:serviceName: redis-serviceselector:matchLabels:app: redis replicas: 6template:metadata:labels:app: redisspec:containers:- name: redisimage: redis:5.0ports:- name: rediscontainerPort: 6379protocol: TCP- name: clustercontainerPort: 16379protocol: TCPcommand: ["/etc/redis/fix-ip.sh", "redis-server", "/etc/redis/redis.conf"]volumeMounts:- name: redis-confmountPath: /etc/redis- name: redis-datamountPath: /dataresources:limits:cpu: 0.5memory: 1Girequests:cpu: 0.1memory: 1Givolumes:- name: redis-confconfigMap:name: redis-cluster-confitems:- key: redis.confpath: redis.conf- key: fix-ip.shpath: fix-ip.shdefaultMode: 0755volumeClaimTemplates:- metadata:name: redis-dataspec:accessModes: [ "ReadWriteOnce" ]storageClassName: managed-nfs-storageresources:requests:storage: 2Gi
---
apiVersion: v1
kind: ConfigMap
metadata:namespace: testlabels:name: redisname: redis-cluster-conf
# maxmemory 设置为 limit.memory 80%
data:fix-ip.sh: |#!/bin/shCLUSTER_CONFIG="/data/nodes.conf"if [ -f ${CLUSTER_CONFIG} ]; thenif [ -z "${POD_IP}" ]; then echo "Unable to determine Pod IP address!"exit 1fiecho "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}fiexec "$@"redis.conf: |port 6379cluster-enabled yescluster-config-file nodes.confrepl-ping-slave-period 10repl-timeout 60cluster-node-timeout 15000maxmemory 966367641maxmemory-policy noeviction appendonly yesappendfsync everysec tcp-keepalive 60protected-mode norequirepass admin123masterauth  admin123

 镜像使用官方的就行