«

K8S 部署单节点Redis

作者:myluzh 分类: Kubernetes 长度:1550 阅读:575


0x01 部署单节点redis

注意:如果需要持久化就把容器的/data目录挂载出来。

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-config

k8s redis k8s部署


正文到此结束
版权声明:若无特殊注明,本文皆为 Myluzh Blog 原创,转载请保留文章出处。
文章内容:https://itho.cn/k8s/450.html
文章标题:《K8S 部署单节点Redis