k8s Redis安装部署

一、文档简介

作者:lanjiaxuan

邮箱:lanheader@163.com

博客地址:https://www.cnblogs.com/lanheader/

更新时间:2021-07-09

安装方式

kubectl apply -f redis.yaml -n xxxxx

安装配置文件

分别创建以下资源的yaml文件,替换上面的redis.yaml执行

创建pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redis-6379-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: "nfs-provisioner"  # 这里指定storageClass名称

创建configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-cm
data:
    redis_6379.conf: |
      protected-mode no
      port 6379
      tcp-backlog 511
      timeout 0
      tcp-keepalive 300
      daemonize no
      supervised no
      pidfile /var/run/redis_6379.pid
      loglevel notice
      logfile "/data/redis_6379.log"
      databases 16
      always-show-logo yes
      # requirepass {{ $name.redis.env.passwd }}
      save 900 1
      save 300 10
      save 60 10000
      stop-writes-on-bgsave-error yes
      rdbcompression yes
      rdbchecksum yes
      dbfilename dump_6379.rdb
      dir  /data
      replica-serve-stale-data yes
      replica-read-only yes
      repl-diskless-sync no
      repl-diskless-sync-delay 5
      repl-disable-tcp-nodelay no
      replica-priority 100
      lazyfree-lazy-eviction no
      lazyfree-lazy-expire no
      lazyfree-lazy-server-del no
      replica-lazy-flush no
      appendonly no
      appendfilename "appendonly.aof"
      appendfsync everysec
      no-appendfsync-on-rewrite no
      auto-aof-rewrite-percentage 100
      auto-aof-rewrite-min-size 64mb
      aof-load-truncated yes
      aof-use-rdb-preamble yes
      lua-time-limit 5000
      slowlog-log-slower-than 10000
      slowlog-max-len 128
      latency-monitor-threshold 0
      notify-keyspace-events ""
      hash-max-ziplist-entries 512
      hash-max-ziplist-value 64
      list-max-ziplist-size -2
      list-compress-depth 0
      set-max-intset-entries 512
      zset-max-ziplist-entries 128
      zset-max-ziplist-value 64
      hll-sparse-max-bytes 3000
      stream-node-max-bytes 4096
      stream-node-max-entries 100
      activerehashing yes
      client-output-buffer-limit normal 0 0 0
      client-output-buffer-limit replica 256mb 64mb 60
      client-output-buffer-limit pubsub 32mb 8mb 60
      hz 10
      dynamic-hz yes
      aof-rewrite-incremental-fsync yes
      rdb-save-incremental-fsync yes
      rename-command FLUSHALL SAVEMORE16
      rename-command FLUSHDB  SAVEDB16
      rename-command CONFIG   UPDATEC16
      rename-command KEYS     NOALL16

创建Service

apiVersion: v1
kind: Service
metadata:
 name: redis-service
 labels:
   name: redis-service
spec:
 type: ClusterIP   # 如果需要集群外部访问,这里改为NodePort
 ports:
 - port: 6379
   protocol: TCP
   targetPort: 6379
   name: redis-6379
 selector:
   name: redis   # 这里填写Deployment/metadata/name 的值

部署redis

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: redis
  name: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      name: redis
  template:
    metadata:
      labels:
        name: redis
    spec:
      containers:
      - name: redis-6379
        image: redis:5.0
        volumeMounts:
        - name: configmap-volume
          mountPath: /usr/local/etc/redis/redis_6379.conf
          subPath: redis_6379.conf
        - name: redis-6379
          mountPath: "/data"
        command:
          - "redis-server"
        args:
          - /usr/local/etc/redis/redis_6379.conf
      volumes:
      - name: configmap-volume
        configMap:
          name: redis-cm
          items:
          - key: redis_6379.conf
            path: redis_6379.conf
      - name: redis-6379
        persistentVolumeClaim:
          claimName: redis-6379-pvc  # 这里填写pvc的名称
原文地址:https://www.cnblogs.com/lanheader/p/14153973.html