Redisinsight fails to launch in kubernetes

I have the following .yaml file to install redisgraph in kubernetes.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: redisinsight-storage-class
provisioner: 'kubernetes.io/gce-pd'
parameters:
  type: 'pd-standard'
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redisinsight-volume-claim
spec:
  storageClassName: redisinsight-storage-class
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
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:
      initContainers:
        - name: change-data-dir-ownership
          image: alpine:3.6
          command:
            - chmod
            - -R
            - '777'
            - /db
          volumeMounts:
            - name: db
              mountPath: /db
      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
          persistentVolumeClaim:
            claimName: redisinsight-volume-claim
---
apiVersion: v1
kind: Service
metadata:
  name: redisinsight
spec:
  ports:
    - port: 8001
      name: redisinsight
  type: LoadBalancer
  selector:
    app: redisinsight

But the redisinsight pod does not get launched and gives the following error:

INFO 2020-07-03 06:30:08,117 redisinsight_startup Registered SIGTERM handler
ERROR 2020-07-03 06:30:08,131 redisinsight_startup Error in main()
Traceback (most recent call last):
  File "./startup.py", line 477, in main
ValueError: invalid literal for int() with base 10: 'tcp://10.69.9.111:8001'
Traceback (most recent call last):
  File "./startup.py", line 495, in <module>
  File "./startup.py", line 477, in main
ValueError: invalid literal for int() with base 10: 'tcp://10.69.9.111:8001'

My guess is that the port number is tried to be read as int but it comes as a string with protocol, ip address and port. I could also be wrong. This seems like a code issue. Or if there is any other ENV variable that I should set, I will be happy to add it. The documentation is inadequate in kubernetes related things. Any help ?

@psankar have you followed the steps to install #RedisInsight on #kubernetes?

https://docs.redislabs.com/latest/ri/installing/install-k8s/

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

Then you can open your browser and point to http://localhost:8001

The issue only seems to appear when a Service is provisioned to expose the redisinsight endpoint.

You can work around the bug by creating the Deployment first, allowing the redisinsight container to start up, then create the Service. Skipping the startup.py script bug.

Super inconvenient if you’re using Helm to deploy since Helm prioritises the creation of Services before Deployments.

Is there is a way to cache node.js application with Redis

@aniket

what do you mean “cache node.js application”? please elaborate.

You may use redis or ioredis npm packages for node.js and then implement caching logic.

Below is npm packages for caching use cases using Redis:

@aniket Do you mean that you want to use Redis as a cache for a node.js application? If so, yes, you can do this. You can get more information here: https://redislabs.com/lp/node-js-redis/

I have doubts service would affect deployments, since service does not manipulate deployment/pod’s environment.

My guess is this caused by some version that you use? You can try using a more stable version (instead of latest): https://hub.docker.com/r/redislabs/redisinsight/tags

In addition to asking the question here I asked in stackoverflow and someone has recommended an answer. https://stackoverflow.com/questions/62714925/redisinsights-with-persistent-volume-in-kubernetes/63705326#63705326

வெள்., 18 செப்., 2020, பிற்பகல் 8:09 அன்று, Harry M via Redis Community Forum <redis@discoursemail.com> எழுதியது:

1 Like

The problem is with the name of the service. Since there’s a service named “redisinsight”, the new environment variables that is created via the service is passed to the redisinsight pod and there’s an environment variable conflict and so the redisinsight pod is crashing.

RedisInsight’s kubernetes documentation has been updated recently. It clearly describes how to create a RedisInsight k8s deployment with and without a service.

IT also explains what to do when there’s a service named “redisinsight” already:

Note - If the deployment will be exposed by a service whose name is ‘redisinsight’, set REDISINSIGHT_HOST and REDISINSIGHT_PORT environment variables to override the environment variables created by the service.

Please have a look at the documentation.

The error message invalid literal for int() with base 10 would seem to indicate that you are passing a string that’s not an integer to the int() function . In other words it’s either empty, or has a character in it other than a digit. You can solve this error by using Python isdigit() method to check whether the value is number or not. The returns True if all the characters are digits, otherwise False . The other way to overcome this issue is to wrap your code inside a Python try…except block to handle this error.

Sometimes the difference between Python2.x and Python3.x that leads to this ValueError: invalid literal for int() with base 10 . With Python2.x , int(str(3/2)) gives you “1”. With Python3.x , the same gives you (“1.5”): ValueError: invalid literal for int() with base 10: “1.5”.

@delonbest

RedisInsight has two port variables. RIPORT and REDISINSIGHT_PORT.

The problem is, @psankar has created a service under name REDISINSIGHT which causes k8s to pass service ip details as environment variable in the redisinsight container.

So k8s does <service_name>_PORT = “service-ip”, i.e., REDISINSIGHT_PORT=“service-ip” inside the container which is causing the crash. The solution is to not use “RI” or “Redisinsight” as service name.