Skip to content

Welcome to the Full Stack Realtime Chat App project, where we're building a scalable and secure real-time chat experience using the latest technologies

License

Notifications You must be signed in to change notification settings

dev7nsh/full-stack_chatApp_k8s

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Full-Stack Chat App - Kubernetes Deployment

Screencast.from.2025-10-06.14-11-16.webm

A complete three-tier chat application deployed on Kubernetes with separate frontend, backend, and database components.

πŸ—οΈ Architecture Overview

graph TB
    subgraph "Kubernetes Cluster"
        subgraph "chat-app Namespace"
            subgraph "Frontend Tier"
                FE[Frontend Pod<br/>nginx:80]
                FES[Frontend Service<br/>Port: 80]
            end
            
            subgraph "Backend Tier"
                BE[Backend Pod<br/>Node.js:5001]
                BES[Backend Service<br/>Port: 5001]
            end
            
            subgraph "Database Tier"
                DB[MongoDB<br/>Port: 27017]
                DBS[MongoDB Service<br/>Port: 27017]
            end
        end
    end
    
    subgraph "External Access"
        USER[πŸ‘€ User]
        PFBE[Port Forward<br/>Backend: 5001]
        PFFE[Port Forward<br/>Frontend: 80]
    end
    
    USER --> PFFE
    USER --> PFBE
    PFFE --> FES
    PFBE --> BES
    FES --> FE
    BES --> BE
    BE --> DBS
    DBS --> DB
    FE --> BES
Loading

πŸš€ Quick Start

Prerequisites

  • Kubernetes cluster (kind, minikube, or cloud provider)
  • kubectl configured
  • Docker images available:
    • dockerdev7nsh/chatapp-frontend
    • dockerdev7nsh/chatapp-backend

1. Create Kubernetes Cluster (using kind)

# Create cluster with custom configuration
kind create cluster --config cluster.yaml --name main

# Verify cluster
kubectl cluster-info
kubectl get nodes

2. Deploy Application

# Clone the repository
git clone <your-repo-url>
cd full-stack_chatApp_k8s/K8s

# Create namespace
kubectl apply -f namespace.yaml

# Deploy backend
kubectl apply -f backend-deployement.yaml
kubectl apply -f service-backend.yaml

# Deploy frontend
kubectl apply -f frontend-deployement.yaml
kubectl apply -f frontend-service.yaml

# Verify deployments
kubectl get all -n chat-app

3. Access Application

# Port forward backend (API)
kubectl port-forward service/backend -n chat-app 5001:5001 --address=0.0.0.0 &

# Port forward frontend (UI)
kubectl port-forward service/chatapp-service-frontend -n chat-app 8080:80 --address=0.0.0.0 &

Access the application:

πŸ“ Project Structure

full-stack_chatApp_k8s/
β”œβ”€β”€ K8s/
β”‚   β”œβ”€β”€ namespace.yaml              # Creates chat-app namespace
β”‚   β”œβ”€β”€ backend-deployement.yaml    # Backend deployment (Node.js)
β”‚   β”œβ”€β”€ service-backend.yaml        # Backend service
β”‚   β”œβ”€β”€ frontend-deployement.yaml   # Frontend deployment (nginx)
β”‚   β”œβ”€β”€ frontend-service.yaml       # Frontend service
β”‚   └── cluster.yaml                # Kind cluster configuration
β”œβ”€β”€ src/                           # Application source code
└── README.md                      # This file

πŸ”§ Configuration Details

Backend Configuration

  • Image: dockerdev7nsh/chatapp-backend
  • Port: 5001
  • Environment Variables:
    • PORT=5001
    • MONGODB_URI=mongodb://localhost:27017/chatapp

Frontend Configuration

  • Image: dockerdev7nsh/chatapp-frontend
  • Port: 80
  • Nginx configuration for API proxy

Labels & Selectors

  • Backend: app: chat-app-backend
  • Frontend: app: chat-app-frontend

πŸ› οΈ Deployment Flow

flowchart TD
    A[Start] --> B[Create Kind Cluster]
    B --> C[Apply Namespace]
    C --> D[Deploy Backend]
    D --> E[Deploy Backend Service]
    E --> F[Deploy Frontend]
    F --> G[Deploy Frontend Service]
    G --> H[Verify Pods Running]
    H --> I{All Pods Ready?}
    I -->|No| J[Check Logs]
    J --> K[Fix Issues]
    K --> I
    I -->|Yes| L[Setup Port Forwarding]
    L --> M[Access Application]
    M --> N[End]
    
    style A fill:#90EE90
    style N fill:#FFB6C1
    style I fill:#FFE4B5
    style J fill:#FFA07A
Loading

πŸ“‹ Commands Reference

Cluster Management

# Create cluster
kind create cluster --config cluster.yaml --name main

# Delete cluster
kind delete cluster --name main

# List clusters
kind get clusters

Application Management

# Apply all configurations
kubectl apply -f .

# Check status
kubectl get all -n chat-app
kubectl get pods -n chat-app
kubectl get services -n chat-app

# View logs
kubectl logs <pod-name> -n chat-app
kubectl logs -f <pod-name> -n chat-app  # Follow logs

# Describe resources
kubectl describe pod <pod-name> -n chat-app
kubectl describe service <service-name> -n chat-app

Port Forwarding

# Background port forwarding
kubectl port-forward service/backend -n chat-app 5001:5001 --address=0.0.0.0 &
kubectl port-forward service/chatapp-service-frontend -n chat-app 8080:80 --address=0.0.0.0 &

# Check running port forwards
ps aux | grep port-forward

# Stop port forwarding
kill <PID>
# or
pkill -f "kubectl port-forward"

Debugging

# Check pod status
kubectl get pods -n chat-app -o wide

# Shell into pod
kubectl exec -it <pod-name> -n chat-app -- /bin/bash

# Check events
kubectl get events -n chat-app --sort-by='.lastTimestamp'

# Check resource usage
kubectl top pods -n chat-app
kubectl top nodes

πŸ” Troubleshooting

Common Issues

  1. Pod in CrashLoopBackOff

    kubectl logs <pod-name> -n chat-app
    kubectl describe pod <pod-name> -n chat-app
  2. Service not accessible

    # Check if service endpoints are available
    kubectl get endpoints -n chat-app
    
    # Verify label selectors match
    kubectl get pods -n chat-app --show-labels
  3. Port forward connection refused

    # Check if application is listening on correct port
    kubectl exec -it <pod-name> -n chat-app -- netstat -tulpn
  4. Image pull errors

    # Check if image exists and is accessible
    docker pull dockerdev7nsh/chatapp-backend
    docker pull dockerdev7nsh/chatapp-frontend

Label Mismatch Fix

If you get "selector does not match template labels" error:

# Ensure deployment selector matches pod labels
kubectl get deployment <deployment-name> -n chat-app -o yaml

πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

Welcome to the Full Stack Realtime Chat App project, where we're building a scalable and secure real-time chat experience using the latest technologies

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 96.8%
  • Dockerfile 2.5%
  • Other 0.7%