Skip to main content

Lab 001: Deploy Redis Deployment on Kubernetes



Requirements

The Nautilus 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:

      • An Empty directory volume called data at path /redis-master-data
      • A configmap volume called redis-config at path /redis-master
      • The container should expose the port 6379
  • Finally, redis-deployment should be in an up and running state.

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.


Note

This lab demonstrates creating a Redis deployment with ConfigMap and volume management on Kubernetes. All resources will be deployed to the default namespace.

Prerequisites

  • Access to Kubernetes cluster via kubectl
  • kubectl configured to work with the target cluster
  • Sufficient cluster resources for Redis deployment

Steps

Create and apply the Redis deployment manifest with ConfigMap:

# 1. Create the ConfigMap and Deployment manifest
---
kind: ConfigMap
apiVersion: v1
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: "1000m"
volumeMounts:
- name: data
mountPath: /redis-master-data
- name: redis-config
mountPath: /redis-master
volumes:
- name: data
emptyDir: {}
- name: redis-config
configMap:
name: my-redis-config
items:
- key: redis-config
path: redis.conf

Apply the manifest and verify:

# 2. Apply the manifest
kubectl apply -f deploy.yml

# 3. Verify the deployment is running
kubectl get pod,deployment,cm

Verification

Verify that all resources are created and running:

# Check pods
kubectl get pods -l app=redis
kubectl get pods

# Check deployment status
kubectl get deployment redis-deployment

# Verify ConfigMap exists
kubectl get configmap my-redis-config

# Check Redis container logs
kubectl logs -l app=redis

# Connect to Redis pod and verify configuration
kubectl exec -it <pod-name> -- redis-cli CONFIG GET maxmemory
kubectl exec -it <pod-name> -- redis-cli PING

Resources