You can create any number of microservices you want (2 at least).
Better is one of them should connect to database. If you are uncomfortable with coding, You can use the code that was presented in the class(Frontend & Backend). If can’t use Database in code, so just add a Database service in docker-compose like Mysql or Mongodb with related environment variables.
The microservices each should have their own Github repository.
The repositories should contain the manifests for docker-compose of your microservices.
For now, you will build and push the docker image to your Dockerhub manually for your code.
So you will have at least 2 repositories based on the number of your microservices:
Backend: Exposes an API endpoint. This repo will contain thebackend code,Dockerfileto build image,Docker composemanifest to deploy it.Frontend: Calls the backend and displays the result. This repo will contain thefrontend code,Dockerfileto build image,Docker composemanifest to deploy it.
- The frontend code is maintained at https://github.com/aliarslan-cs/devops-workshop-frontend. I productionized the docker image using flags from node.js and using a multi-stage build. The Docker Hub repository is hosted at https://hub.docker.com/repository/docker/aliarsal/workshop-project-frontend.
- The backend code is maintained at https://github.com/aliarslan-cs/devops-workshop-backend. I used golang to create a simple Nicknames registry app and also used a multi-stage builds for its docker image. The Docker Hub repository is hosted at https://hub.docker.com/repository/docker/aliarsal/workshop-project-backend.
create pipeline for the services and repos.
Add CI/CD to the above microservices repos. Better to add both Github Actions Workflow and Jenkins but one of them is compulsory… For a sample golang-app, you can see the Github Actions workflow at https://github.com/kahootali/golang-sample-app/tree/master/.github/workflows It will be same for all language apps, only Dockerfile will change… Github Action to build and push Docker Image https://github.com/marketplace/actions/build-and-push-docker-images
The CI/CD pipelines for both backend and frontend application are created using GitHub Actions.
- the-frontend: https://github.com/aliarslan-cs/devops-workshop-frontend/blob/main/.github/workflows/ci-cd.yml
- the-backend: https://github.com/aliarslan-cs/devops-workshop-backend/blob/main/.github/workflows/ci-cd.yml
Add Kubernetes manifests to deploy your application in the repositories.
When the pipeline of any of your microservice runs, it will build & push a new docker image tag, so you will update that docker image tag in your K8s manifests and apply it on a Kubernetes cluster i.e. minikube in your case. The Kubernetes manifest should include
- Deployment:
- Service: exposing frontend on NodePort and backend on Cluster IP
The deployment manifests for frontend and backend application are available at:
- the-frontend: https://github.com/aliarslan-cs/devops-workshop-project/tree/main/frontend
- the-backend: https://github.com/aliarslan-cs/devops-workshop-project/tree/main/backend
The frontend is exposed on Nodeport. The backend had to be exposed on Nodeport as well, as the frontend application is made using React.js which runs primarily on the frontend and communicates to the backend using APIs.
This is optional phase but do try to complete this, as having knowledge is one thing, but once you implement all this, you can easily work on Kubernetes in future…
In Backend Kubernetes Deployment, add Resources for request and limits on memory & CPU (need to read it yourself), add Probes(readiness & liveness).
Backend should have environment variables NAME and PASSWORD that should be set from a Secret named backend and a file feedback.txt on path /user/feedback.txt that should be set from Configmap named backend where you can give the feedback for the course
Also in the backend repository add Configmap & Secret manifest files containing above environment variables and file respectively
Also add RBAC files to run above deployment with a Service Account with permissions to get, list, watch Pods cluster wide
Also if you used DB for your app, try to deploy the DB from the public helm chart Can also add helm chart for the application ( totally optional )
The helm chart scripts for the-db are maintained at https://github.com/aliarslan-cs/devops-workshop-project/tree/main/db.
Note: I could not work on the remaining tasks of Phase 4 yet.