DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 65

Deploy Redis Deployment on Kubernetes

Introduction

This article details the precise steps and Kubernetes configuration used to successfully deploy a single, dedicated Redis cache instance on the cluster for initial testing.

The deployment leverages essential Kubernetes primitives—ConfigMap, Deployment, and VolumeMounts—to ensure a scalable, configurable, and ephemeral testing environment.

Step 1: Configuring Redis with a ConfigMap

Before deploying the Redis application, the team needed to define a specific memory limit to prevent uncontrolled resource consumption. In Redis, this is managed by the maxmemory directive. Kubernetes ConfigMaps are the ideal mechanism for injecting such configuration data into a container.

A ConfigMap named my-redis-config was created, containing the Redis configuration data under the key redis-config.

configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-redis-config
data:
  redis-config: |
    maxmemory 2mb
Enter fullscreen mode Exit fullscreen mode

This ConfigMap was applied to the cluster:

kubectl apply -f configmap.yaml
configmap/my-redis-config created
Enter fullscreen mode Exit fullscreen mode

Step 2: Defining the Redis Deployment

The core of the solution is the Deployment manifest, which specifies the application's desired state, including the image, resource requests, and how configuration and data volumes are handled.

Key Deployment Parameters:

Parameter Value Purpose
Name redis-deployment Standard naming convention.
Image redis:alpine Uses the lightweight Redis Alpine image.
Replicas 1 Deploys a single instance for initial testing.
CPU Request 1 Guarantees 1 full CPU core for the Redis container, ensuring high performance for cache operations.
Container Port 6379 Standard Redis port for communication.

Volume Strategy for Redis

The deployment utilizes two ephemeral volumes crucial for Redis operation in a testing environment:

EmptyDir Volume (data):

  • Purpose: Provides temporary storage for Redis's dump file (if persistence were enabled) or other scratch data.
  • Mount Path: /redis-master-data
  • Nature: Data is destroyed when the Pod terminates, aligning with the temporary nature of this initial test deployment.

ConfigMap Volume (redis-config):

  • Purpose: Mounts the my-redis-config ConfigMap so the container can access the configuration file.
  • Mount Path: /redis-master
  • Usage: The Redis server command is explicitly told to use this mounted configuration file.

deployment.yaml (Simplified Manifest)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    # ... (metadata)
    spec:
      volumes:
        - name: data
          emptyDir: {}
        - name: redis-config
          configMap:
            name: my-redis-config
      containers:
        - name: redis-container
          image: redis:alpine
          # Crucial: Instructs Redis to start with the custom config file
          command: ["redis-server"]
          args: ["/redis-master/redis-config"]
          ports:
            - containerPort: 6379
          resources:
            requests:
              cpu: "1"
          volumeMounts:
            - name: data
              mountPath: /redis-master-data
            - name: redis-config
              mountPath: /redis-master
Enter fullscreen mode Exit fullscreen mode

The deployment was then applied:

thor@jumphost ~$ kubectl apply -f deployment.yaml
deployment.apps/redis-deployment created
Enter fullscreen mode Exit fullscreen mode

Step 3: Verification and Conclusion

The final step confirmed that the new caching utility was operational and ready for integration testing.

thor@jumphost ~$ kubectl get deployment redis-deployment
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
redis-deployment   1/1     1            1           21s
Enter fullscreen mode Exit fullscreen mode

The output shows that the redis-deployment is fully available (1/1 Ready, 1 Available), confirming that the Redis container is running correctly, utilizing the requested CPU resources, and applying the custom maxmemory 2mb configuration.

Top comments (0)