Full Stack Deployment in Kubernetes: A Simple Walkthrough
Deploying full stack applications can be tricky. You need to make sure the frontend, backend, and database all work together, even when they are running in different places. Kubernetes helps solve this problem by organizing and managing your app in containers.
Kubernetes is a powerful tool that makes it easier to deploy, scale, and manage applications. It can run your frontend, backend, and database in small units called pods, which are grouped and controlled for better performance and reliability.
If you’re learning through a full stack developer course, understanding Kubernetes is a great skill to add. It will help you deploy your projects like real production applications, just like large companies do.
In this blog we will walk you through a simple example of deploying a full stack application using Kubernetes.
What Is Kubernetes?
Kubernetes (also called K8s) is a platform for managing containerized applications. It works with Docker or other container tools to handle:
- Deployment of apps
- Automatic restarts if something crashes
- Load balancing (sharing traffic across different parts of the app)
- Scaling up or down based on usage
- Networking and communication between app parts
Instead of running your app manually, Kubernetes does it for you in a more organized and reliable way.
What Does a Full Stack App Look Like?
Let’s say your app has three parts:
- Frontend: A React app that users see
- Backend: A Node.js and Express server that handles data and logic
- Database: MongoDB for storing user data
You want all of these to work together. In Kubernetes, each of them runs in its own pod (or group of pods), and Kubernetes connects them using services.
Step 1: Dockerize Your Application
Before you use Kubernetes, your app should be containerized. That means wrapping each part in a Docker container.
For example:
Frontend Dockerfile (client/Dockerfile):
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
RUN npm install -g serve
CMD [“serve”, “-s”, “build”]
EXPOSE 3000
Backend Dockerfile (server/Dockerfile):
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
CMD [“npm”, “start”]
EXPOSE 5000
Build and push these images to a container registry like Docker Hub.
docker build -t yourname/frontend ./client
docker push yourname/frontend
docker build -t yourname/backend ./server
docker push yourname/backend
This step is important. Kubernetes pulls your images from this registry when creating containers.
Step 2: Create Kubernetes Manifests
Now we’ll write configuration files for Kubernetes. These files are written in YAML and tell Kubernetes what to do.
1. MongoDB Deployment and Service
Create a file called mongo.yaml:
apiVersion: v1
kind: Service
metadata:
name: mongo
spec:
ports:
– port: 27017
selector:
app: mongo
—
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo
spec:
replicas: 1
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
containers:
– name: mongo
image: mongo
ports:
– containerPort: 27017
This will create a MongoDB pod and allow other services to talk to it.
2. Backend Deployment and Service
Create a file called backend.yaml:
apiVersion: v1
kind: Service
metadata:
name: backend
spec:
selector:
app: backend
ports:
– port: 5000
targetPort: 5000
type: ClusterIP
—
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
spec:
replicas: 1
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
– name: backend
image: yourname/backend
ports:
– containerPort: 5000
env:
– name: MONGO_URL
value: mongodb://mongo:27017/mydatabase
This file connects the backend to MongoDB using the internal service name mongo.
If you’re practicing cloud deployment in your full stack developer classes, this kind of service setup is exactly how real-world apps are built.
3. Frontend Deployment and Service
Create a file called frontend.yaml:
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
selector:
app: frontend
ports:
– port: 80
targetPort: 3000
type: LoadBalancer
—
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
– name: frontend
image: yourname/frontend
ports:
– containerPort: 3000
This setup allows users to access your frontend using a public IP (if you’re using a cloud provider like AWS or GCP).
Step 3: Deploy to Kubernetes
If you are running Kubernetes locally (using Minikube or Docker Desktop), you can apply the configs like this:
kubectl apply -f mongo.yaml
kubectl apply -f backend.yaml
kubectl apply -f frontend.yaml
To check that everything is running:
kubectl get pods
kubectl get services
If you’re using Minikube, you can open the frontend in your browser:
minikube service frontend
Now your full stack app is up and running, with all parts talking to each other inside Kubernetes.
Step 4: Scaling and Updates
One of the best parts of Kubernetes is scaling. You can easily increase the number of pods for your frontend or backend:
kubectl scale deployment frontend –replicas=3
kubectl scale deployment backend –replicas=3
This means more copies of your app are running, which can handle more users.
You can also update your app by changing the Docker image and applying the config again. Kubernetes will slowly replace the old pods with new ones—this is called a rolling update.
Step 5: Clean Up
When you’re done, you can remove everything:
kubectl delete -f mongo.yaml
kubectl delete -f backend.yaml
kubectl delete -f frontend.yaml
Cleaning up resources helps you save system memory and avoid confusion during future deployments.
Why Use Kubernetes for Full Stack Deployment?
Here’s why Kubernetes is useful for full stack applications:
- It keeps your app running, even if something crashes
- It manages multiple containers easily
- It handles traffic and scaling automatically
- It works on your local machine, servers, and the cloud
- It’s used by big companies and teams worldwide
If you’re enrolled in a full stack developer course, learning Kubernetes will make you stand out. It shows that you know how to build and deploy modern, scalable web applications.
Final Thoughts
Kubernetes may seem complex at first, but with practice, it becomes easier to use. In this guide, we walked through:
- Dockerizing your frontend and backend
- Writing Kubernetes configs for each part of the app
- Connecting frontend, backend, and database
- Deploying and scaling your app with simple commands
With this understanding, you can now deploy a full stack app just like professionals do. It’s a powerful skill that will help in personal projects, job interviews, and real company work.
If you are learning through full stack developer classes, try building a project and deploying it in Kubernetes. This will give you a big advantage and help you understand how apps work in the real world.
Now it’s time to try it out yourself. Happy coding and deploying!
Contact Us:
Name: ExcelR – Full Stack Developer Course in Hyderabad
Address: Unispace Building, 4th-floor Plot No.47 48,49, 2, Street Number 1, Patrika Nagar, Madhapur, Hyderabad, Telangana 500081
Phone: 087924 83183
