cloud
cloud-native
云原生与 kubernetes
部署中间件
部署 ElasticSearch(8.x)

部署 Redis(7.2.3)

部署说明:通过 nodeSelector 固定到 worker3 节点上。并使用 worker3 上的原生文件系统目录 /.data

部署文件说明

  1. 通过 config 定制 redis.conf 的配置, 比如 密码
  2. 有使用 LoadBalancer 类型的 Service, 通过 externalIPs 指定外部 IP
  3. 通过 hostPath 挂载宿主机的目录, 用于持久化数据提升IO性能
  4. 部署于 middleware 命名空间
  5. 镜像使用 registry.cn-hongkong.aliyuncs.com/jansora/redis:7.2.3, 拷贝自官方镜像,无改动
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis-1
  namespace: middleware
spec:
  selector:
    matchLabels:
      app: redis-1
  replicas: 1
  template:
    metadata:
      labels:
        app: redis-1
    spec:
      nodeSelector:
        worker: worker3
      containers:
        - name: redis-1
          image: registry.cn-hongkong.aliyuncs.com/jansora/redis:7.2.3
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 6379
          command: ["redis-server", "/etc/redis.conf"]
          volumeMounts:
            - name: host-path
              subPath: 'redis/redis-1/data'
              mountPath: "/data"
            - name: config-volume
              mountPath: /etc/redis.conf # 具体路径请参考官方文档
              subPath: redis.conf
      volumes:
        - name: config-volume
          configMap:
            name: redis-config
        - name: host-path
          hostPath:
            path: /.data/
            type: DirectoryOrCreate
  serviceName: redis-1-service
 
---
 
# 创建 Service 由 kubernetes 来对多个 nameserver 做负载均衡
apiVersion: v1
kind: Service
metadata:
  labels:
    app: redis-1
  name: redis-1-service
  namespace: middleware
spec:
  type: LoadBalancer
  externalIPs:
    - 192.168.36.11
  ports:
    - port: 6379
      protocol: TCP
  selector:
    app: redis-1
 
---
 
 
# 创建 configmap
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-config
  namespace: middleware
data:
  redis.conf: |
    requirepass abcdefg