Giter Club home page Giter Club logo

tjwallas / microservices-demo-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googlecloudplatform/microservices-demo

0.0 2.0 0.0 4.84 MB

Sample cloud-native application composed of 10 microservices showcasing Kubernetes, Istio, gRPC, OpenCensus and Skaffold.

Home Page: http://frontend-external-static.default.svc.hipstershop.us-central1-b.microservices-demo-app.apps.kubernetes.tips/

License: Apache License 2.0

Dockerfile 1.52% Shell 1.37% Java 3.21% C# 49.89% Batchfile 0.93% Go 15.44% JavaScript 2.53% Python 21.13% HTML 3.97%

microservices-demo-1'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 Kubernetes, GKE, Istio, Stackdriver, gRPC and similar cloud-native technologies nowadays.

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 C# Stores the items in the user's shipping 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 Node.js Converts one money amount to another currency. Uses real values fetched from European Central Bank. It's the highest QPS service.
paymentservice Node.js Charges the given credit card info (hypothetically😇) 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 (hypothetically😇)
emailservice Python Sends users an order confirmation email (hypothetically😇).
checkoutservice Go Retrieves user cart, prepares order and orchestrates the payment, shipping and the email notification.
recommendationservice Python 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.
  • OpenCensus Tracing: Most services are instrumented using OpenCensus trace interceptors for gRPC/HTTP.
  • Stackdriver APM: Many services are instrumented with Profiling, Tracing and Debugging. In addition to these, using Istio enables features like Request/Response Metrics and Context Graph out of the box. When it is running out of Google Cloud, this code path remains inactive.
  • 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

Note: that the first build can take up to 20-30 minutes. Consequent builds will be faster.

Option 1: Running locally with “Docker for Desktop”

💡 Recommended if you're planning to develop the application.

  1. Install tools to run a Kubernetes cluster locally:

    • kubectl (can be installed via gcloud components install kubectl)
    • Docker for Desktop (Mac/Windows): It provides Kubernetes support as noted here.
    • skaffold
  2. Launch “Docker for Desktop”. Go to Preferences and choose “Enable Kubernetes”.

  3. Run kubectl get nodes to verify you're connected to “Kubernetes on Docker”.

  4. Run skaffold run (first time will be slow, it can take ~20-30 minutes). This will build and deploy the application. If you need to rebuild the images automatically as you refactor he code, run skaffold dev command.

  5. Run kubectl get pods to verify the Pods are ready and running. The application frontend should be available at http://localhost:80 on your machine.

Option 2: Running on Google Kubernetes Engine (GKE)

💡 Recommended for demos and making it available publicly.

  1. Install tools specified in the previous section (Docker, kubectl, skaffold)

  2. 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
    
     kubectl get nodes
    
  3. 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
    
  4. 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.

    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.

  5. Find the IP address of your application, then visit the application on your browser to confirm installation.

    kubectl get service frontend-external
    

    Troubleshooting: A Kubernetes bug (will be fixed in 1.12) combined with a Skaffold bug causes load balancer to not to work even after getting an IP address. If you are seeing this, run kubectl get service frontend-external -o=yaml | kubectl apply -f- to trigger load balancer reconfiguration.

(Optional) Deploying on a Istio-installed cluster

Note: you followed GKE deployment steps above, run skaffold delete first to delete what's deployed.

  1. Create a GKE cluster.

  2. Install Istio without mutual TLS authentication option.

    (Optional) If you'd like to enable mTLS in the demo app, you need to make a few changes to the deployment manifests:

    • kubernetes-manifests/frontend.yaml: delete "livenessProbe" and "readinessProbe" fields.
    • kubernetes-manifests/loadgenerator.yaml: delete "initContainers" field.
  3. Install the automatic sidecar injection (annotate the default namespace with the label):

    kubectl label namespace default istio-injection=enabled
    
  4. Apply the manifests in ./istio-manifests directory.

    kubectl apply -f ./istio-manifests
    

    This is required only once.

  5. Deploy the application with skaffold run --default-repo=gcr.io/[PROJECT_ID].

  6. Run kubectl get pods to see pods are in a healthy and ready state.

  7. Find the IP address of your istio gateway Ingress or Service, and visit the application.

    INGRESS_HOST="$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')"
    
    echo "$INGRESS_HOST"
    
    curl -v "http://$INGRESS_HOST"
    

Note to fellow Googlers: Please fill out the form at go/microservices-demo if you are using this application.

This is not an official Google project.

microservices-demo-1's People

Contributors

ahmetb avatar daniel-sanche avatar mtwo avatar jkwlui avatar orthros avatar sebright avatar rghetia avatar jba avatar davidstanke avatar michaelawyu avatar ymotongpoo avatar ocervell avatar grayside avatar c24t avatar dgageot avatar enocom avatar rakyll avatar mdelio avatar rvrignaud avatar thesandlord avatar

Watchers

James Cloos avatar Amr Tj. Wallas 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.