Wednesday, 15 October 2025

Deploy Redis on Kubernetes: ConfigMap, Volumes & Resource Management

Our course you can check :-   Udemy course  


Ques:-  

Application development team observed some performance issues with one of the application that is deployed in Kubernetes cluster. After looking into number of factors, the team has suggested to use some in-memory caching utility for DB service. After number of discussions, they have decided to use Redis. Initially they would like to deploy Redis on kubernetes cluster for testing and later they will move it to production. Please find below more details about the task:

Create a redis deployment with following parameters:

Create a config map called my-redis-config having maxmemory 2mb in redis-config.

Name of the deployment should be redis-deployment, it should use

redis:alpine image and container name should be redis-container. Also make sure it has only 1 replica.

The container should request for 1 CPU.

Mount 2 volumes:

a. An Empty directory volume called data at path /redis-master-data.

b. A configmap volume called redis-config at path /redis-master.

c. The container should expose the port 6379.

Finally, redis-deployment should be in an up and running state.


Ans:-

Here’s how you can deploy Redis on your Kubernetes cluster for testing, based on the specifications you provided.


raj@jumphost ~$ cat pod.yaml


---

apiVersion: v1

kind: ConfigMap

metadata:

  name: my-redis-config

data:

  redis-config: |

    maxmemory 2mb


---

apiVersion: apps/v1

kind: Deployment

metadata:

  name: redis-deployment

spec:

  replicas: 1

  selector:

    matchLabels:

      app: redis

  template:

    metadata:

      labels:

        app: redis

    spec:

      containers:

      - name: redis-container

        image: redis:alpine

        ports:

        - containerPort: 6379

        resources:

          requests:

            cpu: "1"

        volumeMounts:

        - name: data

          mountPath: /redis-master-data

        - name: redis-config

          mountPath: /redis-master

          subPath: redis-config

      volumes:

      - name: data

        emptyDir: {}

      - name: redis-config

        configMap:

          name: my-redis-config


raj@jumphost ~$ kubectl apply -f pod.yaml 

configmap/my-redis-config created

deployment.apps/redis-deployment created


raj@jumphost ~$ kubectl get all

NAME                                   READY   STATUS    RESTARTS   AGE

pod/redis-deployment-f57d5465f-kw62p   1/1     Running   0          13s


NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE

service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   23m


NAME                               READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/redis-deployment   1/1     1            1           13s


NAME                                         DESIRED   CURRENT   READY   AGE

replicaset.apps/redis-deployment-f57d5465f   1         1         1       13s


raj@jumphost ~$ kubectl get cm

NAME               DATA   AGE

kube-root-ca.crt   1      23m

my-redis-config    1      21s


raj@jumphost ~$ kubectl describe pod redis-deployment-f57d5465f-kw62p

Name:             redis-deployment-f57d5465f-kw62p

Namespace:        default

Priority:         0

Service Account:  default

Node:             kodekloud-control-plane/172.17.0.2

Start Time:       Thu, 16 Oct 2025 03:44:56 +0000

Labels:           app=redis

                  pod-template-hash=f57d5465f

Annotations:      <none>

Status:           Running

IP:               10.244.0.5

IPs:

  IP:           10.244.0.5

Controlled By:  ReplicaSet/redis-deployment-f57d5465f

Containers:

  redis-container:

    Container ID:   containerd://651011f4257ac76011ec7632e48deb9de47b3492671e4bc82caa57aa0e539480

    Image:          redis:alpine

    Image ID:       docker.io/library/redis@sha256:59b6e694653476de2c992937ebe1c64182af4728e54bb49e9b7a6c26614d8933

    Port:           6379/TCP

    Host Port:      0/TCP

    State:          Running

      Started:      Thu, 16 Oct 2025 03:44:59 +0000

    Ready:          True

    Restart Count:  0

    Requests:

      cpu:        1

    Environment:  <none>

    Mounts:

      /redis-master from redis-config (rw,path="redis-config")

      /redis-master-data from data (rw)

      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-m4pz4 (ro)

Conditions:

  Type              Status

  Initialized       True 

  Ready             True 

  ContainersReady   True 

  PodScheduled      True 

Volumes:

  data:

    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)

    Medium:     

    SizeLimit:  <unset>

  redis-config:

    Type:      ConfigMap (a volume populated by a ConfigMap)

    Name:      my-redis-config

    Optional:  false

  kube-api-access-m4pz4:

    Type:                    Projected (a volume that contains injected data from multiple sources)

    TokenExpirationSeconds:  3607

    ConfigMapName:           kube-root-ca.crt

    ConfigMapOptional:       <nil>

    DownwardAPI:             true

QoS Class:                   Burstable

Node-Selectors:              <none>

Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s

                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s

Events:

  Type    Reason     Age   From               Message

  ----    ------     ----  ----               -------

  Normal  Scheduled  62s   default-scheduler  Successfully assigned default/redis-deployment-f57d5465f-kw62p to kodekloud-control-plane

  Normal  Pulling    61s   kubelet            Pulling image "redis:alpine"

  Normal  Pulled     59s   kubelet            Successfully pulled image "redis:alpine" in 2.39532631s (2.395343237s including waiting)

  Normal  Created    59s   kubelet            Created container redis-container

  Normal  Started    59s   kubelet            Started container redis-container


raj@jumphost ~$ kubectl logs redis-deployment-f57d5465f-kw62p

Starting Redis Server

1:C 16 Oct 2025 03:44:59.768 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

1:C 16 Oct 2025 03:44:59.768 * Redis version=8.2.2, bits=64, commit=00000000, modified=1, pid=1, just started

1:C 16 Oct 2025 03:44:59.768 * Configuration loaded

1:M 16 Oct 2025 03:44:59.769 * monotonic clock: POSIX clock_gettime

1:M 16 Oct 2025 03:44:59.769 * Running mode=standalone, port=6379.

1:M 16 Oct 2025 03:44:59.770 * <bf> RedisBloom version 8.2.3 (Git=unknown)

1:M 16 Oct 2025 03:44:59.770 * <bf> Registering configuration options: [

1:M 16 Oct 2025 03:44:59.770 * <bf>     { bf-error-rate       :      0.01 }

1:M 16 Oct 2025 03:44:59.770 * <bf>     { bf-initial-size     :       100 }

1:M 16 Oct 2025 03:44:59.770 * <bf>     { bf-expansion-factor :         2 }

1:M 16 Oct 2025 03:44:59.770 * <bf>     { cf-bucket-size      :         2 }

1:M 16 Oct 2025 03:44:59.770 * <bf>     { cf-initial-size     :      1024 }

1:M 16 Oct 2025 03:44:59.770 * <bf>     { cf-max-iterations   :        20 }

1:M 16 Oct 2025 03:44:59.770 * <bf>     { cf-expansion-factor :         1 }

1:M 16 Oct 2025 03:44:59.770 * <bf>     { cf-max-expansions   :        32 }

1:M 16 Oct 2025 03:44:59.770 * <bf> ]

1:M 16 Oct 2025 03:44:59.770 * Module 'bf' loaded from /usr/local/lib/redis/modules//redisbloom.so

1:M 16 Oct 2025 03:44:59.773 * <search> Redis version found by RedisSearch : 8.2.2 - oss

1:M 16 Oct 2025 03:44:59.773 * <search> RediSearch version 8.2.5 (Git=222ad3b)

1:M 16 Oct 2025 03:44:59.773 * <search> Low level api version 1 initialized successfully

1:M 16 Oct 2025 03:44:59.773 * <search> gc: ON, prefix min length: 2, min word length to stem: 4, prefix max expansions: 200, query timeout (ms): 500, timeout policy: return, cursor read size: 1000, cursor max idle (ms): 300000, max doctable size: 1000000, max number of search results:  1000000, 

1:M 16 Oct 2025 03:44:59.773 * <search> Initialized thread pools!

1:M 16 Oct 2025 03:44:59.773 * <search> Disabled workers threadpool of size 0

1:M 16 Oct 2025 03:44:59.773 * <search> Subscribe to config changes

1:M 16 Oct 2025 03:44:59.773 * <search> Enabled role change notification

1:M 16 Oct 2025 03:44:59.773 * <search> Cluster configuration: AUTO partitions, type: 0, coordinator timeout: 0ms

1:M 16 Oct 2025 03:44:59.774 * <search> Register write commands

1:M 16 Oct 2025 03:44:59.774 * Module 'search' loaded from /usr/local/lib/redis/modules//redisearch.so

1:M 16 Oct 2025 03:44:59.774 * <timeseries> RedisTimeSeries version 80200, git_sha=1439d4a439ca9c063e6ef124a510abff09a5d493

1:M 16 Oct 2025 03:44:59.774 * <timeseries> Redis version found by RedisTimeSeries : 8.2.2 - oss

1:M 16 Oct 2025 03:44:59.774 * <timeseries> Registering configuration options: [

1:M 16 Oct 2025 03:44:59.774 * <timeseries>     { ts-compaction-policy   :              }

1:M 16 Oct 2025 03:44:59.774 * <timeseries>     { ts-num-threads         :            3 }

1:M 16 Oct 2025 03:44:59.774 * <timeseries>     { ts-retention-policy    :            0 }

1:M 16 Oct 2025 03:44:59.774 * <timeseries>     { ts-duplicate-policy    :        block }

1:M 16 Oct 2025 03:44:59.774 * <timeseries>     { ts-chunk-size-bytes    :         4096 }

1:M 16 Oct 2025 03:44:59.774 * <timeseries>     { ts-encoding            :   compressed }

1:M 16 Oct 2025 03:44:59.774 * <timeseries>     { ts-ignore-max-time-diff:            0 }

1:M 16 Oct 2025 03:44:59.774 * <timeseries>     { ts-ignore-max-val-diff :     0.000000 }

1:M 16 Oct 2025 03:44:59.774 * <timeseries> ]

1:M 16 Oct 2025 03:44:59.774 * <timeseries> Detected redis oss

1:M 16 Oct 2025 03:44:59.774 * <timeseries> Enabled diskless replication

1:M 16 Oct 2025 03:44:59.774 * Module 'timeseries' loaded from /usr/local/lib/redis/modules//redistimeseries.so

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> Created new data type 'ReJSON-RL'

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> version: 80201 git sha: unknown branch: unknown

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> Exported RedisJSON_V1 API

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> Exported RedisJSON_V2 API

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> Exported RedisJSON_V3 API

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> Exported RedisJSON_V4 API

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> Exported RedisJSON_V5 API

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> Enabled diskless replication

1:M 16 Oct 2025 03:44:59.775 * <ReJSON> Initialized shared string cache, thread safe: false.

1:M 16 Oct 2025 03:44:59.775 * Module 'ReJSON' loaded from /usr/local/lib/redis/modules//rejson.so

1:M 16 Oct 2025 03:44:59.775 * <search> Acquired RedisJSON_V5 API

1:M 16 Oct 2025 03:44:59.776 * Server initialized

1:M 16 Oct 2025 03:44:59.776 * Ready to accept connections tcp

raj@jumphost ~$ 


Conclusion:-

In this hands-on tutorial, you'll learn how to deploy Redis on a Kubernetes cluster using best practices for configuration and resource management. We'll walk through creating a ConfigMap to set Redis memory limits, deploying Redis with specific CPU requests, and mounting volumes for data and configuration. This video is perfect for developers, DevOps engineers, and Kubernetes enthusiasts looking to integrate Redis caching into their microservices architecture.

What you'll learn:

  • Creating a Redis ConfigMap with custom memory settings
  • Deploying Redis using the redis:alpine image
  • Mounting volumes: EmptyDir for data and ConfigMap for configuration
  • Setting CPU resource requests
  • Verifying Redis deployment status

By the end of this video, you'll have a fully functional Redis deployment ready for testing in your Kubernetes environment.


No comments:

Post a Comment