Skip to content

cosmopolitan033/pacman-distributed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ•ΉοΈ Pacman Multiplayer Game on Kubernetes

A real-time multiplayer Pacman game powered by Flask + Socket.IO, Redis, and a static JavaScript frontend. The entire stack is containerized and deployed on Kubernetes using Minikube, complete with observability via Prometheus, Loki, and Grafana.


πŸ“¦ Tech Stack

  • Frontend: Vanilla JavaScript, HTML, CSS
  • Backend: Flask + Flask-SocketIO
  • Real-Time Sync: Redis Pub/Sub
  • Deployment: Kubernetes (Minikube)
  • Monitoring: Prometheus, Loki, Grafana
  • Dev Tools: Docker, kubectl, Helm

πŸ› οΈ Prerequisites

Ensure you have the following installed:


πŸš€ Quickstart

1. Start Minikube with Ingress Enabled

minikube start --driver=docker
minikube addons enable ingress

2. Build Docker Images Inside Minikube

eval $(minikube docker-env)

# Frontend
docker build -t pacman-frontend ./pacman-js

# Backend
docker build -t pacman-backend ./multiplayer

3. Deploy Kubernetes Resources

kubectl apply -f k8s/

Ensure k8s/ includes:

  • backend-deployment.yaml
  • frontend-deployment.yaml
  • redis.yaml
  • ingress.yaml

4. Configure Local DNS

Edit /etc/hosts:

sudo vim /etc/hosts

Add:

127.0.0.1 pacman.local grafana.local

5. Enable Ingress Exposure

kubectl patch svc ingress-nginx-controller \
  -n ingress-nginx \
  -p '{"spec": {"type": "LoadBalancer"}}'

If still inaccessible, run:

sudo minikube tunnel

⚠️ Keep this terminal open.


6. Access the Game

Open your browser:

http://pacman.local

πŸ“Š Monitoring & Observability

This project comes with a full observability stack using Prometheus, Loki, and Grafana.

🧰 Setup Instructions

  1. Ensure minikube is running with ingress enabled.

  2. Add the following to /etc/hosts (if not already):

    127.0.0.1 grafana.local
    
  3. Navigate to the monitoring setup directory:

    cd k8s/monitoring
    ./setup-monitoring.sh
    kubectl apply -f grafana-ingress.yaml

πŸ“ˆ Access Grafana Dashboard

http://grafana.local

Default credentials:

  • Username: admin
  • Password:
    kubectl get secret loki-grafana -n monitoring \
      -o jsonpath="{.data.admin-password}" | base64 --decode

πŸ“¦ Monitoring Components

  • Prometheus: Collects metrics
    • Kubernetes cluster
    • Node & app performance
  • Loki: Aggregates logs
    • Frontend + Backend logs
    • System logs
  • Grafana: Visualization dashboards
    • Cluster overview
    • Application metrics
    • Logs

🧰 Troubleshooting Grafana Access

# Check all ingresses
kubectl get ingress -A

# Verify Grafana pod status
kubectl get pods -n monitoring

# Ensure correct Grafana service name
kubectl get svc -n monitoring

# Check Grafana logs
kubectl logs -n monitoring -l app.kubernetes.io/name=grafana

# Run minikube tunnel if access still fails
minikube tunnel

🧱 Project Structure

pacman-distributed/
β”œβ”€β”€ docker-compose.yml          # Local dev option (non-K8s)
β”œβ”€β”€ pacman-js/                  # Frontend game code
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ *.js, *.css, *.html
β”‚   └── sounds/
β”œβ”€β”€ multiplayer/                # Flask backend
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── main.py
β”œβ”€β”€ k8s/                        # Kubernetes manifests
β”‚   β”œβ”€β”€ backend-deployment.yaml
β”‚   β”œβ”€β”€ frontend-deployment.yaml
β”‚   β”œβ”€β”€ redis.yaml
β”‚   β”œβ”€β”€ ingress.yaml
β”‚   └── monitoring/             # Monitoring setup
β”‚       β”œβ”€β”€ grafana-ingress.yaml
β”‚       β”œβ”€β”€ loki-stack-values.yaml
β”‚       β”œβ”€β”€ prometheus-values.yaml
β”‚       └── setup-monitoring.sh

πŸ§ͺ Useful Kubernetes Commands

# Logs
kubectl logs -l app=pacman-backend
kubectl logs -l app=pacman-frontend

# Resources
kubectl get pods
kubectl get svc
kubectl get ingress

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors