Coder Social home page Coder Social logo

elbetasal / kuma-counter-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kumahq/kuma-counter-demo

0.0 1.0 0.0 116 KB

This is the counter demo for Kuma, that demonstrates the capabilities of the service mesh.

License: Apache License 2.0

Dockerfile 1.45% HTML 80.01% JavaScript 18.54%

kuma-counter-demo's Introduction

Kuma Counter Demo

License Slack Twitter

Welcome to a sample application that demonstrates the Kuma service mesh in action. Kuma is designed to work across Kubernetes and VMs environments, with support for multi-zone deployments across many different clusters, data centers, and clouds.

To learn more about Kuma, see the Kuma repository.

Kuma is a CNCF Sandbox project.

Introduction

The application consists of two services:

  • A demo-app service that presents a web application that allows us to increment a numeric counter
  • A redis service that stores the counter

kuma-counter-demo

The demo-app service presents a browser interface that listens on port 5000. When it starts, it expects to find a zone key in Redis that specifies the name of the datacenter (or cluster) that the current redis instance belongs to. This name is then displayed in the demo-app GUI.

The zone key is purely static and arbitrary, but by having different zone values across different redis instances, we know at any given time from which Redis instance we are fetching/incrementing our counter when we route across a distributed environment across many zones, clusters and clouds.

Run the application

  1. Run redis

    • (Kubernetes setup) on the default port 6379 and set a default zone name:
    $ redis-server
    $ redis-cli set zone local
    • (Universal setup) on port 26379 and set a default zone name:
    $ redis-server --port 26379
    $ redis-cli -p 26379 set zone local
  2. Install and start demo-app on the default port 5000:

    $ npm install --prefix=app/
    $ npm start --prefix=app/
  3. (Only for Kubernetess) Navigate to 127.0.0.1:5000 and increment the counter!

Run in Universal

  1. First we need to generate two tokens:
  • One for redis

  • Second for node-app To do so we need to run:

    $ kumactl generate dataplane-token --name=redis > kuma-token-redis
    $ kumactl generate dataplane-token --name=app > kuma-token-app
  1. Then we need to generate two DPPs:
  • For redis:
kuma-dp run \
   --cp-address=https://localhost:5678/ \
   --dns-enabled=false \
   --dataplane-token-file=kuma-token-redis \
   --dataplane="type: Dataplane
mesh: default
name: redis
networking:
  address: 127.0.0.1 # Or any public address (needs to be reachable by every other dp in the zone) 
  inbound:
    - port: 16379
      servicePort: 26379
      tags:
        kuma.io/service: redis
        kuma.io/protocol: tcp"
  • And for app:
kuma-dp run \
  --cp-address=https://localhost:5678/ \
  --dns-enabled=false \
  --dataplane-token-file=kuma-token-app \
  --dataplane="type: Dataplane
mesh: default
name: app
networking:
  address: 127.0.0.1 # Or any public address (needs to be reachable by every other dp in the zone) 
  outbound:
    - port: 6379
      tags:
        kuma.io/service: redis
  inbound:
    - port: 15000
      servicePort: 5000
      tags:
        kuma.io/service: app
        kuma.io/protocol: http
  admin:
    port: 9902"
  1. Navigate to 127.0.0.1:5000 and increment the counter!

Run in Kubernetes

Two different YAML files are provided for Kubernetes:

  • one that installs the basic resources
  • one that installs a version of the frontend service with different colors (useful to demonstrate routing across multiple versions, for example)
  1. Install the basic demo resources in a kuma-demo namespace:

    $ kubectl apply -f demo.yaml
  2. Port-forward the service to the namespace on port 5000:

    $ kubectl port-forward svc/demo-app -n kuma-demo 5000:5000
  3. Navigate to 127.0.0.1:5000 and increment the counter!

Run v2 (Kubernetes)

To install the v2 version of the demo application, we can apply the following YAML file instead, which will change the colors and version number of our frontend application:

$ kubectl apply -f demo-v2.yaml

By inspecting the file we can see that the demo-v2.yaml file sets the following environment variables - which are also available on VMs - to different values so that we have immediate visual feedback that a new version is runnning.

Environment Variables

We can configure the following environment variables when running demo-app:

  • REDIS_HOST: Determines the hostname to use when connecting to Redis. Default is 127.0.0.1.
  • REDIS_PORT: Determines the port to use when connecting to Redis. Default is 6379.
  • APP_VERSION: Lets you change the version number displayed in the main page of demo-app. Default is 1.0.
  • APP_COLOR: Lets you change background color of the demo-app main page. Default is #efefef.

The APP_VERSION and APP_COLOR environment variables are handy when we want to create different versions of demo-app and get immediate visual feedback when routing across them.

kuma-counter-demo's People

Contributors

subnetmarco avatar lahabana avatar github-actions[bot] avatar bradamant3 avatar jakubdyszkiewicz avatar tomaszwylezek avatar d19dotca avatar michaelbeaumont avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.