k8s部署redis cluster集群该怎么写yaml,帮我写出来
时间: 2024-03-22 15:39:10 浏览: 222
Redis架构演变与Redis-cluster群集读写方案
好的,这是 Redis Cluster 部署的 YAML 配置文件示例:
```yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-cluster
namespace: default
spec:
serviceName: redis-cluster
replicas: 6
selector:
matchLabels:
app: redis-cluster
template:
metadata:
labels:
app: redis-cluster
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- redis-cluster
topologyKey: "kubernetes.io/hostname"
containers:
- name: redis
image: redis:6.2.5-alpine
command:
- sh
- -c
- "redis-server /redis/redis.conf"
ports:
- containerPort: 6379
name: client
- containerPort: 16379
name: gossip
volumeMounts:
- name: redis-conf
mountPath: /redis
volumes:
- name: redis-conf
configMap:
name: redis-cluster-config
items:
- key: redis.conf
path: redis.conf
---
apiVersion: v1
kind: Service
metadata:
name: redis-cluster
namespace: default
spec:
type: ClusterIP
selector:
app: redis-cluster
ports:
- name: client
port: 6379
targetPort: 6379
- name: gossip
port: 16379
targetPort: 16379
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-cluster-config
namespace: default
data:
redis.conf: |
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
protected-mode no
```
这个 YAML 文件使用了 Kubernetes 的 `StatefulSet` 来管理 Redis Cluster 的多个节点,`Service` 对外提供服务,`ConfigMap` 存储 Redis 的配置文件。这里配置的是一个 6 个节点的 Redis Cluster。
阅读全文