A microservice app that allows users to vote for their favorite emoji and track the votes received on leaderboards. May the best emoji win.

The application consists of the following three services:

  • emojivoto-web:WebThe front andREST API
  • emojivoto-emoji-svc: used to find and listemojigRPC API
  • emojivoto-voting-svc: used for voting and leaderboardsgRPC API

In actual combat

Tencent Cloud K8S deployment Service Mesh — Linkerd2 & Traefik2 deployment emojivoto application

run

In Minikube

Deploy the application to Minikube using the Linkerd2 service grid.

  1. Install linkerd CLI

    curl https://run.linkerd.io/install | sh
    Copy the code
  2. Install Linkerd2

    linkerd install | kubectl apply -f -
    Copy the code
  3. Check the dashboard!

    linkerd dashboard
    Copy the code
  4. Inject, Deploy, and Enjoy

    kubectl kustomize kustomize/deployment | \
        linkerd inject - | \
        kubectl apply -f -
    Copy the code
  5. Use the app!

    minikube -n emojivoto service web-svc
    Copy the code

In the docker – compose

You can also run the application using Docker-compose (without Linkerd2).

Build and run:

make deploy-to-docker-compose
Copy the code

The Web application will run on port 8080 of the Docker host.

Via the URL

Independent deployment to an existing cluster:

kubectl apply -k github.com/BuoyantIO/emojivoto/kustomize/deployment
Copy the code

Generate some traffic

The VoteBot service can bring you some traffic. It voted “randomly” on emojis as follows:

  • 15%🍩
  • When it doesn’t vote for 🍩, it randomly selects an emoji

If you run the application using the instructions(deployment instructions) above, VoteBot will be deployed and will start sending traffic to the voting endpoints.

If you want to run the robot manually:

export WEB_HOST=localhost:8080 # replace with your web location
go run emojivoto-web/cmd/vote-bot/main.go
Copy the code

Release a new version

To build and push a multi-arch Docker image:

  1. Update the label name in common.mk

  2. Create the Buildx builder instance

    docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    docker buildx create --name=multiarch-builder --driver=docker-container --use
    docker buildx inspect multiarch-builder --bootstrap
    Copy the code
  3. Build & push multi-arch Docker images to hub.docker.com

    docker login
    make multi-arch
    Copy the code
  4. Update:

    • docker-compose.yml
    • kustomize/deployment/emoji.yml
    • kustomize/deployment/vote-bot.yml
    • kustomize/deployment/voting.yml
    • kustomize/deployment/web.yml
  5. Distribute to the Linkerd Website repo

    kubectl kustomize kustomize/deployment > .. /website/run.linkerd.io/public/emojivoto.yml kubectl kustomize kustomize/daemonset > .. /website/run.linkerd.io/public/emojivoto-daemonset.yml kubectl kustomize kustomize/statefulset > .. /website/run.linkerd.io/public/emojivoto-statefulset.ymlCopy the code

Prometheus indicators

By default, the voting service exposes Prometheus metrics about the current vote count on port 8801.

This can be disabled by unsetting the PROM_PORT environment variable.

Local development

Emojivoto webapp

The application is written in React and packaged with Webpack. Use the following commands to run emojivoto Go Services and develop them on the front end.

Set up the proto file to build the application

make build
Copy the code

Start polling Service

GRPC_PORT=8081 go run emojivoto-voting-svc/cmd/server.go
Copy the code

Start the Emoji service [in a separate terminal window]

GRPC_PORT=8082 go run emojivoto-emoji-svc/cmd/server.go
Copy the code

Bundle front-end resources [in a separate terminal window]

cd emojivoto-web/webapp
yarn install
yarn webpack # one time asset-bundling OR
yarn webpack-dev-server --port 8083 # bundle/serve reloading assets
Copy the code

Start the Web service [in a separate terminal window]

export WEB_PORT=8080
export VOTINGSVC_HOST=localhost:8081
export EMOJISVC_HOST=localhost:8082

# if you ran yarn webpack
export INDEX_BUNDLE=emojivoto-web/webapp/dist/index_bundle.js

# if you ran yarn webpack-dev-server
export WEBPACK_DEV_SERVER=http://localhost:8083

# start the webserver
go run emojivoto-web/cmd/server.go
Copy the code

Optional. Start the voting robot to generate traffic automatically.

export WEB_HOST=localhost:8080
go run emojivoto-web/cmd/vote-bot/main.go
Copy the code

Check the emojivoto

open http://localhost:8080
Copy the code

Test the Linkerd service configuration file

Service Profiles is a feature of Linkerd that provides per-route functionality, such as Telemetry, timeouts, and retries. The Emojivoto application aims to present the service configuration file with the following instructions.

from.protoThe ServiceProfile file generates the ServiceProfile definition

Emoji and voting services are gRPC applications with Protocol Buffers (Protobuf) definition files. These.proto files can be used as input to the Linkerd profile command to create the ServiceProfile Definition YAMl file. The Linkerd Service Profile document Outlines the steps required to create a YAML file. Here are the commands you can use from the root of the repository:

linkerd profile --proto proto/Emoji.proto emoji-svc -n emojivoto
Copy the code
linkerd profile --proto proto/Voting.proto voting-svc -n emojivoto
Copy the code

Each of these commands outputs YAML, which you can write to a file or pipe, directly to Kubectl apply. Such as:

  • Write to file:
linkerd profile --proto proto/Emoji.proto emoji-svc -n emojivoto > emoji
-sp.yaml
Copy the code
  • Apply directly to:
linkerd profile --proto proto/Voting.proto voting-svc -n emojivoto | \
kubectl apply -f -
Copy the code

Generate the ServiceProfile definition for the Web deployment

Emojivoto’s web-SVC deployment is a React application hosted by Go Server. We can use Linkerd Profile Auto Creation to generate a ServiceProfile resource for Web-SVC using the following command:

linkerd profile -n emojivoto web-svc --tap deploy/web --tap-duration 10s | \
   kubectl apply -f -
Copy the code

Now that service profiles are generated for all services, you can view each routing metric for each service on the Linkerd Dashboard or using the Linkerd routes command

linkerd -n emojivoto routes deploy/web-svc --to svc/emoji-svc
Copy the code