Skip to main content

Lab 005: Deploy Guest Book App on Kubernetes



Requirements

The Nautilus Application Development team wants to deploy a guest book application on their Kubernetes cluster. The application will store guest entries in a Redis backend for caching and quick retrieval. This lab demonstrates a typical multi-tier application deployment pattern on Kubernetes.

Requirements include:

  • Redis backend deployment for data storage
  • Guest book frontend application deployment
  • Services to expose both Redis and the application
  • Proper environment variable configuration
  • Volume mounting for persistent data

Note

This lab demonstrates deploying a multi-tier application with frontend and backend services on Kubernetes using standard Kubernetes resource patterns.

Prerequisites

  • Access to Kubernetes cluster via kubectl
  • kubectl configured to work with the target cluster
  • Understanding of Kubernetes Deployments and Services
  • Sufficient cluster resources for frontend and backend deployments

Steps

Create the Redis backend deployment and service:

# Step 1: Create Redis deployment
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
image: redis:alpine
ports:
- containerPort: 6379
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "500m"
---
# Step 2: Create Redis service
apiVersion: v1
kind: Service
metadata:
name: redis-service
spec:
selector:
app: redis
ports:
- port: 6379
targetPort: 6379
type: ClusterIP
---
# Step 3: Create Guest Book frontend deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: guestbook-deployment
spec:
replicas: 3
selector:
matchLabels:
app: guestbook
template:
metadata:
labels:
app: guestbook
spec:
containers:
- name: guestbook
image: gcr.io/google_samples/gb-frontend:v5
ports:
- containerPort: 3000
env:
- name: REDIS_HOST
value: redis-service
- name: REDIS_PORT
value: "6379"
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "500m"
---
# Step 4: Create Guest Book frontend service
apiVersion: v1
kind: Service
metadata:
name: guestbook-service
spec:
type: NodePort
selector:
app: guestbook
ports:
- port: 3000
targetPort: 3000
nodePort: 30081

Apply the manifests:

# Apply all resources
kubectl apply -f guestbook-deployment.yaml

# Monitor deployments
kubectl get deployments
kubectl get services
kubectl get pods

Verification

Verify that the guest book application is deployed and running correctly:

# Check deployments
kubectl get deployments

# Check services
kubectl get services

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

# Check logs
kubectl logs -l app=redis
kubectl logs -l app=guestbook

# Check Redis connectivity
kubectl exec -it deployment/redis-deployment -- redis-cli PING

# Verify environment variables in guestbook pod
kubectl exec -it deployment/guestbook-deployment -- env | grep REDIS

# Access the guest book application
# Via NodePort: http://<node-ip>:30081
# Via port-forward: kubectl port-forward service/guestbook-service 3000:3000

# Test from within cluster
kubectl run -it --rm --image=ubuntu --restart=Never test-client -- \
bash -c "apt-get update && apt-get install -y curl && \
curl http://guestbook-service:3000"

Resources