/microservices

A demo project which shows how to use Quarkus backed grpc microservices in k8s along with istio

Primary LanguageHTMLApache License 2.0Apache-2.0

A Kubernetes + Istio + Quarkus Demo

Pre-requisites

  1. JDK17 - If you have sdkman and have installed temurin 17.0.5-tem then you can just run sdk env (This project already has an sdk env initialisation config file) to activate Temurin 17.0.5.

  2. Docker Desktop (or) Rancher Desktop (or) Colima

  3. minikube installed

  4. Istio installed

  5. grpCurl is installed (This is just for testing needs)

  6. The command docker ps works fine (This is to just test if docker is up and running properly)

  7. minikube add-ons enabled using the commands:

    • minikube addons enable dashboard
    • minikube addons enable metrics-server
  8. gRPC benchmarking and load testing tool is installed.

Steps to be followed after cloning this repository.

  1. Start minikube using the command minikube start --cpus 6 --memory 8192 everytime you delete your deployment and trigger a fresh one so that the request reaches your k8s cluster)
  2. Install istio on your k8s cluster via istioctl install
  3. Install all the istio default addons via kubectl apply -f ~/tools/istio/istio-1.16.1/samples/addons (Here we are assuming that the istio installation directory is ~/tools/istio/istio-1.16.1). This will help us view the Kiali, Grafana, Prometheus, Jaegar dashboards.
  4. Install the otel collector (Open Telemetry Collector) by running kubectl apply -f deploy/otel-collector-config.yml This will ensure that our distributed tracing works fine.
  5. Create a namespace (This is where our apps will be deployed) via kubectl create ns rationale-emotions. For additional details read at the bottom.
  6. Enable Envoy proxy auto injection via Istio: kubectl label ns rationale-emotions istio-injection=enabled
  7. Setup minikube docker daemon for accessing our locally built image: eval $(minikube -p minikube docker-env)
  8. Build the docker images using ./mvnw clean package -Dquarkus.container-image.build=true
  9. Once the images have been built now deploy the images into kubernetes using the shell script ./install-to-k8s.sh rationale-emotions (Here rationale-emotions is our namespace)
  10. Open up the tunnel in a new terminal using minikube tunnel (Remember to kill this and restart this,
  11. Now you can open up an RPC client such as grpcurl (or) BloomRPC and then interact with the service. Try accessing the end point com.rationaleemotions.generated.DashboardService.dashBoardDetails with the username as rajnikanth
  12. Remember to run (8) in the same terminal wherein you ran (7)
  13. If you would like to delete our app, run the shell script ./delete-from-k8s.sh rationale-emotions
  14. If you would like to generate the kubernetes manifest files (Yes, Quarkus lets you generate them too!!!) then you can do it using ./mvnw clean package
  15. To view the Jaegar dashboard you can run istioctl dashboard jaeger (In a new terminal because this should be running)

Here's an example of how a grpcurl invocation looks like

grpCurl Example
➜  microservices git:(main) grpcurl -d '{"userName":"rajnikanth"}' --plaintext \
--import-path dashboard-app/src/main/proto \
--proto dashboard-app/src/main/proto/dashboard.proto \
localhost:10030 com.rationaleemotions.generated.DashboardService/dashBoardDetails
{
  "basicDetails": {
    "username": "rajnikanth",
    "fullName": {
      "firstName": "Sivaji",
      "lastName": "Rao"
    },
    "emailAddress": "sivaji.rao@india.com"
  },
  "favoriteMovies": [
    {
      "movieId": 31,
      "language": "tamil",
      "movieName": "b3d03050-76d7-40bb-a40b-536061bf3f6e",
      "durationInMins": 73
    },
    {
      "movieId": 32,
      "language": "tamil",
      "movieName": "e90bb8b8-6269-476e-b233-f9015362ec0f",
      "durationInMins": 51
    }
  ],
  "recentlyWatchedMovies": [
    {
      "movieId": 301,
      "language": "tamil",
      "movieName": "e578fb45-4871-4ad6-984c-c7312e690800",
      "durationInMins": 18
    },
    {
      "movieId": 302,
      "language": "tamil",
      "movieName": "9b9edd74-26de-45fe-a757-277a486e09f3",
      "durationInMins": 1
    }
  ]
}

Shell scripts

There are some useful shell scripts created.

  1. install-to-k8s.sh - Allows you to install our demo microservices to a namespace of your choice. Invoke using ./install-to-k8s.sh my-fancy-namespace
  2. delete-from-k8s.sh - Deletes whatever demo microservices you installed via (1). Invoke using ./delete-from-k8s.sh my-fancy-namespace
  3. fire.sh - Generates one request against our demo dashboard.
  4. generate_load.sh - Generates a load for 1 minute against our demo dashboard.

Some fancy commands

  1. istioctl dashboard jaeger - Opens up the Jaegar UI
  2. istioctl dashboard - Tells you what other things you can open up.
  3. minikube dashboard - Opens up the Minikube dashboard which shows the internals of the k8s cluster.

Namespaces

There are essentially two ways in which one can deal with namespaces viz.,

  1. When applying a manifest file (You will find the apply commands in the install-to-k8s.sh script) using the -n <namespaceNameGoesHere> option in the kubectl apply command.
  2. In the Quarkus application configuration file src/main/resourcs/application.properties via the parameter quarkus.kubernetes.namespace

In this demo project, I have chosen to go with (1).

References