Welcome to the official guide for deploying a Full-Stack Chat Application on your local machine. Whether you're a student, a professional, or someone exploring the world of Kubernetes and Docker, this guide is designed to help you deploy the app with ease.
In this tutorial, you will learn how to:
- Set up a local Kubernetes environment using Kind.
- Deploy a Full-Stack Chat Application (Frontend, Backend, MongoDB) on Kubernetes.
- Explore an alternative deployment using Docker Compose.
Before we start the deployment, ensure that you have the following tools installed and set up on your machine:
Kind is a tool that lets you run Kubernetes clusters in Docker containers. It’s lightweight, easy to use, and perfect for local development.
For Windows (PowerShell):
curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.25.0/kind-windows-amd64
Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exeFor Windows (WSL - Windows Subsystem for Linux):
# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kindFor Linux:
# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.25.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kindKubectl is the tool we’ll use to manage Kubernetes clusters. You’ll use it to interact with your local Kubernetes cluster and deploy resources.
For x86_64 Architecture:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"For ARM64 Architecture:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"Validate the downloaded binary:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256) kubectl" | sha256sum --checkInstall kubectl:
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# OR if there’s an issue with your root permissions:
chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin/kubectlVerify kubectl installation:
kubectl version --client --output=yamlDocker is required for building and running containers locally. Follow the instructions on the official Docker website to download and install Docker on your system.
Once installed, you can verify Docker by running:
docker --versionWith the prerequisites set up, let’s grab the code for the chat application. Run the following commands:
git clone https://github.com/iemafzalhassan/full-stack_chatApp.gitcd full-stack_chatApp/k8sgit checkout DevOpsThis will:
- Clone the project repository from GitHub.
- Navigate into the
k8sfolder, which contains the Kubernetes configuration files for the deployment.
Now that we have everything in place, let’s start deploying the chat application to Kubernetes. Below are the detailed steps to deploy each component of the application using Kind.
# Create cluster using config
kind create cluster --config k8s/kind-config.yaml
# Verify cluster is running
kubectl cluster-infoA namespace is a way to organize your resources. It keeps the app's resources isolated and easy to manage. To create the namespace for our chat app, run:
# Create namespace
kubectl apply -f k8s/namespace.yaml
# Verify namespace creation
kubectl get namespacesMongoDB is used for storing chat messages and user data. To deploy MongoDB, apply the following commands:
# Create MongoDB PVC
kubectl apply -f k8s/mongo-pvc.yaml -n chat-app
# Create backend secrets
kubectl apply -f k8s/backend-secrets.yaml -n chat-app
# Create frontend nginx config
kubectl apply -f k8s/frontend-configmap.yaml -n chat-app# Deploy MongoDB
kubectl apply -f k8s/mongodb-deployment.yaml -n chat-app
kubectl apply -f k8s/mongodb-service.yaml -n chat-app
# Wait for MongoDB pod to be ready
kubectl wait --for=condition=Ready pods -l app=mongodb -n chat-app --timeout=120sThe backend service processes messages and user authentication. To deploy the backend, run the following commands:
# Deploy Backend
kubectl apply -f k8s/backend-deployment.yaml -n chat-app
kubectl apply -f k8s/backend-service.yaml -n chat-app
# Wait for Backend pod to be ready
kubectl wait --for=condition=Ready pods -l app=backend -n chat-app --timeout=120sThese files will deploy the backend service, which will handle all API requests from the frontend.
The frontend is the user interface where people interact with the chat app. To deploy the frontend, use these commands:
# Deploy Frontend
kubectl apply -f k8s/frontend-deployment.yaml -n chat-app
kubectl apply -f k8s/frontend-service.yaml -n chat-app
# Wait for Frontend pod to be ready
kubectl wait --for=condition=Ready pods -l app=frontend -n chat-app --timeout=120sThis will launch the frontend UI and expose it to the web.
Once the app is deployed, it's crucial to verify that everything is running smoothly.
# Check all resources
kubectl get all -n chat-app
# Check pod logs if needed
kubectl logs -f -l app=frontend -n chat-app
kubectl logs -f -l app=backend -n chat-app
kubectl logs -f -l app=mongodb -n chat-appThe application is exposed through NodePort services: http://localhost:8080
You can verify the service URLs using:
# Get service details
kubectl get svc -n chat-appIf a pod isn’t working as expected, you can describe it to get more information:
kubectl describe pod <pod-name> -n chat-appThis will give you detailed information about a specific pod, including any potential issues.
When you're done, you can clean up using:
# Delete all resources in namespace
kubectl delete namespace chat-app
# Delete the kind cluster
kind delete cluster --name chat-app-clusterIf you prefer a simpler local setup using Docker Compose, you can deploy the chat app without Kubernetes. Here’s how to do it:
docker-compose up -d --buildThis command:
- Starts all services defined in the
docker-compose.ymlfile. - Runs the services in detached mode (
-d). - Rebuilds the Docker images (
--build) in case of any changes.
Once the services are running, you can access the app at http://localhost:8080.
Congratulations! You’ve successfully deployed the Full-Stack Chat Application using Kubernetes (via Kind) or Docker Compose. Whether you're using Kubernetes for a more robust, scalable solution or Docker Compose for a simpler local setup, your chat app is now running!