sapient007 / example-voting-app

Example Docker Compose app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example Voting App

A simple distributed application running across multiple Docker containers.

Getting started

Download Docker Desktop for Mac or Windows. Docker Compose will be automatically installed. On Linux, make sure you have the latest version of Compose.

Linux Containers

The Linux stack uses Python, Node.js, .NET Core (or optionally Java), with Redis for messaging and Postgres for storage.

If you're using Docker Desktop on Windows, you can run the Linux version by switching to Linux containers, or run the Windows containers version.

Run in this directory:

docker-compose up

The app will be running at http://localhost:5000, and the results will be at http://localhost:5001.

Alternately, if you want to run it on a Docker Swarm, first make sure you have a swarm. If you don't, run:

docker swarm init

Once you have your swarm, in this directory run:

docker stack deploy --compose-file docker-stack.yml vote

Windows Containers

An alternative version of the app uses Windows containers based on Nano Server. This stack runs on .NET Core, using NATS for messaging and TiDB for storage.

You can build from source using:

docker-compose -f docker-compose-windows.yml build

Then run the app using:

docker-compose -f docker-compose-windows.yml up -d

Or in a Windows swarm, run docker stack deploy -c docker-stack-windows.yml vote

The app will be running at http://localhost:5000, and the results will be at http://localhost:5001.

Run the app in Kubernetes (Minikube)

The folder k8s-specifications contains the yaml specifications of the Voting App's services.

First create the vote namespace

$ kubectl create namespace vote

Run the following command to create the deployments and services objects:

$ kubectl create -f k8s-specifications/
deployment "db" created
service "db" created
deployment "redis" created
service "redis" created
deployment "result" created
service "result" created
deployment "vote" created
service "vote" created
deployment "worker" created

The vote interface is then available on port 31000 on each host of the cluster, the result one is available on port 31001.

Run in GKE (Google Kubernetes Engine)

đź’ˇ Recommended if you're using Google Cloud Platform and want to try it on a realistic cluster.

  1. Install tools specified in the previous section (Docker, kubectl, skaffold)

  2. Create a Google Kubernetes Engine cluster and make sure kubectl is pointing to the cluster.

    gcloud services enable container.googleapis.com
    gcloud container clusters create demo --enable-autoupgrade \
        --enable-autoscaling --min-nodes=3 --max-nodes=10 --num-nodes=5 --zone=us-central1-a
    kubectl get nodes
    
  3. Enable Google Container Registry (GCR) on your GCP project and configure the docker CLI to authenticate to GCR:

    gcloud services enable containerregistry.googleapis.com
    gcloud auth configure-docker -q
  4. Create Vote namespace in Kubernetes

    kubectl create namespace vote
  5. In the root of this repository, run skaffold run --default-repo=gcr.io/[PROJECT_ID], where [PROJECT_ID] is your GCP project ID.

    This command:

    • builds the container images
    • pushes them to GCR
    • applies the ./k8s-specifications deploying the application to Kubernetes.

    Optional: Build docker images in Goole Container Builder If you don't have docker running locally and want to still build the images, you can use the -p gcb option to build it on Google Cloud

    skaffold run --default-repo=gcr.io/gcr.io/[PROJECT_ID] -p gcb

    Troubleshooting: If you get "No space left on device" error on Google Cloud Shell, you can build the images on Google Cloud Build: Enable the Cloud Build API, then run skaffold run -p gcb --default-repo=gcr.io/[PROJECT_ID] instead.

    If you have errors with the application, you can use the -tail option in skaffold to tail all the logs

  6. Find the IP address of your application, then visit the application on your browser to confirm installation.

    kubectl get services -n vote
    

    Troubleshooting: A Kubernetes bug (will be fixed in 1.12) combined with a Skaffold bug causes load balancer to not to work even after getting an IP address. If you are seeing this, run kubectl get service frontend-external -o=yaml | kubectl apply -f- to trigger load balancer reconfiguration.

Architecture

Architecture diagram

Notes

The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.

This isn't an example of a properly architected perfectly designed distributed app... it's just a simple example of the various types of pieces and languages you might see (queues, persistent data, etc), and how to deal with them in Docker at a basic level.

About

Example Docker Compose app

License:Apache License 2.0


Languages

Language:C# 49.8%Language:CSS 14.1%Language:HTML 12.3%Language:JavaScript 9.6%Language:Java 5.3%Language:Dockerfile 4.3%Language:Python 2.8%Language:Objective-J 0.9%Language:Shell 0.8%