forked from gitea_admin/simple-node
4526d164ef6c4436e8a612b34313dfd56ea4ed8a
Simple Microservices Todo App
This project consists of two separate microservices: a backend and a frontend.
Project Structure
backend/: Node.js Express API.frontend/: Node.js Express server serving static HTML.
How to Separate into Two Repositories
If you want to host these on separate GitHub repositories:
-
Backend Repository:
cd backend git init git add . git commit -m "Initial commit for backend" # Create a new repo on GitHub and follow their instructions to push -
Frontend Repository:
cd frontend git init git add . git commit -m "Initial commit for frontend" # Create a new repo on GitHub and follow their instructions to push
Local Development (Monorepo mode)
To run both services together from this root directory:
- Install root dependencies:
npm install - Install sub-service dependencies:
npm run install:all - Start both:
npm start
CI/CD with Jenkins, Harbor & Kubernetes
The Jenkinsfile in each microservice is now fully integrated with Kubernetes:
- Build & Push: Builds the Docker image and pushes it to Harbor.
- Dynamic Deployment: Uses
sedto inject the unique build image tag into the microservice-specific Kubernetes manifest. - K8s Rollout: Executes
kubectl applyand waits for a successful rollout status.
Pipeline Configuration:
- Ensure
kubectlis installed and configured on your Jenkins agent. - Update the
HARBOR_*andK8S_CREDENTIALS_IDvariables in eachJenkinsfile. - Each microservice uses its own
k8s-deployment.yamlfile.
Kubernetes Deployment (Manual)
Each microservice contains its own Kubernetes manifest for complete independence:
backend/k8s-deployment.yamlfrontend/k8s-deployment.yaml
1. Update Manifests
- In
backend/k8s-deployment.yaml, update theimagefield with your actual Harbor image path (or leave asIMAGE_PATH_PLACEHOLDERif using Jenkins). - In
frontend/k8s-deployment.yaml:- Update the
imagefield with your Harbor image path. - Update the
BACKEND_URLin theConfigMapsection to point to your backend service's accessible IP/URL (e.g., your Node IP and the 30001 NodePort).
- Update the
2. Deploy
Run the following commands:
kubectl apply -f backend/k8s-deployment.yaml
kubectl apply -f frontend/k8s-deployment.yaml
3. Verify
kubectl get pods
kubectl get services
The services are configured as NodePort:
- Frontend: Port
30000 - Backend: Port
30001
Using Docker Compose
Alternatively, run everything using Docker:
docker-compose up --build
Description
Languages
HTML
59.9%
JavaScript
30.8%
Dockerfile
9.3%