# 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: 1. **Backend Repository**: ```bash 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 ``` 2. **Frontend Repository**: ```bash 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: 1. Install root dependencies: `npm install` 2. Install sub-service dependencies: `npm run install:all` 3. Start both: `npm start` ### CI/CD with Jenkins, Harbor & Kubernetes The `Jenkinsfile` in each microservice is now fully integrated with Kubernetes: 1. **Build & Push**: Builds the Docker image and pushes it to **Harbor**. 2. **Dynamic Deployment**: Uses `sed` to inject the unique build image tag into the microservice-specific Kubernetes manifest. 3. **K8s Rollout**: Executes `kubectl apply` and waits for a successful rollout status. **Pipeline Configuration:** - Ensure `kubectl` is installed and configured on your Jenkins agent. - Update the `HARBOR_*` and `K8S_CREDENTIALS_ID` variables in each `Jenkinsfile`. - Each microservice uses its own `k8s-deployment.yaml` file. ## Kubernetes Deployment (Manual) Each microservice contains its own Kubernetes manifest for complete independence: - `backend/k8s-deployment.yaml` - `frontend/k8s-deployment.yaml` ### 1. Update Manifests - In `backend/k8s-deployment.yaml`, update the `image` field with your actual Harbor image path (or leave as `IMAGE_PATH_PLACEHOLDER` if using Jenkins). - In `frontend/k8s-deployment.yaml`: - Update the `image` field with your Harbor image path. - Update the `BACKEND_URL` in the `ConfigMap` section to point to your backend service's accessible IP/URL (e.g., your Node IP and the 30001 NodePort). ### 2. Deploy Run the following commands: ```bash kubectl apply -f backend/k8s-deployment.yaml kubectl apply -f frontend/k8s-deployment.yaml ``` ### 3. Verify ```bash 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: ```bash docker-compose up --build ```