Giter Club home page Giter Club logo

microservices-demo's Introduction

Hipster Shop: Cloud-Native Microservices Demo Application

This project contains a 10-tier microservices application. The application is a web-based e-commerce app called “Hipster Shop” where users can browse items, add them to the cart, and purchase them.

Google uses this application to demonstrate use of technologies like Kubernetes/GKE, Istio, and gRPC. This application works on any Kubernetes cluster (such as a local one), as well as Google Kubernetes Engine. It’s easy to deploy with little to no configuration.

If you’re using this demo, please ★Star this repository to show your interest!

Screenshots

Home Page Checkout Screen
Screenshot of store homepage Screenshot of checkout screen

Service Architecture

Hipster Shop is composed of many microservices written in different languages that talk to each other over gRPC.

Architecture of microservices

Find Protocol Buffers Descriptions at the ./pb directory.

Service Language Description
frontend Go Exposes an HTTP server to serve the website. Does not require signup/login and generates session IDs for all users automatically.
cartservice Go Stores the items in the user's shopping cart in Redis and retrieves it.
productcatalogservice Go Provides the list of products from a JSON file and ability to search products and get individual products.
currencyservice Go Converts one money amount to another currency. Uses real values fetched from European Central Bank. It's the highest QPS service.
paymentservice Go Charges the given credit card info (mock) with the given amount and returns a transaction ID.
shippingservice Go Gives shipping cost estimates based on the shopping cart. Ships items to the given address (mock)
emailservice Go Sends users an order confirmation email (mock).
checkoutservice Go Retrieves user cart, prepares order and orchestrates the payment, shipping and the email notification.
recommendationservice Go Recommends other products based on what's given in the cart.
adservice Java Provides text ads based on given context words.
loadgenerator Python/Locust Continuously sends requests imitating realistic user shopping flows to the frontend.

Features

  • Kubernetes/GKE: The app is designed to run on Kubernetes (both locally on "Docker for Desktop", as well as on the cloud with GKE).
  • gRPC: Microservices use a high volume of gRPC calls to communicate to each other.
  • Istio: Application works on Istio service mesh.
  • Skaffold: Application is deployed to Kubernetes with a single command using Skaffold.
  • Synthetic Load Generation: The application demo comes with a background job that creates realistic usage patterns on the website using Locust load generator.

Installation

We offer the following installation methods:

  1. Running locally (~20 minutes) You will build and deploy microservices images to a single-node Kubernetes cluster running on your development machine. There are two options to run a Kubernetes cluster locally for this demo:

  2. Running on Google Kubernetes Engine (GKE)” (~30 minutes) You will build, upload and deploy the container images to a Kubernetes cluster on Google Cloud.

Option 1: Running locally

💡 Recommended if you're planning to develop the application or giving it a try on your local cluster.

  1. Install tools to run a Kubernetes cluster locally:

    • kubectl (can be installed via gcloud components install kubectl)
    • Local Kubernetes cluster deployment tool:
    • skaffold (ensure version ≥v0.20)
  2. Launch the local Kubernetes cluster with one of the following tools:

    • Launch Minikube (tested with Ubuntu Linux). Please, ensure that the local Kubernetes cluster has at least:

      • 4 CPU's
      • 4.0 GiB memory

      To run a Kubernetes cluster with Minikube using the described configuration, please run:

    minikube start --cpus=4 --memory 4096
    • Launch “Docker for Desktop” (tested with Mac/Windows). Go to Preferences:
      • choose “Enable Kubernetes”,
      • set CPUs to at least 3, and Memory to at least 6.0 GiB
      • on the "Disk" tab, set at least 32 GB disk space
  3. Run kubectl get nodes to verify you're connected to “Kubernetes on Docker”.

  4. Make sure you have istio running in your cluster already with Jaeger add-on.

    1. Install and run Istio. Only follow up to the 'Install Istio' step. Don't deploy their sample application.
    2. Install Jaeger
  5. Run deploy.sh (first time will be slow, it can take ~20 minutes).

    1. First, this script sets the Docker env to that of minikube.
    2. Second, it builds all Docker images.
    3. Third, it will run skaffold to deploy the built Docker images to minikube.
    4. It will most likely encounter an error deploying the services due to timeout exception. Don't worry about this. It takes a bit for the services to start up in Kubernetes.
  6. Run kubectl get pods to verify the Pods are ready and running.

  7. To check out traces, run istioctl dashboard jaeger

  8. To check out the application frontend:

    1. Run kubectl get services | grep frontend to get the frontend node port.
    2. Run minikube ip to get the ip address of your minikube cluster.
    3. Go to http://$MINIKUBE_IP:$FRONTEND_PORT in your browser to see Hipster Shop.

Option 2: Running on Google Kubernetes Engine (GKE)

  1. Install tools to run a cluster on the GKE:

    • kubectl (can be installed via gcloud components install kubectl)
    • skaffold (ensure version ≥v0.20)
    • docker
  2. Create a new project for Google Kubernetes Engine

  3. Run gcloud init to configure the GCloud SDK.

  4. Create a Google Kubernetes Engine cluster and make sure kubectl is pointing to the cluster.

    gcloud services enable container.googleapis.com
    gcloud container clusters create demo --enable-autoupgrade \
        --enable-autoscaling --min-nodes=3 --max-nodes=10 --num-nodes=5 --zone=us-central1-a
    kubectl get nodes
    
  5. Enable Google Container Registry (GCR) on your GCP project and configure the docker CLI to authenticate to GCR:

    gcloud services enable containerregistry.googleapis.com
    gcloud auth configure-docker -q
  6. Prepare the GKE cluster for istio.

    1. Prepare GKE cluster for Istio. Skip the first step which sets up a new cluster. You can get the $CLUSTER_NAME, $ZONE and $PROJECT_ID from the Google Cloud CLI.
  7. Make sure you have istio running in your cluster already with Jaeger add-on. You might have to update the Kubernetes master (from the GCloud webpage) for newer versions of Istio.

    1. Install and run Istio. Only follow up to the 'Install Istio' step. Don't deploy their sample application.
    2. Install Jaeger
  8. In the root of this repository, run skaffold run --default-repo=gcr.io/[PROJECT_ID], where [PROJECT_ID] is your GCP project ID.

    This command:

    • builds the container images
    • pushes them to GCR
    • applies the ./kubernetes-manifests deploying the application to Kubernetes.

    If this command fails, try re-running it! Also, sometimes this command fails but ends up setting up the pods and deployments.

    Troubleshooting: If you get "No space left on device" error on Google Cloud Shell, you can build the images on Google Cloud Build: Enable the Cloud Build API, then run skaffold run -p gcb --default-repo=gcr.io/[PROJECT_ID] instead.

  9. Check if all the pods are running.

    kubectl get pods
    
  10. Find the IP address of your application, then visit the application on your browser to confirm installation.

    kubectl get service frontend-external
    
  11. To check out traces, run istioctl dashboard jaeger Note, you can view each trace as a JSON file and save it.

Updating Services

When making code changes to a specifc service you need to rebuild the docker image. Then you have to delete the Kubernetes pod with that is running the service so that when it rescales the deployment, it grabs the new docker image.

Cleanup

If you've deployed the application with skaffold run command, you can run skaffold delete to clean up the deployed resources.

If you've deployed the application with kubectl apply -f [...], you can run kubectl delete -f [...] with the same argument to clean up the deployed resources.

Conferences featuring Hipster Shop


This is not an official Google project.

microservices-demo's People

Contributors

ahmetb avatar triplewy avatar daniel-sanche avatar askmeegs avatar saimsalman36 avatar mtwo avatar rghetia avatar jkwlui avatar orthros avatar sebright avatar davidstanke avatar jba avatar ymotongpoo avatar michaelawyu avatar idvoretskyi avatar kalyanac avatar ocervell avatar rakyll avatar howardjohn avatar jsirianni avatar mdelio avatar mehdime avatar mshahat avatar oussemos avatar caulagi avatar riccardomc avatar rvrignaud avatar thesandlord avatar selcukusta avatar mrtrustor 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.