Skip to content

Kubernetes voting app demo with microservices, Redis, PostgreSQL, and load balancing. Educational project for container orchestration./

jainalphin/voting-app-kubernetes-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Kubernetes Voting Application

A distributed voting application deployed on Kubernetes, demonstrating microservices architecture with multiple components working together to provide a complete voting solution.

Architecture Overview

This application consists of five main components:

  • Voting App (3 replicas) - Frontend web application for casting votes
  • Result App (3 replicas) - Web application for displaying voting results
  • Redis - In-memory data store for temporary vote storage
  • Database (PostgreSQL) - Persistent storage for final vote counts
  • Worker - Background service that processes votes from Redis to PostgreSQL

Components

1. Voting App Pods

  • Replicas: 3 instances for high availability
  • Purpose: Web interface where users can cast their votes
  • Technology: Typically Python Flask or Node.js
  • Service: ClusterIP service for internal communication
  • LoadBalancer: External access for users

2. Result App Pods

  • Replicas: 3 instances for high availability
  • Purpose: Web interface displaying real-time voting results
  • Technology: Typically Node.js or similar
  • Service: ClusterIP service for internal communication
  • LoadBalancer: External access for viewing results

3. Redis Pod

  • Replicas: 1 instance
  • Purpose: Temporary storage for incoming votes
  • Service: ClusterIP service for internal communication only
  • Storage: In-memory, ephemeral

4. Database Pod (PostgreSQL)

  • Replicas: 1 instance
  • Purpose: Persistent storage for processed votes
  • Service: ClusterIP service for internal communication only
  • Storage: Persistent volume for data durability

5. Worker Pod

  • Replicas: 1 instance
  • Purpose: Background processor that moves votes from Redis to PostgreSQL
  • No Service: Internal processing component

Deployment Steps

Step 1: Create Deployments

# Deploy all application components
kubectl apply -f voting-app-deployment.yaml
kubectl apply -f result-app-deployment.yaml
kubectl apply -f redis-deployment.yaml
kubectl apply -f postgres-deployment.yaml
kubectl apply -f worker-deployment.yaml

Step 2: Create Services (ClusterIP)

# Create internal services
kubectl apply -f voting-app-service.yaml
kubectl apply -f result-app-service.yaml
kubectl apply -f redis-service.yaml
kubectl apply -f postgres-service.yaml

Step 3: Create LoadBalancer Services

# Create external access services
kubectl apply -f voting-app-loadbalancer.yaml
kubectl apply -f result-app-loadbalancer.yaml

Service Configuration

Internal Services (ClusterIP)

  • voting-app-service: Port 80 → voting app pods
  • result-app-service: Port 80 → result app pods
  • redis-service: Port 6379 → Redis pod
  • postgres-service: Port 5432 → PostgreSQL pod

External Services (LoadBalancer)

  • voting-app-lb: External access to voting interface
  • result-app-lb: External access to results interface

Data Flow

  1. Vote Submission: Users access the voting app through LoadBalancer and submit votes
  2. Temporary Storage: Votes are stored in Redis for quick processing
  3. Vote Processing: Worker service reads votes from Redis
  4. Persistent Storage: Worker processes and stores votes in PostgreSQL
  5. Result Display: Result app reads from PostgreSQL to display current results

Networking

  • Pod-to-Pod Communication: All internal communication uses ClusterIP services
  • External Access: LoadBalancer services expose voting and result apps
  • Service Discovery: Kubernetes DNS enables service name resolution

Monitoring and Troubleshooting

Check Pod Status

kubectl get pods
kubectl describe pod <pod-name>

Check Services

kubectl get services
kubectl describe service <service-name>

View Logs

kubectl logs <pod-name>
kubectl logs -f <pod-name>  # Follow logs

Access Applications

# Get external IPs
kubectl get services -o wide

# Port forward for local testing
kubectl port-forward service/voting-app-service 8080:80
kubectl port-forward service/result-app-service 8081:80

Scaling

Scale Voting App

kubectl scale deployment voting-app --replicas=5

Scale Result App

kubectl scale deployment result-app --replicas=5

Cleanup

# Delete all resources
kubectl delete -f .
# Or delete by labels
kubectl delete all -l app=voting-app

About

Kubernetes voting app demo with microservices, Redis, PostgreSQL, and load balancing. Educational project for container orchestration./

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published