A containerized Next.js application with CI/CD pipeline and Kubernetes deployment.
- Next.js 14 with TypeScript and Tailwind CSS
- Multi-stage Docker build for optimized production images
- GitHub Actions CI/CD pipeline with GHCR integration
- Kubernetes deployment with health checks and auto-scaling
- Security best practices with non-root user and minimal attack surface
- Node.js 18+
- Docker
- Minikube
- kubectl
- Git
git clone <your-repo-url>
cd <repo-name>
npm install
npm run dev
Visit http://localhost:3000
npm run build
npm start
docker build -t nextjs-devops-app .
docker run -p 3000:3000 nextjs-devops-app
docker ps # Check container health status
-
Enable GitHub Container Registry:
- Go to repository Settings β Actions β General
- Enable "Read and write permissions" for GITHUB_TOKEN
-
Update Image Reference:
- Edit
k8s/deployment.yaml
- Replace
YOUR_USERNAME
with your GitHub username
- Edit
-
Push to Main Branch:
git add . git commit -m "Initial commit" git push origin main
The workflow will automatically:
- Build Docker image
- Push to GitHub Container Registry
- Tag with branch name and commit SHA
minikube start
minikube addons enable ingress
Edit k8s/deployment.yaml
and replace the image URL:
image: ghcr.io/YOUR_USERNAME/nextjs-docker-k8s-deployment:latest
kubectl apply -f k8s/
# Check pods
kubectl get pods
# Check services
kubectl get services
# Check deployment status
kubectl rollout status deployment/nextjs-app
Option 1: NodePort Service
minikube service nextjs-service --url
Option 2: Port Forward
kubectl port-forward service/nextjs-service 8080:80
Visit http://localhost:8080
Option 3: Minikube IP
minikube ip
# Visit http://<minikube-ip>:30080
kubectl logs -l app=nextjs-app
kubectl describe deployment nextjs-app
kubectl describe service nextjs-service
kubectl scale deployment nextjs-app --replicas=5
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β GitHub Repo βββββΆβ GitHub Actions βββββΆβ GHCR β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Minikube ββββββ kubectl apply ββββββ K8s Manifests β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
After successful GitHub Actions build, your image will be available at:
ghcr.io/YOUR_USERNAME/nextjs-docker-k8s-deployment:latest
-
Image Pull Error:
# Make repository public or configure image pull secrets kubectl create secret docker-registry ghcr-secret \ --docker-server=ghcr.io \ --docker-username=YOUR_USERNAME \ --docker-password=YOUR_TOKEN
-
Service Not Accessible:
# Check if minikube tunnel is running minikube tunnel
-
Pod CrashLoopBackOff:
kubectl logs <pod-name> kubectl describe pod <pod-name>
- β Next.js application created
- β Multi-stage Dockerfile with best practices
- β GitHub Actions workflow for CI/CD
- β GHCR integration with proper tagging
- β Kubernetes deployment with replicas
- β Health checks (liveness & readiness probes)
- β Service configuration for external access
- β Comprehensive documentation
- Security: Non-root user, minimal base image
- Performance: Multi-stage build, standalone output
- Reliability: Health checks, resource limits
- Scalability: Horizontal pod autoscaling ready
- Monitoring: Structured logging, metrics endpoints
Repository URL: https://github.com/YOUR_USERNAME/nextjs-docker-k8s-deployment
GHCR Image URL: ghcr.io/YOUR_USERNAME/nextjs-docker-k8s-deployment:latest
# Trigger workflow