发布时间: 2024-9-4 文章作者: myluzh 分类名称: Kubernetes 朗读文章
apiVersion: v1 kind: ConfigMap metadata: name: redis-config namespace: test # 根据实际情况调整 data: redis.conf: | # 监听所有网络接口 bind 0.0.0.0 # 设置Redis密码 requirepass qwer1234 # 关闭保护模式,允许远程连接 protected-mode no # 配置内存使用最大量 maxmemory 2147483648 # 内存满时的淘汰策略为volatile-lru,即仅对设置了过期时间的键使用LRU淘汰策略。 maxmemory-policy volatile-lru # 设置日志文件路径 logfile "/data/redis.log" # RDB快照,每 600 秒(10 分钟)和至少 120 个键被修改时执行持久化操作。 save 600 120 # 启用RDB快照压缩 rdbcompression yes # 启用AOF持久化 appendonly yes appendfsync everysec # 设置 TCP 连接待处理队列大小 tcp-backlog 511 # 客户端空闲超时时间,秒。 timeout 300 # 最大客户端连接数 maxclients 10000 # 重命名命令,将 FLUSHALL 和 FLUSHDB 命令重命名为空字符串,即禁用这些命令。 rename-command FLUSHALL "" rename-command FLUSHDB "" --- apiVersion: apps/v1 kind: Deployment metadata: name: redis namespace: test labels: app: redis spec: replicas: 1 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: containers: - name: redis image: redis:6.2.14 volumeMounts: - name: redis-config mountPath: /usr/local/etc/redis/redis.conf subPath: redis.conf ports: - containerPort: 6379 command: [ "redis-server", "/usr/local/etc/redis/redis.conf" ] volumes: - name: redis-config configMap: name: redis-config0x02 部署redis集群
helm repo add ot-helm https://ot-container-kit.github.io/helm-charts/ helm install redis-operator ot-helm/redis-operator --namespace redis-operator --create-namespace使用 YAML 安装:
kubectl apply -f https://raw.githubusercontent.com/OT-CONTAINER-KIT/redis-operator/main/deploy/all-in-one.yaml2、创建 Redis Cluster 定义
apiVersion: redis.kun/v1alpha1 kind: RedisCluster metadata: name: redis-cluster namespace: redis-operator spec: clusterSize: 3 redis: image: registry.cn-hangzhou.aliyuncs.com/qiluo-images/redis:6.2.6 resources: limits: cpu: "500m" memory: "500Mi" requests: cpu: "250m" memory: "250Mi" exporter: enabled: true persistence: enabled: true storageClass: "standard" # 替换为你的存储类 accessModes: - ReadWriteOnce size: 1Gi3、部署 Redis Cluster
kubectl apply -f redis-cluster.yaml4、验证 Redis 集群状态
kubectl get rediscluster -n redis-operator5、访问 Redis 集群
标签: k8s redis k8s部署 redis集群 redis-operater operater operater.io
发表评论