Skip to content

cage1016/ms-demo

Repository files navigation

gokit microservice demo

Continuous Integration - Master/Release

Service Description
add Expose Sum method
tictac Expose Tic/Tac method

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.
  • go-kit/kit: Go kit is a programming toolkit for building microservices (or elegant monoliths) in Go. We solve common problems in distributed systems and application architecture so you can focus on delivering business value.
  • kubernetes/ingress-nginx: ingress-nginx is an Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer
  • Jaeger: open source, end-to-end distributed tracing. Monitor and troubleshoot transactions in complex distributed systems
  • Telepresence: Local development against a remote Kubernetes or OpenShift cluster

Install

this demo support Kubernetes service or nginx ingress and Istio three ways to access

Kubernetes Service

  1. Run ms-demo kubernetes cluster

    skaffold run --default-repo=<your-repo>

    or

    kubectl apply -f https://raw.githubusercontent.com/cage1016/ms-demo/master/release/kubernetes-manifests-all.yaml

LoadBalancer

  1. Apply LoadBalancer yaml

    kubectl apply -f https://raw.githubusercontent.com/cage1016/ms-demo/master/release/lb-all.yaml
  2. We expose add, tictac service with TWO external service (LoadBalancer)

  3. Set the ADD_HTTP_EXTERNAL_URL/ADD_GRPC_EXTERNAL_URL

    ADD_HTTP_EXTERNA_PORT=$(kubectl get service add-external -o jsonpath='{.spec.ports[?(@.name=="http")].port}')
    ADD_GRPC_EXTERNA_PORT=$(kubectl get service add-external -o jsonpath='{.spec.ports[?(@.name=="grpc")].port}')
    ADD_EXTERNA_HOST=$(kubectl get service add-external -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
    # ADD_EXTERNA_HOST=$(kubectl get service add-external -o jsonpath='{.status.loadBalancer.ingress[0].ip}') # unmark if necessary
    ADD_HTTP_EXTERNA_URL=$ADD_EXTERNA_HOST:$ADD_HTTP_EXTERNA_PORT
    ADD_GRPC_EXTERNA_URL=$ADD_EXTERNA_HOST:$ADD_GRPC_EXTERNA_PORT
    echo $ADD_HTTP_EXTERNA_URL
    echo $ADD_GRPC_EXTERNA_URL
  4. Set the TICTAC_HTTP_EXTERNAL_URL/TICTAC_GRPC_EXTERNAL_URL

    TICTAC_HTTP_EXTERNAL_PORT=$(kubectl get service tictac-external -o jsonpath='{.spec.ports[?(@.name=="http")].port}')
    TICTAC_GRPC_EXTERNAL_PORT=$(kubectl get service tictac-external -o jsonpath='{.spec.ports[?(@.name=="grpc")].port}')
    TICTAC_EXTERNAL_HOST=$(kubectl get service tictac-external -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
    # TICTAC_EXTERNAL_HOST=$(kubectl get service tictac-external -o jsonpath='{.status.loadBalancer.ingress[0].ip}') # unmark if necessary
    TICTAC_HTTP_EXTERNAL_URL=$TICTAC_EXTERNAL_HOST:$TICTAC_HTTP_EXTERNAL_PORT
    TICTAC_GRPC_EXTERNAL_URL=$TICTAC_EXTERNAL_HOST:$TICTAC_GRPC_EXTERNAL_PORT
    echo $TICTAC_HTTP_EXTERNAL_URL
    echo $TICTAC_GRPC_EXTERNAL_URL
  5. Access by command

    sum restful method

    curl -X POST $ADD_HTTP_EXTERNA_URL/sum -d '{"a": 1, "b":1}'

    sum grpc mwthod

    grpcurl -d '{"a": 1, "b":1}' -plaintext -proto ./pb/add/add.proto $ADD_GRPC_EXTERNA_URL pb.Add.Sum

    tic restful method

    curl -X POST $TICTAC_HTTP_EXTERNAL_URL/tic

    tic grpc method

    grpcurl -plaintext -proto ./pb/tictac/tictac.proto $TICTAC_GRPC_EXTERNAL_URL pb.Tictac.Tic

    tac restful method

    curl $TICTAC_HTTP_EXTERNAL_URL/tac

    tac grpc method

    grpcurl -plaintext -proto ./pb/tictac/tictac.proto $TICTAC_GRPC_EXTERNAL_URL pb.Tictac.Tac
  6. Remove LoadBalancer

    kubectl delete -f https://raw.githubusercontent.com/cage1016/ms-demo/master/deployments/lb-all.yaml

Nginx ingress

  1. setup nginx ingress

    kubectl create ns ingress-nginx
    helm install ingress-nginx -n ingress-nginx ingress-nginx/ingress-nginx
  2. Prepare tls for nginx ingress GRPC for two grpc test domain tictac.localhost & add.localhost

    • create RSA private key and certificate
      sh tls/generate.sh
    • set ingress tls
      sh tls/tls.sh
  3. Setup nginx ingress

    kubectl apply -f https://raw.githubusercontent.com/cage1016/ms-demo/master/release/nginx-ingress-all.yaml
    
  4. Set up ADD_NGINX_INGRESS_GRPC_URL & TICTAC_NGINX_INGRESS_GRPC_URL

    ADD_NGINX_INGRESS_GRPC_URL=$(kubectl get ingress add-grpc-ingress -o jsonpath='{.spec.tls[0].hosts[0]}'):443
    TICTAC_NGINX_INGRESS_GRPC_URL=$(kubectl get ingress tictac-grpc-ingress -o jsonpath='{.spec.tls[0].hosts[0]}'):443
    echo ${ADD_NGINX_INGRESS_GRPC_URL}
    echo ${TICTAC_NGINX_INGRESS_GRPC_URL}
  5. Access by command

    sum restful method

    curl --insecure -X POST -d '{"a": 1, "b":1}' https://localhost/api/v1/add/sum

    sum grpc method

    grpcurl --insecure -d '{"a": 1, "b":1 }' ${ADD_NGINX_INGRESS_GRPC_URL}  pb.Add.Sum

    tic restful method

    curl --insecure -X POST https://localhost/api/v1/tictac/tic

    tic grpc method

    grpcurl --insecure ${TICTAC_NGINX_INGRESS_GRPC_URL} pb.Tictac.Tic

    tac restful method

    curl --insecure https://localhost/api/v1/tictac/tac

    tac grpc method

    grpcurl --insecure ${TICTAC_NGINX_INGRESS_GRPC_URL} pb.Tictac.Tac
  6. Clean up Nnginx

    kubectl delete -f https://raw.githubusercontent.com/cage1016/ms-demo/master/deployments/nginx-ingress-all.yaml
    
    kubectl delete secret add-tls-secret
    kubectl delete secret tictac-tls-secret

Istio

  1. You should have a Kubernetes cluster with Istio already.

  2. Apply Istio manifests

    kubectl apply -f https://raw.githubusercontent.com/cage1016/ms-demo/master/release/istio-manifests-all.yaml
  3. Set the GATEWAY_HTTP_URL/GATEWAY_GRPC_URL environment variable in your shell to the public IP/port of the Istio Ingress gateway.

    export INGRESS_HTTP_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
    export INGRESS_GRPC_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].port}')
    export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
    export GATEWAY_HTTP_URL=$INGRESS_HOST:$INGRESS_HTTP_PORT
    export GATEWAY_GRPC_URL=$INGRESS_HOST:$INGRESS_GRPC_PORT
    echo $GATEWAY_HTTP_URL
    echo $GATEWAY_GRPC_URL
  4. Access by command sum restful method

    curl -X POST $GATEWAY_HTTP_URL/api/v1/add/sum -d '{"a": 1, "b":1}'

    sum grpc method

    grpcurl -d '{"a": 1, "b":1}' -plaintext -proto ./pb/add/add.proto $GATEWAY_GRPC_URL pb.Add.Sum

    tic restful method

    curl -X POST $GATEWAY_HTTP_URL/api/v1/tictac/tic

    tic grpc method

    grpcurl -plaintext -proto ./pb/tictac/tictac.proto $GATEWAY_GRPC_URL pb.Tictac.Tic

    tac restful method

    curl $GATEWAY_HTTP_URL/api/v1/tictac/tac

    tac grpc method

    grpcurl -plaintext -proto ./pb/tictac/tictac.proto $GATEWAY_GRPC_URL pb.Tictac.Tac
  5. CleanUp Istio

    kubectl delete -f https://raw.githubusercontent.com/cage1016/ms-demo/master/release/istio-manifests-all.yaml

Jaeger (Optional)

  1. Install Jaeger to Kubernetes cluster. Please visit Jaeger: open source, end-to-end distributed tracing to check more detail information

    kubectl create namespace observability
    kubectl create -n observability -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/crds/jaegertracing.io_jaegers_crd.yaml
    kubectl create -n observability -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/service_account.yaml
    kubectl create -n observability -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/role.yaml
    kubectl create -n observability -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/role_binding.yaml
    kubectl create -n observability -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/deploy/operator.yaml
  2. Setup Jaeger sample config

    kubectl apply -f https://raw.githubusercontent.com/cage1016/ms-demo/master/release/with-sampling.yaml
    
  3. patch add & tictac env to connect Jaeger agent

    kubectl set env deployment/add QS_JAEGER_URL=with-sampling-agent.observability.svc.cluster.local:6831
    kubectl set env deployment/tictac QS_JAEGER_URL=with-sampling-agent.observability.svc.cluster.local:6831
  4. Do some restful or grpc requests as above steps that Jeager could collect some data

  5. port-forward Jaeger UI and access

    kubectl -n observability port-forward svc/with-sampling-query 16686
    
  6. visit https://localhost:16686

  7. CleanUP jaeger

    kubectl delete ns observability

CleanUP claster

skaffold delete

or

kubectl delete -f https://raw.githubusercontent.com/cage1016/ms-demo/master/release/kubernetes-manifests-all.yaml