Emoji.voto, a sample application for Linkerd service mesh

Emoji.voto, a sample application for Linkerd service mesh

[[412321]]

A microservice application that allows users to vote for their favorite emoji and keeps track of the votes received on a leaderboard. May the best emoji win.

The application consists of the following 3 services:

emojivoto-web: Web frontend and REST API

  • https://github.com/BuoyantIO/emojivoto/tree/main/emojivoto-web

emojivoto-emoji-svc: gRPC API for finding and listing emojis

  • https://github.com/BuoyantIO/emojivoto/tree/main/emojivoto-emoji-svc

emojivoto-voting-svc: gRPC API for voting and leaderboards

  • https://github.com/BuoyantIO/emojivoto/blob/main/emojivoto-voting-svc

Actual Combat

Tencent Cloud K8S Cluster Practice Service Mesh—Linkerd2 & Traefik2 Deployment of emojivoto Application

run

In Minikube

Deploy the application to Minikube using the Linkerd2 service mesh.

1. Install linkerd CLI

  1. curl https://run.linkerd.io/install | sh

2. Install Linkerd2

  1. linkerd install | kubectl apply -f -

3. Check out the dashboard!

  1. linkerd dashboard

4.Inject, Deploy, and Enjoy

  1. kubectl kustomize kustomize/deployment | \
  2. linkerd inject - | \
  3. kubectl apply -f -

5. Use apps!

  1. minikube -n emojivoto service web-svc

In docker-compose

It is also possible to run the application using docker-compose (without Linkerd2).

Build and run:

  1. make deploy- to -docker-compose

The web application will run on port 8080 of the docker host.

Via URL

Standalone deployment to an existing cluster:

  1. kubectl apply -k github.com/BuoyantIO/emojivoto/kustomize/deployment

Generate some traffic

The VoteBot service can bring you some traffic. It votes "randomly" on emojis like this:

  • 15% of the votes went to 🍩
  • When you don't vote for 🍩, it will randomly select an emoji

If you ran the application using the above instructions, VoteBot will be deployed and will start sending traffic to the voting endpoint.

If you want to run the bot manually:

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

Release a new version

To build and push a multi-arch docker image:

1. Update the tag name in common.mk

2. Create a Buildx builder instance

  1. docker run --rm --privileged multiarch/qemu-user-static --reset -p yes  
  2. docker buildx create   --name=multiarch-builder --driver=docker-container --use  
  3. docker buildx inspect multiarch-builder --bootstrap  

3. Build & push multi-arch docker image to hub.docker.com

  1. docker login
  2. make multi-arch

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

  1. kubectl kustomize kustomize/deployment > ../website/run.linkerd.io/ public /emojivoto.yml
  2. kubectl kustomize kustomize/daemonset > ../website/run.linkerd.io/ public /emojivoto-daemonset.yml
  3. kubectl kustomize kustomize/statefulset > ../website/run.linkerd.io/ public /emojivoto-statefulset.yml

Prometheus metrics

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

This application is written in React and bundled using webpack. Use the following command to run emojivoto go services and develop on the front-end.

Set up the proto file and build the application

  1. make build

Start voting service

  1. GRPC_PORT=8081 go run emojivoto-voting-svc/cmd/server.go

[In a separate terminal window] Start the emoji server

  1. GRPC_PORT=8082 go run emojivoto-emoji-svc/cmd/server.go

[In a separate terminal window] Bundle frontend resources

  1. cd emojivoto-web/webapp
  2. yarn install
  3. yarn webpack # one time asset-bundling OR  
  4. yarn webpack-dev-server --port 8083 # bundle/serve reloading assets  

[In a separate terminal window] Start the web server

  1. export WEB_PORT=8080
  2. export VOTINGSVC_HOST=localhost:8081
  3. export EMOJISVC_HOST=localhost:8082
  4.  
  5. # if you ran yarn webpack
  6. export INDEX_BUNDLE=emojivoto-web/webapp/dist/index_bundle.js
  7.  
  8. # if you ran yarn webpack-dev-server
  9. export WEBPACK_DEV_SERVER=http://localhost:8083
  10.  
  11. # start the webserver
  12. go run emojivoto-web/cmd/server.go

[Optional] Start a voting bot to automatically generate traffic.

  1. export WEB_HOST=localhost:8080
  2. go run emojivoto-web/cmd/vote-bot/main.go

View emojivoto

  1. open http://localhost:8080

Testing the Linkerd Service Configuration File

Service Profiles are a feature of Linkerd that provide per-route functionality such as telemetry, timeouts, and retries. The Emojivoto application aims to showcase service profiles with the following instructions.

Service Profiles: https://linkerd.io/2/features/service-profiles

Generate ServiceProfile definition from .proto file

The emoji and voting services are gRPC applications that have Protocol Buffers (protobuf) definition files. These .proto files can be used as input to the linkerd profile command to create a ServiceProfile definition yaml file. The Linkerd Service Profile documentation outlines the steps required to create the yaml file, and these are the commands you can use from the root of that repository:

  1. linkerd profile --proto proto/Emoji.proto emoji-svc -n emojivoto  
  2. linkerd profile --proto proto/Voting.proto voting-svc -n emojivoto  

Protocol Buffers (protobuf): https://developers.google.com/protocol-buffers

gRPC: https://grpc.io

Linkerd Service Profile documentation: https://linkerd.io/2/tasks/setting-up-service-profiles/#protobuf

Each of these commands will output YAML, which you can write to a file or pipe directly to kubectl apply. For example:

  • Writing to a file:
  1. linkerd profile --proto proto/Emoji.proto emoji-svc -n emojivoto > emoji  
  2. -sp.yaml
  • Apply directly:
  1. linkerd profile --proto proto/Voting.proto voting-svc -n emojivoto | \  
  2. kubectl apply -f -

Generate ServiceProfile definition for Web deployment

emojivoto's web-svc deployment is a React application hosted by a Go server. We can use linkerd profile auto creation to generate a ServiceProfile resource for web-svc using the following command:

  1. linkerd profile -n emojivoto web-svc --tap deploy/web --tap-duration 10s | \  
  2. kubectl apply -f -

Now that service configuration files are generated for all services, you can observe per-service route metrics on the Linkerd Dashboard or using the linkerd routes command.

  1. linkerd -n emojivoto routes deploy/web-svc --to svc/emoji-svc  

linkerd profile auto creation

  • https://linkerd.io/2/tasks/setting-up-service-profiles/#auto-creation

Linkerd Dashboard

  • https://linkerd.io/2/features/dashboard

<<:  5G construction has not yet been completed, and countries have invested heavily in 6G research. Will my country still be ahead in 6G?

>>:  Unexpectedly, China Unicom is the biggest loser in number portability

Recommend

Cisco: Continuous innovation to create an inclusive future

On June 14, Cisco's annual networking and sec...

2G/3G will be phased out soon, and NB-IoT will start to take over

With the upcoming decommissioning of 2G/3G networ...

The Why and How of a Two-Tier Network Monitoring Topology

As data centers upgrade to 100Gbps at an accelera...

I2C case using SHT3x-DIS temperature and humidity sensor

To learn more about open source, please visit: ​​...

What are virtual networks and why they are here to stay

The computer networks we typically imagine involv...

Blockchain technology will change the world in these four ways

As the underlying technology of Bitcoin, blockcha...

Eight major IT disasters in 2024

Like most years, 2024 has seen a series of IT dis...

Can Chrome DevTools' Network be used like this?

If you were to pick the most used feature in Chro...

Is there still a market for pure 4G mobile phones?

According to a report by China Business News, Hua...