This README explains how to deploy the Portfolio React app using Docker and Kubernetes, and how to scale it and test load step by step.
Tested with: Windows + Docker Desktop + Minikube (kubectl)
Make sure you have:
- Docker Desktop installed
- Kubernetes enabled (Docker Desktop) or Minikube running
- kubectl installed
- Docker Hub account
Check:
kubectl version --client
kubectl config current-context# Step 1: Build React app
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# Step 2: Serve using Nginx
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]Note: If using Create-React-App, replace
/app/distwith/app/build.
docker build -t chandankumar55/portfolio:latest .
docker login
docker push chandankumar55/portfolio:latestWhy? Kubernetes pulls images from registries like Docker Hub, not from your local system.
apiVersion: apps/v1
kind: Deployment
metadata:
name: portfolio-deployment
spec:
replicas: 1
selector:
matchLabels:
app: portfolio
template:
metadata:
labels:
app: portfolio
spec:
containers:
- name: portfolio
image: chandankumar55/portfolio:latest
ports:
- containerPort: 80
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"apiVersion: v1
kind: Service
metadata:
name: portfolio-service
spec:
type: NodePort
selector:
app: portfolio
ports:
- port: 80
targetPort: 80
nodePort: 30006Apply:
kubectl apply -f deployment.yaml
kubectl apply -f service.yamlCheck:
kubectl get pods
kubectl get svcAccess:
http://localhost:30006
Increase pods:
kubectl scale deployment portfolio-deployment --replicas=3Verify:
kubectl get podsKubernetes Service load-balances requests:
Request → Pod A
Request → Pod B
Request → Pod C
HPA requires Metrics Server. Works best in Minikube or cloud clusters.
minikube addons enable metrics-serverVerify:
kubectl top nodes
kubectl top podsapiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: portfolio-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: portfolio-deployment
minReplicas: 1
maxReplicas: 6
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50Apply:
kubectl apply -f hpa.yamlCheck:
kubectl get hpakubectl delete pod load-testkubectl run load-test --image=busybox --restart=Never -it -- shInside pod:
while true; do wget -q -O- http://portfolio-service; doneIn another terminal:
kubectl get pods -wIf CPU increases and metrics are working, new pods will be created automatically.
Frontend apps (React + Nginx):
- Very low CPU usage
- HPA may NOT trigger easily
Best autoscaling demo:
- Backend APIs (Node / Java / Python)
Push new image version and update:
kubectl set image deployment/portfolio-deployment portfolio=chandankumar55/portfolio:latestKubernetes will:
- Create new pod
- Remove old pod
- No downtime
Users
↓
Ingress (Nginx)
↓
Service
↓
Multiple Pods (Auto-scaled)
↓
Backend APIs
↓
Database (Replica Set)
