This is a sample distributed (microservices) Ruby app using Sinatra, ActiveRecord, and ActiveResource. The app is designed to demonstrate the various value propositions of Linkerd 2.0 including debugging, observability, and monitoring. Some of the services in the app periodically fail. This is by design in order to demo debugging and monitoring in Linkerd 2.0.
The application is composed of the following four services:
- webapp.rb
- authors.rb
- books.rb
- traffic/main.go (demo traffic generator, written in Go)
You can deploy the application to Kubernetes using the Linkerd 2.0 service mesh.
-
Install the
linkerd
CLIcurl https://run.linkerd.io/install | sh
-
Install the Linkerd control plane
linkerd install | kubectl apply -f -
-
Inject and deploy the application
curl https://run.linkerd.io/booksapp.yml | linkerd inject - | kubectl apply -f -
-
Use the app!
kubectl port-forward svc/webapp 7000 open "http://localhost:7000"
-
View the Linkerd dashboard!
linkerd dashboard
The default booksapp configuration uses SQLite. It's also possible to run the
app with a MySQL backend, using the configs in the k8s/
directory. The MySQL
configuration uses a separate pod for the storage backend, which allows running
multiple replicas of each of the app deployments.
-
Start by installing the MySQL backend
kubectl apply -f k8s/mysql-backend.yml
-
Verify that the mysql-init job successfully completes
kubectl get po NAME READY STATUS RESTARTS AGE mysql-9bd5bcfdf-7jb2s 1/1 Running 0 3m mysql-init-29nxv 0/1 Completed 0 3m
-
Install Linkerd as described above; install the app configured to use MySQL
linkerd install | kubectl apply -f - linkerd inject k8s/mysql-app.yml | kubectl apply -f -
-
Use the app!
kubectl port-forward svc/webapp 7000 open "http://localhost:7000"
This repo includes a Chaos Monkey script, that randomly kills a pod every 10 seconds. It is intended to be run with the Kubernetes / MySQL configuration. To deploy, run:
```bash
kubectl apply -f k8s/mysql-chaos.yml
```
In order to record per-route metrics, you can create service profiles for the webapp, books, and authors services based on their Swagger specs:
```bash
linkerd profile --open-api swagger/webapp.swagger webapp | kubectl apply -f -
linkerd profile --open-api swagger/books.swagger books | kubectl apply -f -
linkerd profile --open-api swagger/authors.swagger authors | kubectl apply -f -
```
You can then view route data for each service:
```bash
linkerd routes webapp
```
```bash
linkerd routes books
```
```bash
linkerd routes authors
```
You can use a modified version of booksapp to demo a trafficsplit.
-
Install
booksapp-trafficsplit.yml
which includes the MySQL backend, a modified version of booksapp.yml that does not introduce a FAILURE_RATE, a secondauthors
service calledauthors-clone
, and two trafficsplits. Linkerd has already been injected into booksapp andauthors-clone
.kubectl apply -f booksapp-trafficsplit.yml
-
Verify that two trafficsplits now exist in the
default
namespace.kubectl get ts
-
Give the app 1-2 minutes to begin sending traffic.
-
Run
watch linkerd stat ts
to verify that the trafficsplits are working. You should see the below results -- one trafficsplit dividing traffic 50/50 betweenauthors
andauthors-clone
, one dividing traffic 100/0 betweenwebapp
and the non-existentwebapp-clone
(You can create a split between two services before the second service has been created).NAME APEX LEAF WEIGHT SUCCESS RPS LATENCY_P50 LATENCY_P95 LATENCY_P99 authors-split authors authors 500m 100.00% 3.1rps 8ms 29ms 37ms authors-split authors authors-clone 500m 100.00% 3.5rps 8ms 23ms 37ms webapp-split webapp webapp 1 100.00% 7.3rps 26ms 74ms 95ms webapp-split webapp webapp-clone 0 - - - - -
-
When you are done, delete the app.
kubectl delete -f booksapp-trafficsplit.yml
You can also run the application locally for development.
-
Create, migrate, and seed the database
bundle install bundle exec rake db:create bundle exec rake db:migrate bundle exec rake db:seed
-
Start the web app
bundle exec rake dev:webapp
-
Start the authors app
bundle exec rake dev:authors
-
Start the books app
bundle exec rake dev:books
-
Open the website
open "http://localhost:7000"
All of the Docker images used for this application are already published publicly and don't need to be built by hand. If you'd like to build the images locally follow the instructions below.
-
Build the
buoyantio/booksapp
imagedocker build -t buoyantio/booksapp:latest .
-
Build the
buoyantio/booksapp-traffic
imagedocker build -t buoyantio/booksapp-traffic:latest traffic