redis-cluster部署手册(helm版本)
使用 Helm 部署 Redis 集群
前提条件
- Kubernetes 集群已搭建完成。
- Helm 已安装完成。
Redis 集群部署流程
1. 部署 Redis 集群
使用 Helm 部署 Redis 集群,并将其存储配置为使用 NFS Provisioner。
1.1 添加 Helm 仓库
添加 Bitnami 的 Helm 仓库:
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
1.2 安装 Redis 集群
使用 Helm 安装 Redis 集群,并配置使用 NFS Provisioner 提供的存储:
helm install redis-cluster bitnami/redis-cluster \
--set cluster.enabled=true \
--set persistence.enabled=true \
--set persistence.storageClass=nfs-sc \ # 替换成已部署的storageClass名称
--set persistence.size=30Gi \
--set password=psd123 \ # 替换密码
--namespace redis-cluster \
--create-namespace \
--version 12.0.1
参数说明:
- cluster.enabled=true:启用 Redis 集群模式。
- persistence.enabled=true:启用Redis 持久化(建议不启用)
- persistence.storageClass=nfs-sc:使用 NFS Provisioner 提供的 StorageClass。
- persistence.size=30Gi:每个 Redis 节点的存储大小。
- password=psd123:设置 Redis 密码。
2. 验证部署
2.1 检查 Pod 状态
部署完成后,可以使用以下命令检查 Redis 集群的 Pod 状态:
kubectl get pods -n redis-cluster
2.2 检查 Service 状态
检查 Redis 集群的 Service 状态:
kubectl get svc -n redis-cluster
确保所有 Service 都正常运行。
3. 部署redis-cluster-proxy(Camellia Redis Proxy)
因redis官方提供的redis-cluster-proxy长久未更新,可以使用网易云提供的camellia-redis-proxy来代理redis集群
3.1 官方yaml源
3.2 自定义官方yaml源
以下是一个自定义的 YAML 文件,用于部署 Camellia Redis Proxy:
#创建camellia-redis-cluster-proxy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: camellia-redis-cluster-proxy
namespace: redis-cluster #保持与redis-cluster部署在同一个命名空间中
labels:
app: camellia-redis-cluster-proxy
spec:
replicas: 3
selector:
matchLabels:
app: camellia-redis-cluster-proxy
template:
metadata:
labels:
app: camellia-redis-cluster-proxy
spec:
enableServiceLinks: false
containers:
- name: container-camellia
image: 48n6e/camellia-redis-proxy:1.3.2-jdk-21-0.0.1
command:
- java
- "-XX:+UseG1GC"
- "-XX:+UseContainerSupport"
- "-Dio.netty.tryReflectionSetAccessible=true"
- "--add-opens"
- "java.base/java.lang=ALL-UNNAMED"
- "--add-opens"
- "java.base/java.io=ALL-UNNAMED"
- "--add-opens"
- "java.base/java.math=ALL-UNNAMED"
- "--add-opens"
- "java.base/java.net=ALL-UNNAMED"
- "--add-opens"
- "java.base/java.nio=ALL-UNNAMED"
- "--add-opens"
- "java.base/java.security=ALL-UNNAMED"
- "--add-opens"
- "java.base/java.text=ALL-UNNAMED"
- "--add-opens"
- "java.base/java.time=ALL-UNNAMED"
- "--add-opens"
- "java.base/java.util=ALL-UNNAMED"
- "--add-opens"
- "java.base/jdk.internal.access=ALL-UNNAMED"
- "--add-opens"
- "java.base/jdk.internal.misc=ALL-UNNAMED"
- "--add-opens"
- "java.base/sun.net.util=ALL-UNNAMED"
- "-Xms100m"
- "-Xmx4096m"
- "-server"
- "org.springframework.boot.loader.JarLauncher"
resources:
requests:
memory: "100Mi"
cpu: "1"
limits:
memory: "4Gi"
cpu: "1"
ports:
- containerPort: 6380
name: db
protocol: TCP
volumeMounts:
- name: camellia-redis-cluster-proxy
mountPath: /opt/camellia-redis-proxy/BOOT-INF/classes/application.yml
subPath: application-sharding-singlewrite-multiread.yml
volumes:
- name: camellia-redis-cluster-proxy
configMap:
name: camellia-redis-cluster-proxy
---
apiVersion: v1
kind: ConfigMap
metadata:
name: camellia-redis-cluster-proxy
namespace: redis-cluster
data:
application-sharding-singlewrite-multiread.yml: |
server:
port: 6380
spring:
application:
name: camellia-redis-proxy-server
camellia-redis-proxy:
console-port: 16379
password: psd123 #代理密码,部署时请替换
monitor-enable: true
monitor-interval-seconds: 60
plugins:
- monitorPlugin
- bigKeyPlugin
- hotKeyPlugin
- hotKeyCachePlugin
config:
"check.redis.resource.valid.not.active.threshold.sceonds": 300
transpond:
type: local
local:
type: simple
resource: redis-cluster://zsfund@redis-cluster.redis-cluster.svc.cluster.local:6379 ##替换成redis-cluster service域名
redis-conf:
sharding-func: com.netease.nim.camellia.core.client.env.CRC16HashTagShardingFunc
preheat: false
close-idle-connection: true
check-idle-connection-threshold-seconds: 600
close-idle-connection-delay-seconds: 60
---
apiVersion: v1
kind: Service
metadata:
name: camellia-redis-cluster-proxy
namespace: redis-cluster
annotations:
prometheus.io/scrape: 'true'
prometheus.io/port: '16379'
prometheus.io/services: 'false'
prometheus.io/scrape_slow: 'true'
prometheus.io/path: '/metrics'
spec:
ports:
- name: port-6380
protocol: TCP
port: 6380
targetPort: 6380
- name: port-16379
protocol: TCP
port: 16379
targetPort: 16379
type: ClusterIP
selector:
app: camellia-redis-cluster-proxy
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: redis-cluster-proxy-ingress
namespace: redis-cluster
spec:
ingressClassName: nginx
rules:
- host: redis.xxx.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: camellia-redis-cluster-proxy
port:
number: 6380
3.3 部署
将上述 YAML 文件保存为 camellia-redis-cluster-proxy.yaml,然后使用以下命令部署:
kubectl apply -f camellia-redis-cluster-proxy.yaml
3.4 访问方式
- Ingress 访问:https://redis.xxx.com(注意:ingress-nginx必须开启tcp代理,客户端(如:aspnetcore)才可通过域名使用)