Practice deploying a full-stack application (Vite React frontend + Hono backend + PostgreSQL) to Kubernetes with Helm charts.
./deploy.shThis script will:
- Deploy PostgreSQL (only if not already running)
- Build and deploy the backend with latest changes
- Build and deploy the frontend with latest changes
- Wait for all pods to be ready
- Show you how to access all services
If you prefer to do it step by step:
# 1. Build Docker image
eval $(minikube docker-env)
docker build -f app/Dockerfile -t vite-app:latest .
# 2. Deploy with Helm
helm install vite-app ./helm/vite-app
# Or upgrade if already installed:
helm upgrade vite-app ./helm/vite-app
# 3. Access the app
minikube service vite-appJust run the deploy script again - it will rebuild and upgrade automatically:
./deploy.shOr manually:
eval $(minikube docker-env)
docker build -f app/Dockerfile -t vite-app:latest .
helm upgrade vite-app ./helm/vite-app./scripts/deploy-postgres.shThis script will:
- Add Bitnami Helm repository
- Install PostgreSQL with minikube-optimized settings
- Show connection information and credentials
From within the cluster:
- Host:
postgresql - Port:
5432 - Username:
postgres - Password: (shown after deployment, or get it with command below)
- Database:
postgres
From local machine:
# Port forward
kubectl port-forward svc/postgresql 5432:5432
# Then connect to localhost:5432Connect via psql:
kubectl run -it --rm psql --image=postgres:alpine --restart=Never -- \
psql -h postgresql -U postgres -d postgres# Get password
kubectl get secret postgresql -o jsonpath="{.data.postgres-password}" | base64 -d
# View logs
kubectl logs -l app.kubernetes.io/name=postgresql
# Check status
kubectl get pods -l app.kubernetes.io/name=postgresql
# Uninstall
helm uninstall postgresqlPrerequisites: PostgreSQL must be deployed first.
./scripts/deploy-backend.shThis script will:
- Build the Docker image using minikube's Docker daemon
- Install or upgrade the Helm chart
- Wait for pods to be ready
- Show connection information
From within the cluster:
- Service name:
backend - Port:
3000
From local machine:
# Port forward
kubectl port-forward svc/backend 3000:3000
# Then access at http://localhost:3000Or use minikube service:
minikube service backendGET /- API informationGET /health- Health check (includes database connection status)GET /api/hello- Simple hello endpointGET /api/db/test- Test database connection
Test endpoints:
# Get backend URL
BACKEND_URL=$(minikube service backend --url)
# Test endpoints
curl $BACKEND_URL/health
curl $BACKEND_URL/api/hello
curl $BACKEND_URL/api/db/test- Stateless architecture - Supports multiple replicas (default: 2)
- PostgreSQL connection - Connects to PostgreSQL using Kubernetes service DNS
- Health checks - Includes database connection verification
- Connection pooling - Efficient database connection management
# View logs
kubectl logs -l app=backend
# View logs from specific pod
kubectl logs <pod-name>
# Check status
kubectl get pods -l app=backend
# Scale replicas
kubectl scale deployment backend --replicas=3
# Uninstall
helm uninstall backend# Check status
kubectl get pods
kubectl get svc
# View logs
kubectl logs -l app=vite-app
# Uninstall
helm uninstall vite-appk8s-playground/
├── app/ # Vite React app (frontend)
├── backend/ # Hono backend app
│ ├── src/
│ │ ├── index.ts # Main server file
│ │ └── db.ts # PostgreSQL connection module
│ ├── package.json
│ └── tsconfig.json
├── helm/
│ ├── vite-app/ # Frontend Helm chart
│ │ ├── Chart.yaml
│ │ ├── values.yaml
│ │ └── templates/
│ │ ├── deployment.yaml
│ │ ├── service.yaml
│ │ └── configmap.yaml
│ ├── backend/ # Backend Helm chart
│ │ ├── Chart.yaml
│ │ ├── values.yaml
│ │ └── templates/
│ │ ├── deployment.yaml
│ │ └── service.yaml
│ └── postgresql-values.yaml # PostgreSQL configuration
├── app/
│ └── Dockerfile # Frontend Dockerfile
├── backend/
│ └── Dockerfile # Backend Dockerfile
├── nginx.conf
├── deploy.sh # Frontend deployment script
├── deploy.sh # Main deployment script (deploys everything)
└── scripts/
├── deploy-backend.sh # Backend deployment script
├── deploy-frontend.sh # Frontend deployment script
└── deploy-postgres.sh # PostgreSQL deployment script