/emojivoto

Example application to help demonstrate the Linkerd service mesh

Primary LanguageGoApache License 2.0Apache-2.0

Emoji.voto

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

The application is composed of the following 3 services:

Emojivoto Topology

Running

In Minikube

Deploy the application to Minikube using the Linkerd2 service mesh.

  1. Install the linkerd CLI

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

    linkerd install | kubectl apply -f -
  3. View the dashboard!

    linkerd dashboard
  4. Inject, Deploy, and Enjoy

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

    minikube -n emojivoto service web-svc

In docker-compose

It's also possible to run the app with docker-compose (without Linkerd2).

Build and run:

make deploy-to-docker-compose

The web app will be running on port 8080 of your docker host.

Via URL

To deploy standalone to an existing cluster:

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

Generating some traffic

The VoteBot service can generate some traffic for you. It votes on emoji "randomly" as follows:

  • It votes for 🍩 15% of the time.
  • When not voting for 🍩, it picks an emoji at random

If you're running the app using the instructions above, the VoteBot will have been deployed and will start sending traffic to the vote endpoint.

If you'd like to run the bot manually:

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

Releasing a new version

To build and push multi-arch docker images:

  1. Update the tag 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
  3. Build & push the multi-arch docker images to hub.docker.com

    docker login
    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

    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.yml

Prometheus Metrics

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

This can be disabled by unsetting the PROM_PORT environment variable.

Local Development

Emojivoto webapp

Requirements

  1. Set your GOPATH
   export GOPATH=/path/to/go
  1. Add your GOPATH/bin to the PATH
   export PATH=$PATH:$GOPATH/bin
  1. Install protobuf compiler: https://grpc.io/docs/protoc-installation/
  2. Install go packages
go get -u github.com/golang/protobuf/protoc-gen-go
go get google.golang.org/protobuf/reflect/protoreflect@v1.26.0
go get google.golang.org/protobuf/runtime/protoimpl@v1.26.0
  1. Install yarn: https://classic.yarnpkg.com/en/docs/install/

Building process

This app is written with React and bundled with webpack. Use the following to run the emojivoto go services and develop on the frontend.

Set up proto files, build apps

make local

Start the voting service

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

[In a separate terminal window] Start the emoji service

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

[In a separate terminal window] Bundle the frontend assets

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

[In a separate terminal window] Start the web service

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

[Optional] Start the vote bot for automatic traffic generation.

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

View emojivoto

open http://localhost:8080

Testing Linkerd Service Profiles

Service Profiles are a feature of Linkerd that provide per-route functionality such as telemetry, timeouts, and retries. The Emojivoto application is designed to showcase Service Profiles by following the instructions below.

Generate the ServiceProfile definitions from the .proto files

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

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

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

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

Generate the ServiceProfile definition for the Web deployment

The web-svc deployment of emojivoto is a React application that is hosted by a Go server. We can use linkerd profile auto creation to generate the ServiceProfile resource for the web-svc with this command:

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

Now that the service profiles are generated for all the services, you can observe the per-route metrics for each service on the Linkerd Dashboard or with the linkerd routes command

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

License

Copyright 2020 Buoyant, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.