评论

收藏

[NoSQL] kubernetes部署redis5.0.6单机版 自定义配置文件、密码、日志路径等

数据库 数据库 发布于:2021-07-08 10:47 | 阅读数:368 | 评论:0

  kubernetes部署redis5.0.6单机版 自定义配置文件、密码、日志路径等
  创建redis配置configmaps:
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-conf
data:
  redis.conf: |
    bind 0.0.0.0
    port 6379
    requirepass 123456
    pidfile .pid
    appendonly yes
    cluster-config-file nodes-6379.conf
    pidfile /data/middleware-data/redis/log/redis-6379.pid
    cluster-config-file /data/middleware-data/redis/conf/redis.conf
    dir /data/middleware-data/redis/data/
    logfile "/data/middleware-data/redis/log/redis-6379.log"
    cluster-node-timeout 5000
    protected-mode no
  创建StatefulSet,并把数据挂载到宿主机上:
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
spec:
  replicas: 1
  serviceName: redis
  selector:
  matchLabels:
    name: redis
  template:
  metadata:
    labels:
    name: redis
  spec:
    initContainers:
    - name: init-redis
    image: busybox
    command: ['sh', '-c', 'mkdir -p /data/middleware-data/redis/log/;mkdir -p /data/middleware-data/redis/conf/;mkdir -p /data/middleware-data/redis/data/']
    volumeMounts:
    - name: data
      mountPath: /data/middleware-data/redis/
    containers:
    - name: redis
    image: redis:5.0.6
    imagePullPolicy: IfNotPresent
    command:
    - sh
    - -c
    - "exec redis-server /data/middleware-data/redis/conf/redis.conf"
    ports:
    - containerPort: 6379
      name: redis
      protocol: TCP
    volumeMounts:
    - name: redis-config
      mountPath: /data/middleware-data/redis/conf/
    - name: data
      mountPath: /data/middleware-data/redis/
    volumes:
    - name: redis-config
    configMap:
      name: redis-conf
    - name: data
    hostPath:
      path: /data/middleware-data/redis/
  创建Service:
kind: Service
apiVersion: v1
metadata:
  labels:
  name: redis
  name: redis
spec:
  type: NodePort
  ports:
  - name: redis
  port: 6379
  targetPort: 6379
  nodePort: 30020
  selector:
  name: redis
  
关注下面的标签,发现更多相似文章