Giter Site home page Giter Site logo

rajibmitra / spring-petclinic-gcp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saturnism/spring-petclinic-gcp

0.0 2.0 0.0 465 KB

Spring PetClinic Microservices on GCP

License: Other

Dockerfile 1.96% Shell 0.04% Java 59.15% CSS 10.87% HTML 14.79% JavaScript 13.19%

spring-petclinic-gcp's Introduction

Google Cloud Native Spring Boot PetClinic

Example Petclinic deployment on Google Cloud Platform into Google Kubernetes Engine with Istio. This is based on Spring PetClinic Microservices

This example has:

  • Observability and Monitoring
    • Stackdriver Trace
    • Stackdriver Monitorning
    • Stackdriver Logging
    • Stackdriver Debugging
    • Stackdriver Profiling
  • Spring Boot Petclinic Example with Google Cloud Native configuration
    • Spring Cloud GCP
    • Removed Eureka, Hystrix, Ribbon, Config Server, Gateway, and many other components, because they are provided by Kubernetes and Istio.
      • Eureka -> Kubernetes Service
      • Config Server -> Kubernetes Config Map
      • Gateway -> Kubernetes Ingress
      • Hystrix -> Istio
      • Ribbon -> Istio
  • Build
    • Spotify's dockerfile-maven-plugin
  • DevOps
    • Travis CI

Google Cloud Platform Project

Create a new Project if you haven't done so already.

$ export PROJECT_ID=...
$ gcloud project create $PROJECT_ID

Set the default Project ID:

$ gcloud config set core/project $PROJECT_ID

Kubernetes Engine Cluster

Use gcloud to provision a multi-zone Kubernetes Engine cluster.

$ gcloud services enable compute.googleapis.com container.googleapis.com
$ gcloud beta container clusters create petclinic-cluster \
    --cluster-version=1.10.5 \
    --region=us-central1 \
    --num-nodes=2 \
    --machine-type=n1-standard-2 \
    --enable-autorepair \
    --enable-stackdriver-kubernetes

Stackdriver Prometheus Scraper

Install Prometheus scraper to propagate Prometheus metrics to Stackdriver Monitoring.

$ kubectl apply -f https://storage.googleapis.com/stackdriver-prometheus-documentation/rbac-setup.yml --as=admin --as-group=system:masters
$ curl -s https://storage.googleapis.com/stackdriver-prometheus-documentation/prometheus-service.yml | \
  sed -e "s/\(\s*_kubernetes_cluster_name:*\).*/\1 'petclinic-cluster'/g" | \
  sed -e "s/\(\s*_kubernetes_location:*\).*/\1 'us-central1'/g" | \
  sed -e "s/\(\s*_stackdriver_project_id:*\).*/\1 '${PROJECT_ID}'/g" | \
  kubectl apply -f -

Istio

Install the basics:

$ cd ~/
$ export ISTIO_VERSION=0.7.1
$ curl -L https://git.io/getLatestIstio | sh -
$ cd istio-$ISTIO_VERSION
$ kubectl apply -f install/kubernetes/istio.yaml --as=admin --as-group=system:masters

Spanner

$ gcloud spanner instances create petclinic --config=regional-us-central1 --nodes=1 --description="PetClinic Spanner Instance"
$ gcloud spanner databases create petclinic --instance=petclinic
$ gcloud spanner databases ddl update petclinic --instance=petclinic --ddl="$(<db/spanner.ddl)"

Debugging and Profiling

$ gcloud services enable cloudprofiler.googleapis.com clouddebugger.googleapis.com

Generate Service Account

Create a new Service Account for the microservices:

$ gcloud iam service-accounts create petclinic --display-name "PetClinic Service Account"

Grant IAM Roles to the Service Account:

$ gcloud projects add-iam-policy-binding $PROJECT_ID \
     --member serviceAccount:petclinic@$PROJECT_ID.iam.gserviceaccount.com \
     --role roles/cloudprofiler.agent
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
     --member serviceAccount:petclinic@$PROJECT_ID.iam.gserviceaccount.com \
     --role roles/clouddebugger.agent
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
     --member serviceAccount:petclinic@$PROJECT_ID.iam.gserviceaccount.com \
     --role roles/cloudtrace.agent
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
     --member serviceAccount:petclinic@$PROJECT_ID.iam.gserviceaccount.com \
     --role roles/spanner.databaseUser

Create a new JSON Service Account Key. Keep it secure!

$ gcloud iam service-accounts keys create ~/petclinic-service-account.json \
    --iam-account petclinic@$PROJECT_ID.iam.gserviceaccount.com

Build

Compile and Install to Maven

$ ./mvnw install

Build Docker Images

Build all images:

$ ./mvnw package install -PbuildDocker

Build just one image:

$ ./mvnw package install -PbuildDocker -pl spring-petclinic-customers-service

Run

Docker Compose

Update docker-compose.yml file so that secrets.petclinic-credentials.file points to the JSON file.

Run everything:

$ echo "PROJECT_ID=$PROJECT_ID" > .env
$ docker-compose up

Kubernetes

Store Service Account as a Kubenetes Secret:

$ kubectl create secret generic petclinic-credentials --from-file=$HOME/petclinic-service-account.json

Deploy Application:

$ kubectl apply -f kubernetes/

Try It Out

Find the Ingress IP address

$ kubectl get ingress
petclinic-ingress   *         X.X.X.X   80        

Open the browser to see if the app is working!

Travis CI/CD

Install the Travis CLI:

$ brew install travis

Or, follow the Travis CLI Installation instruction

Login to Travis

$ travis login

Or, optionally login with travis login --github-token=... to avoid typing password, etc.

Configure Docker credentials:

$ travis env set DOCKER_USERNAME your_username
$ travis env set DOCKER_PASSWORD your_password

Create a CI/CD Service Account, assign roles, and create a JSON file:

$ gcloud iam service-accounts create travis-ci --display-name "Travis CI/CD"
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
     --member serviceAccount:travis-ci@$PROJECT_ID.iam.gserviceaccount.com \
     --role roles/container.developer
$ gcloud iam service-accounts keys create ~/travis-ci-petclinic.json \
    --iam-account travis-ci@$PROJECT_ID.iam.gserviceaccount.com

Encrypt and Store the Travis CI/CD Service Account:

$ travis encrypt-file ~/travis-ci-petclinic.json

Travis asks you to add a line to before_install section. Make sure it's updated.

Set the Google Cloud Platform Project ID for reference in the build:

$ travis env set PROJECT_ID $PROJECT_ID

Commit .travis.yml

spring-petclinic-gcp's People

Contributors

saturnism avatar

Watchers

rajib avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.