Skip to content

Simple testbed microservice application for kubernetes

Notifications You must be signed in to change notification settings

FearlessSolutions/k8straining

Repository files navigation

Kubernetes Training

Testbed

BackgroundUsageDockerKubernetesDeploy to GKENetwork DiagramContributors

Background

This testbed was created as an "Idiot's Guide" to learning Kubernetes. Kubernetes training can be unnecessarily complicated when it involves building an application, trying to force it into a microservices architecture, and then trying to put features on top of that architecture.

Instead, this testbed allows for the creation of multiple services that talk to each other and only perform simple functions. This testbed can therefore be used to test Kubernetes assumptions and systems without too much added complexity.

This testbed can also be used for new systems (e.g., Helm, service mesh, virtualkubelt). If you want to test any of these additional complexities, please create a fork of this repo.

This testbed includes the following four microservices:

  1. Add: Takes 2 integers, adds them together, and returns the result.
  2. Multiply: Takes 2 integers, checks which is smaller, calls Add enough times with the larger integer to get the correct result, decides positive or negative, and returns the result.
  3. Nest1: Gets Nest2, then returns "Nest2 responded: [Nest2's response]."
  4. Nest2: Returns the contents of an environment variable.

Usage

Docker

docker-compose up --build

curl -X POST -G 'http://localhost:8080/add' -d a=3 -d b=36
curl -X POST -G 'http://localhost:8080/multiply' -d a=3 -d b=36
curl localhost:8080/nest1

Kubernetes

For local kubernetes setup, see instructions in /localk8ssetup

kubectl apply -f k8s.yml

curl -X POST -G 'http://localhost/add' -d a=3 -d b=36 -H"Content-Length:0"
curl -X POST -G 'http://localhost/multiply' -d a=3 -d b=36 -H"Content-Length:0"
curl http://localhost/nest1

Deploy to GKE

  1. Follow the instructions here for configuring your shell and deploying / authenticating a cluster.
  2. Ensure you are using the correct context to address the remote cluster (I use kubectx and kube_ps1 to make this easy).
  3. Edit the k8s.yml file: change the image: entries to use the remote registries.
  4. Deploy the YAML as follows:
kubectl apply -f k8s.yml

Network Diagram


                                 +----------------+
                                 |                |
                          +------>    Frontend    |
                          |      |                |
                          |      +----------------+
                          |
                          |      +----------------+
                          |      |                |
                          +----->+     Adder      |
                          |      |                |
                          |      +----------------+
                          |              ^
                          |              |
                          |              |
       +------------+     |      +----------------+
       |            |     |      |                |
       |   Client   +----------->+   Multiplier   |
       |            |     |      |                |
       +------------+     |      +----------------+
                          |
                          |      +----------------+      +----------------+
                          |      |                |      |                |
                          +----->+     Nest1      +----->+     Nest2      |
                                 |                |      |                |
                                 +----------------+      +----------------+

Contributors