Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).

5 Minutes to RedisInsight running on Single Node Kubernetes Cluster on Docker Desktop for Mac

3 min read

If you are looking out for a tool which can inspect your Redis data, monitor health, and perform runtime server configuration with a browser-based management interface for your Redis deployment, then I would recommend “RedisInsight”. RedisInsight is built by RedisLabs, offered free of cost and help in gaining insights into real-time performance metrics, inspect slow commands, and manage Redis configuration directly through the interface.

RedisInsight offers the following features –

  • Easy to use browser based interface to search keys, view and edit data
  • Only GUI tool to support Redis Cluster
  • Supports SSL/TLS based connections
  • Memory Analysis

Redis is an in-memory but persistent on disk database, so it represents a different trade off where very high write and read speed is achieved with the limitation of data sets that can’t be larger than memory. Hence, it becomes important to keep track of Memory usage. One of the exciting feature of RedisInsight is Memory analysis. Memory analysis help you analyze your Redis instance and helps in reducing memory usage and improving application performance. Analysis can be done in two ways: online mode – In this mode, RedisInsight downloads a rdb file from your connected Redis instance and analyzes it to create a temp file with all the keys and meta data required for analysis. In case there is a master-slave connection, RedisInsight downloads the dump from the slave instead of the master in order to avoid affecting the performance of the master.

RedisInsight today runs on bare metal, VM, on your desktop and inside container too. Running it inside Docker container is an one-liner command:

docker run -v redisinsight:/db -p 8001:8001 redislabs/redisinsight

In case you face the below permission issue:

[Captains-Bay]? >  docker run -it -v redisinsight:/db -p 8001:8001 redislabs/redisinsight
Traceback (most recent call last):
  File "./startup.py", line 395, in <module>
  File "./startup.py", line 378, in create_startup_logger
  File "/usr/local/lib/python3.6/logging/handlers.py", line 202, in __init__
    BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay)
  File "/usr/local/lib/python3.6/logging/handlers.py", line 57, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/local/lib/python3.6/logging/__init__.py", line 1032, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/lib/python3.6/logging/__init__.py", line 1061, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/db/redisinsight.log'

All you need to do is ensure that you have right permission set as shown below:


[Captains-Bay]? >  chown -R 1001 myinfo
[Captains-Bay]? >  docker run -v myinfo:/db -p 8001:8001 redislabs/redisinsight

Under this blog post, I will showcase how to run RedisInsight on a single-node Kubernetes cluster running on Docker Desktop for Mac.

Pre-requisite

  • Docker Desktop for Mac
  • Enable Kubernetes

Install Redis

brew install redis

Running Redis-Server with auth


~ % redis-server --requirepass redis12#
1825:C 29 Mar 2020 00:52:56.943 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1825:C 29 Mar 2020 00:52:56.943 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=1825, just started
1825:C 29 Mar 2020 00:52:56.943 # Configuration loaded
1825:M 29 Mar 2020 00:52:56.945 * Increased maximum number of open files to 10032 (it was originally set to 2560).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1825
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

1825:M 29 Mar 2020 00:52:56.946 # Server initialized
1825:M 29 Mar 2020 00:52:56.947 * DB loaded from disk: 0.000 seconds
1825:M 29 Mar 2020 00:52:56.947 * Ready to accept connections

Push Hash keys into Redis using Python

If you’re a Python developer, here’s a bonus. Use the below code snippet to get your dataset into Redis Database. I could push over 1 million dataset into Redis database in just 43 seconds. Interesting, isn’t it?

Copy the below content into a file called push-keys-auth.python

import redis
# Create connection object
r = redis.StrictRedis(host='localhost', port=6379, db=0, password='redis12#')
# set a value for the foo object
r.set('foo', 'bar')
# retrieve and print the value for the foo object
print(r.get('foo'))

Running Python Script

python push-keys-auth.py

Verifying Single Node Kubernetes Cluster

kubectl get nodes
NAME             STATUS   ROLES    AGE   VERSION
docker-desktop   Ready    master   15h   v1.15.5

Running RedisInsight inside Kubernetes Pods

You can download YAML file from this link

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 #repo/image
        imagePullPolicy: Always #Always pull image
        volumeMounts:
        - name: db #Pod volumes to mount into the container's filesystem. Cannot be updated.
          mountPath: /db
        ports:
        - containerPort: 8001 #exposed conainer port and protocol
          protocol: TCP
      volumes:
      - name: db
        emptyDir: {} # node-ephemeral volume https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
ajeetraina@Ajeet-Rainas-Macbook-Pro ~ % kubectl apply -f redisinsight.yaml
ajeetraina@Ajeet-Rainas-Macbook-Pro ~ % kubectl get po,svc,deploy
NAME                                READY   STATUS    RESTARTS   AGE
pod/redisinsight-6b6b9d69c5-sfztk   1/1     Running   0          4m24s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   15h

NAME                                 READY   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/redisinsight   1/1     1            1           4m24s
ajeetraina@Ajeet-Rainas-Macbook-Pro ~ % 

Port Forwarding

Once the deployment has been successfully applied and the deployment complete, access RedisInsight. This can be accomplished by exposing the deployment as a K8s Service or by using port forwarding, as in the example below:

kubectl port-forward deployment/redisinsight 8001

Open your browser and point to http://localhost:8001



As you see above, RedisInsight displays one key which we inserted using Python at the beginning of this blog.

In my next blog post, I will talk about Redis Operator for Kubernetes. Stay tuned !

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).
Join our Discord Server
Index