This project is a simple demonstration of microservices using Springboot integrated with Zipkin. It is a simple project that lists quotes from Marvel movies and users can vote which one of them they like.
The application then tally the votes.
The demo also presents better observability with Prometheus, Grafana, Loki and Jaeger/Zipkin
- MicroK8s
- Docker
- Skaffold version 1.21.1
- Helm, version 3.5.0+
- Maven
- jib-maven-plugin
- Observability tools - Prometheus, Grafana, Loki and Jaeger / Zipkin
Install MicroK8s to easily bootstrap a Kubernetes cluster. For simplicity we will use a single node MicroK8s.
$ sudo snap install microk8s --channel 1.21/stable
$ microk8s config -l > $HOME/.kube/config #Export the kubeconfig to the default location
These addons must be enabled:
- rbac
- dns
- prometheus
- jaeger
$ sudo snap install kubectl --classic
We will be installing your application to my-project
namespace.
$ kubectl create ns my-project
$ microk8s enable prometheus
$ helm repo add loki https://grafana.github.io/loki/charts # Add Grafana helm chart repo
$ helm upgrade --install loki --namespace=monitoring loki/loki-stack # Install the loki stack (loki and promtail) to monitoring namespace
Add Loki
datasource, go to Settings
. Follow the screenshots below.
Make sure that you set the http url to http://loki:3100
After that click Save and Test
To start Zipkin
skaffold run -p local
To stop Zipkin
skaffold delete -p local
Checkout the skaffold.yaml
.
In order to access zipkin, you can use port-forwarding
$ kubectl -n my-project port-forward svc/zipkin 9411:9411
You can now use your browser and point to http://localhost:9411
to access zipkin
Sample screenshot
If you are using MicroK8s, you can simply enable the jaeger addon.
microk8s enable jaeger
This will deploy Jaeger operator and the simplest Jaeger into the default
namespace.
After enabling the addon, you should see the jaeger-operator
and the simplest
pods running in the default
namespace.
kubectl get pods
NAME READY STATUS RESTARTS AGE
jaeger-operator-85fb5c9745-q2lgk 1/1 Running 0 66s
simplest-54b7455bf9-9dnlz 1/1 Running 0 58s
To access the Jaeger UI, simply do port forwarding to the simplest pod.
kubectl port-forward svc/simplest-query 16686
Forwarding from 127.0.0.1:16686 -> 16686
Forwarding from [::1]:16686 -> 16686
Then you can access it with localhost:16686
In the master
branch jaeger addon is the default collector endpoint used.
Main components are:
-
frontend/
- Hosts the web pages as well as RESTful access to backend services. -
quotes/
- This component retrieves the Marvel character quotes data stored PostgresSQL. -
votes/
- This component keeps track of the votes on each quote. -
bot/
- The bot will randomly vote quotes to simulate traffic into the kit. -
bot-go/
- Golang version of bot. -
protos/
- Keeps allproto
files in one location. -
db/
- Contains all infrastructure related components such as PostgreSQL, Redis and flyway (to perform schema migrate).db/postgres
- Postgres kubernetes manifests.db/redis
- Redis kubernetes manifests.db/schema-migrate/
- Flyway schema migration manifests. Run as KubernetesJob
.
-
zipkin/
- Stashes all Zipkin kubernetes manifests.
This is a springboot application that has a simple GUI, which calls the quote service to retrieve all the quotes, calls vote
service to cast and tally votes.
The frontend exposed these REST endpoints.
/api/quote/list
/api/vote/castVote
/api/vote/tally
UI style is brought to you by Material Kit
Go to the directory frontend/
To build the project, do a mvn clean install jib:dockerBuild
For simplicity, you can also use the provided skaffold.yaml
and run skaffold run -p local
or skaffold dev -p local
if you want continuous build and deploy to you local cluster.
You can use Postman to test the frontend's RESTFul endpoints.
This is another springboot application that retrieves quotes stored in PostgreSQL. It uses gRPC java for communication.
Stacks:
- Springboot - 2.3.4.RELEASE
- Lognet grpc-springboot-starter
Go to directory quotes
To build the project, do a mvn clean install jib:dockerBuild
In order to run the quotes
service, you need to have the Quotes DB up and running.
Use skaffold:
- Start the quotes DB (postgres)
skaffold run -p quotes-db-local
- Start the quotes service
skaffold run -p local
Checkout the skaffold.yaml
.
You can use grpcurl to test it from command line.
To get all quotes
grpcurl -plaintext localhost:50052 org.bal.vote.proto.internal.QuoteManagement/AllQuotes
To get quote by Id:
grpcurl -plaintext -d '{"quoteId":"0"}' localhost:50052 org.bal.vote.proto.internal.QuoteManagement/GetQuoteById
This is another springboot application that allows users to cast their favorite Marvel quotes. It also tallies all the votes.
It uses gRPC java for communication.
It stores its data in Redis.
Stacks:
- Springboot - 2.3.4.RELEASE
- Lognet grpc-springboot-starter
- Redis
To build the project, do a mvn clean install jib:dockerBuild
For simplicity, you can also use the provided skaffold.yaml
and run skaffold run -p local
or skaffold dev -p local
if you want continuous build and deploy to you local cluster.
In order to run the votes
service, you need to have the Quotes DB up and running.
Use skaffold:
- Start the Votes DB (Redis)
skaffold run -p votes-db-local
- Start the vote service
skaffold run -p local
Checkout the skaffold.yaml
.
You can use grpcurl to test it from command line.
To get the votes tally
grpcurl -plaintext localhost:50052 org.bal.vote.proto.internal.VoteManagement/GetAllVotes
To cast a vote:
grpcurl -plaintext -d '{"quoteId":"0"}' localhost:50052 org.bal.vote.proto.internal.VoteManagement/CastVote
To build the bot-go
project refer to here