philipz / okta-java-spring-k8s-istio-microservices-example

An example microservices application using JHipster, Spring, Istio and Kubernetes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloud Native Java Microservices with Spring Boot, Istio, Kubernetes and JHipster

This is an example application accompanying the blog post Cloud Native Java Microservices with JHipster and Istio on the Okta dev blog.

Pre-requisites

kind

  1. Create kind cluster by config. kind create cluster --config=./kubernetes/kind.yaml

  2. Install Istio istioctl install --set profile=demo -y

  3. Apply the patch to the Istio ingress controller. kubectl patch deployments.apps -n istio-system istio-ingressgateway -p '{"spec":{"template":{"spec":{"containers":[{"name":"istio-proxy","ports":[{"containerPort":8080,"hostPort":80},{"containerPort":8443,"hostPort":443}]}]}}}}'

Create a GKE Cluster and Install Istio

To deploy the stack to Google Kubernetes Engine, we need to create a cluster and install Istio. So let's begin by creating a cluster using Google Cloud SDK.

Create a cluster

Ensure you are logged into the gcloud CLI and run the below command to create a GKE cluster.

# set region and zone
gcloud config set compute/region europe-west1
gcloud config set compute/zone europe-west1-b
# Create a project and enable container APIs
gcloud projects create jhipster-demo-okta # You need to also enable billing via GUI
gcloud config set project jhipster-demo-okta
gcloud services enable container.googleapis.com

# Create GKE Cluster
gcloud container clusters create hello-hipster \
   --num-nodes 4 \
   --machine-type n1-standard-2

This could take anywhere between 5 to 15 minutes. --machine-type is important as we need more CPU than available in the default setup. Once the cluster is created, it should be set automatically as the current Kubernetes context. You can verify that by running kubectl config current-context. If the new cluster is not set as the current context, you can set it by running gcloud container clusters get-credentials hello-hipster.

Install Istio to cluster

As of writing this, I'm using Istio version 1.13.4. You can install istioctl by running the below command, preferably from the home directory.

export ISTIO_VERSION=1.13.4
curl -L https://istio.io/downloadIstio | sh -
cd istio-$ISTIO_VERSION
export PATH=$PWD/bin:$PATH

You should now be able to run istioctl from the command line. Now, we can use the CLI to Install Istio to the GKE cluster. Istio provides a few Helm profiles out of the box. We will use the demo profile for demo purposes. You can choose the production or dev profile as well. The command should install Istio and setup everything required on our cluster.

istioctl install --set profile=demo -y

Note: If you run into any trouble with firewall or user privilege issues, please refer to GKE setup guide from Istio.

Once the installation is complete, we need to fetch the External IP of the Istio Ingress Gateway. If you are using KDash, you can see it on the services tab, or you can run this command to get it using kubectl: kubectl get svc istio-ingressgateway -n istio-system

Install Observability tools

Istio also provides addons for most of the popular monitoring and observability tools. Lets install Grafana, Prometheus, Kiali and Zipkin on our cluster. These are pre-configured to work with the telemetry data provided by Istio. Ensure you are in the folder where you installed Istio, like istio-1.13.4.

cd istio-$ISTIO_VERSION
kubectl apply -f samples/addons/grafana.yaml
kubectl apply -f samples/addons/prometheus.yaml
kubectl apply -f samples/addons/kiali.yaml
kubectl apply -f samples/addons/extras/zipkin.yaml

If we look at the istio-system namespace, we can see all the Istio components along with Grafana, Prometheus, Kiali, and Zipkin running. You can also see this by running kubectl get pods -n istio-system.

Deploy the microservice stack to GKE

We are ready to deploy now. First, we need to build and push the images to the registry. We can use the handy Jib commands provided by JHipster. Navigate to each of the microservice folders and run the command below.

cd store && ./gradlew bootJar -Pprod jib -Djib.to.image=philipz/store
cd invoice && ./gradlew bootJar -Pprod jib -Djib.to.image=philipz/invoice
cd notification && ./gradlew bootJar -Pprod jib -Djib.to.image=philipz/notification
cd product && ./gradlew bootJar -Pprod jib -Djib.to.image=philipz/product

Once the images are pushed to the Docker registry, we can deploy the stack using the handy script provided by JHipster. Navigate to the kubernetes folder created by JHipster and run the following command.

cd kubernetes
./kubectl-apply.sh -f

Once the deployments are done, we must wait for the pods to be in RUNNING status. Useful links will be printed on the terminal; make a note of them.

Cleanup

Once you are done with experiments, make sure to delete the cluster you created so that you don't end up with a big bill from Google. You can delete the cluster from the Google Cloud Console GUI or via the command line using the below command.

gcloud container clusters delete hello-hipster

About

An example microservices application using JHipster, Spring, Istio and Kubernetes

License:Apache License 2.0


Languages

Language:Java 64.2%Language:TypeScript 31.1%Language:HTML 2.1%Language:JavaScript 1.0%Language:SCSS 0.7%Language:Dockerfile 0.4%Language:Shell 0.3%Language:CSS 0.2%Language:Batchfile 0.0%