Redis StatefulSet Fatal error

Good day,

I am having trouble running a Redis StatefulSet Pod in my kubernetes cluster due to this error

1:C 10 Aug 2020 08:19:47.293 # Fatal error, can’t open config file ‘/etc/redis/redis.conf’

I tried to resolve my problem by executing sudo chmod 777 -R redis and sudo chown -R $user:$user redis to all my redis directories such as:

  1. /etc/redis/redis.conf
  2. /var/lib/redis
  3. /var/run/redis
  4. /var/log/redis

but I still get this error when running my YAML file.

Cluster information:

Kubernetes version: v1.18.6
Cloud being used: bare-metal
Installation method: kubeadm
Host OS: Ubuntu 18.04
CNI and version: calico
CRI and version: Docker 19.03.6

Hello, Amin224
Your Pod is in root privilege or non-root?

Dear tej-singh-rana,

To be honest, I haven’t heard of running a Pod using root privilege before as I am new to Kubernetes, but I already learned most of the basics. I gave it a shot and tried running my YAML file using root privilege (although not advised from sources) unfortunately I am getting the same error. Please note that I have successfully ran PostgreSQL and rabbitMQ without the need of root privilege and they work perfectly unlike Redis. Here is my Redis StatefulSet configuration file:

apiVersion: apps/v1
kind: StatefulSet
  name: reddis-stateful
      app: reddis
  serviceName: reddis
  replicas: 1
              app: reddis
              tier: backend
        app: reddis
        tier: backend
      hostNetwork: true
      - name: redis
        image: bitnami/redis:latest
                allowPrivilegeEscalation: false
                runAsUser: 0
        #- configMapRef:
        #name: redis-conf
          ["/bin/sh", "-c", "redis-server /etc/redis/redis.conf" ]
                # - "redis-server"
          - "/etc/redis/redis.conf"
            #- "--protected-mode"
            #- "yes"
          - name: ALLOW_EMPTY_PASSWORD
            value: "yes"
            cpu: "100m"
            memory: "100Mi"
            - name: redis
              containerPort: 6379
              protocol: "TCP"
            - name: cluster
              containerPort: 16379
              protocol: "TCP"
              - name: "redis-conf"
                mountPath: "/etc/redis"
                #- name: "redis-data"
                #mountPath: "/var/lib/redis"
      - name: "redis-conf"
                claimName: reddis

Actually i don’t know how you are treating your Pods so i just shared my opinions.
I noticed your yaml file and command should be like this
command: ["/bin/sh", “-c”,“redis-server”, “/etc/redis/redis.conf” ]

The Docker page for the bitnami/redis image says the the redis.conf is in a different location to /etc/redis/redis.conf

You are passing the param /etc/redis/redis.conf to the redis binary so you need to make sure you have created that file.
Are you sure that file exists in that location?
Also you are mounting a persistent volume to /etc/redis so you need to make sure you are creating a redis.conf inside that directory after the volume is mounted.

Kind regards,

Dear stephendotcarter,

Thank you for pointing out about the bitnami image it seems you are correct regarding the location, so after reading from the link you have provided I followed the steps to overwrite the redis.conf using my own configuration file by running this command, Unfortunately it didn’t work.

sudo docker run --name bitnamiredis -e ALLOW_EMPTY_PASSWORD=yes -v /etc/redis/redis.conf:/opt/bitnami/redis/mounted-etc/redis.conf -v /var/lib/redis:/bitnami/redis/data bitnami/redis:latest

To answer your question yes I am aware of the existence of the redis.conf file in my /etc/redis directory and I made sure to remove root permission so that my Pod can access it but to no avail.


While working my way to a solution, I tried so many things and eventually I commented out these commands in my StatefulSet configuration YAML file and it worked like a charm. Sorry I do not know about these commands as I am still new to k8s cluster. I hope this can help someone in the future

  - "redis-server"
  - "/etc/redis/redis.conf"
  - "--protected-mode"
  - "no"