返回

使用Kubernetes架設RedisInsight 1.x版,管理Redis集群

使用Kubernetes架設RedisInsight 1.x版,管理Redis集群

目錄

參考網址:https://docs.redis.com/latest/ri/installing/install-k8s/

Create the RedisInsight deployment and service

沒有持久化數據,也就是POD重起,設定數據就會消失

Below is an annotated YAML file that will create a RedisInsight deployment and a service in a k8s cluster.

  1. Create a new file redisinsight.yaml with the content below
# RedisInsight service with name 'redisinsight-service'
apiVersion: v1
kind: Service
metadata:
  name: redisinsight-service       # name should not be 'redisinsight'
                                   # since the service creates
                                   # environment variables that
                                   # conflicts with redisinsight
                                   # application's environment
                                   # variables `REDISINSIGHT_HOST` and
                                   # `REDISINSIGHT_PORT`
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 8001
  selector:
    app: redisinsight
---
# RedisInsight deployment with name 'redisinsight'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redisinsight #deployment name
  labels:
    app: redisinsight #deployment label
spec:
  replicas: 1 #a single replica pod
  selector:
    matchLabels:
      app: redisinsight #which pods is the deployment managing, as defined by the pod template
  template: #pod template
    metadata:
      labels:
        app: redisinsight #label for pod/s
    spec:
      containers:

      - name:  redisinsight #Container name (DNS_LABEL, unique)
        image: redislabs/redisinsight:latest #repo/image
        imagePullPolicy: IfNotPresent #Always pull image
        volumeMounts:
        - name: db #Pod volumes to mount into the container's filesystem. Cannot be updated.
          mountPath: /db
        ports:
        - containerPort: 8001 #exposed container port and protocol
          protocol: TCP
      volumes:
      - name: db
        emptyDir: {} # node-ephemeral volume https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
  1. Create the RedisInsight deployment and service
kubectl apply -f redisinsight.yaml
  1. Once the deployment and service are successfully applied and complete, access RedisInsight. This can be accomplished by listing the using the <external-ip> of the service we created to reach redisinsight.
root@k8s-master71u:~# kubectl get svc,pod
NAME                           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/redisinsight-service   NodePort    10.202.52.175   <none>        80:31785/TCP   8s

NAME                               READY   STATUS    RESTARTS      AGE
pod/redisinsight-cf7f6847b-s2zgg   1/1     Running   0             8s

Or Create the RedisInsight deployment with persistant storage

持久化數據,也就是POD重起,設定數據也不會消失

Below is an annotated YAML file that will create a RedisInsight deployment in a K8s cluster. It will assign a peristent volume created from a volume claim template. Write access to the container is configured in an init container. When using deployments with persistent writeable volumes, it’s best to set the strategy to Recreate. Otherwise you may find yourself with two pods trying to use the same volume.

  1. Create a new file redisinsight.yaml with the content below.
# RedisInsight service with name 'redisinsight-service'
apiVersion: v1
kind: Service
metadata:
  name: redisinsight-service       # name should not be 'redisinsight'
                                   # since the service creates
                                   # environment variables that
                                   # conflicts with redisinsight
                                   # application's environment
                                   # variables `REDISINSIGHT_HOST` and
                                   # `REDISINSIGHT_PORT`
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 8001
  selector:
    app: redisinsight
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redisinsight-pv-claim
  labels:
    app: redisinsight
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  storageClassName: "rook-cephfs"
---
# RedisInsight deployment with name 'redisinsight'
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redisinsight #deployment name
  labels:
    app: redisinsight #deployment label
spec:
  replicas: 1 #a single replica pod
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: redisinsight #which pods is the deployment managing, as defined by the pod template
  template: #pod template
    metadata:
      labels:
        app: redisinsight #label for pod/s
    spec:
      volumes:
        - name: db
          persistentVolumeClaim:
            claimName: redisinsight-pv-claim
      initContainers:
        - name: init
          image: busybox
          command:
            - /bin/sh
            - '-c'
            - |
                            chown -R 1001 /db                            
          resources: {}
          volumeMounts:
            - name: db
              mountPath: /db
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      containers:
        - name:  redisinsight #Container name (DNS_LABEL, unique)
          image: redislabs/redisinsight:latest #repo/image
          imagePullPolicy: IfNotPresent #Always pull image
          volumeMounts:
          - name: db #Pod volumes to mount into the container's filesystem. Cannot be updated.
            mountPath: /db
          ports:
          - containerPort: 8001 #exposed container port and protocol
            protocol: TCP
  1. Create the RedisInsight deployment and service.
kubectl apply -f redisinsight.yaml

開網頁測試

http://192.168.1.71:31785/

Redis Cluster主機IP表

主機名稱主機IP角色主機IP角色跟隨
redis01192.168.1.11:6379master192.168.1.11:6380slave192.168.1.12:6380
redis02192.168.1.12:6379master192.168.1.12:6380slave192.168.1.13:6380
redis03192.168.1.13:6379master192.168.1.13:6380slave192.168.1.11:6380
redis04192.168.1.14:6379master192.168.1.14:6380slave192.168.1.18:6380
redis05192.168.1.18:6379master192.168.1.18:6380slave192.168.1.14:6380

登入畫面

點選ADD REDIS DATABASE

填寫其中一台redis cluster資訊

偵測到為Cluster,就會幫我一同找到其他節點IP

ALL MASTER、REPLICA NODES SUMMARY

可以看到MASTER 節點,彙整總結資訊

也可以看到REPLICA 節點,彙整總結資訊

Browser(SCAN Key)

可以透過此,查詢所有key及其value,也可以添加KEY

CLI(COMMAND)

可以針對節點下REDIS指令

這裡針對所有MASTER下scan 0 count 50指令

就會針對每一台MASTER幫你下指令,並統一顯示於視窗

ANALYSE(Memory Analysis)

可以選擇使用離線分析,也就是提供他rdb file,

或者線上分析,他會對所有redis下bgsave指令,在遠端的redis就會存下目前所有的key資訊為dump.rdb檔。

Memory Overview

Keyspace Summary

Recommendations

Memory Analyzer

ANALYSE Profiler(Monitor)

記錄當下指令執行

ANALYSE Slowlog

查看目前有沒有slowlog慢日誌產生

Bulk Actions

DATEBASE Configuration

可以查看,並設定REDIS

DATEBASE Cluster Management

可以管理Cluster

DATEBASE Client List

可以看到目前連接的客戶端資訊

comments powered by Disqus
使用 Hugo 建立
主題 StackJimmy 設計
發表了128篇文章 · 總計63.96k字
本站已運行
·