bookinfo

module
v0.0.0-...-6907fd9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2024 License: Apache-2.0

README

Bookinfo

Rewrite Bookinfo project using hertz, kitex

Architecture

img.png

Lane

lane.png

QuickStart

Prerequisites
Kubernetes cluster

If you don't have an existing K8S cluster, you can use minikube to quickly launch one

  1. install minikube
  2. minikube start
Istio

Refer to the doc of Istio to deploy a set of istio to the K8S cluster

Helm

Refer to the doc of Helm to install the helm command-line tool

OpenTelemetry
install opentelemetry operator
helm install --set admissionWebhooks.certManager.enabled=false \
  opentelemetry-operator open-telemetry/opentelemetry-operator
deploy opentelemetry collector

We are here just for demo, so we will only export spans and metrics to the log. For the production environment, set up your opentelemetry-collector as needed

kubectl apply -f - <<EOF
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
  name: bookinfo-demo
spec:
  mode: statefulset
  replicas: 3
  config: |
    receivers:
      otlp:
        protocols:
          grpc:
    processors:

    exporters:
      logging:

    service:
      pipelines:
        traces:
          receivers: [otlp]
          processors: []
          exporters: [logging]
        metrics:
          receivers: [otlp]
          processors: []
          exporters: [logging]          
EOF
Deploy Bookinfo Application
helm install bookinfo ./manifest/bookinfo/workloads

After successful deploy, you can see that the pods are running:

img.png

Expose Bookinfo by Istio Ingress Gateway
kubectl apply -f bookinfo/manifest/bookinfo/traffic/bookinfo-gateway.yaml

Use the minikube tunnel feature to assign LB IPs to istio ingress:

minikube tunnel

Then you can request the address on the command line

curl http://localhost/api/v1/products/1

You see the following output, indicating that the deployment was successful!

{"ID":"1","Title":"《Also sprach Zarathustra》","Author":"Friedrich Nietzsche","Description":"Thus Spoke Zarathustra: A Book for All and None, also translated as Thus Spake Zarathustra, is a work of philosophical fiction written by German philosopher Friedrich Nietzsche between 1883 and 1885.","Rating":0}

Traffic routing example

Define routing rules
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews
spec:
  hosts:
    - reviews
  http:
    - match:
        - headers:
            baggage:
              exact: "env=dev"
      route:
        - destination:
            host: reviews
            subset: v2
          weight: 100
    - route:
        - destination:
            host: reviews
            subset: v1
          weight: 80
        - destination:
            host: reviews
            subset: v3
          weight: 20

---

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings
spec:
  hosts:
    - ratings
  http:
    - match:
        - headers:
            baggage:
              exact: "env=dev"
      route:
        - destination:
            host: ratings
            subset: v2
          weight: 100
    - route:
        - destination:
            host: ratings
            subset: v1
          weight: 100
Request base lane service, rating 0 or 1 randomly

bookinfo_1.png bookinfo_2.png

Set the request coloring flag through the browser mod-header plugin

bookinfo_3.png

Click the refresh button again, you can find that the request hits the branch lane, and the rating becomes 5

bookinfo_4.png

View Tracing

tracing-topo tracing

View Topology

operation-topo

Directories

Path Synopsis
cmd
internal
kitex_gen
cwg/bookinfo/details/detailsservice
Code generated by Kitex v0.4.2.
Code generated by Kitex v0.4.2.
cwg/bookinfo/product/productpageservice
Code generated by Kitex v0.4.2.
Code generated by Kitex v0.4.2.
cwg/bookinfo/ratings/ratingservice
Code generated by Kitex v0.4.2.
Code generated by Kitex v0.4.2.
cwg/bookinfo/reviews/reviewsservice
Code generated by Kitex v0.4.2.
Code generated by Kitex v0.4.2.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL