This URL hosts a Git repository (ie. git clone https://steady.supply/git/ee will work). For your convenience, the file README.md from this repository is rendered below.

Equal Experts

Please provide a solution that you would provide to a paying client. This should be delivered zipped up and ready to run. Do include a comprehensive ReadMe file.

Chosen problem

Write a simple hello world application in either of these languages: Python, Ruby, Go. Build the application within a Docker container and then load balance the application within a mini kube.

Solution

This repository contains the necessary automations to allow the user to do the following:

Added after submission:

For more details on these see the Post-submission heading at the end of the document.

Repository structure

.
|-- app
|   |-- Dockerfile          # container image definition
|   `-- src
|       `-- main.py         # application source code
|-- LICENSE
|-- Makefile                # developer commands / local automations
|-- manifest.yml            # kubernetes definitions
`-- README.md

Prerequisites

This repository was written and tested on Ubuntu 20.04 but because it doesn’t rely on a package manager, should work on any 64-bit Linux flavour. The container platform used is Docker (version 19.03.8), which is not installed as part of the Make automations. GNU Make itself is also required, along with standard tools git, tar, curl and watch. These programs are available through the package managers of all mainstream Linux distributions.

How to

The commands for interacting with the Minikube cluster created by this repository are contained within the Makefile at the root of the repo.

Basics

To spin up the Minikube cluster, simply run make start in the repository root. This recipe will download the version of Minikube specified by MINIKUBE_VERSION at the head of the Makefile and create a cluster at the Kubernetes version similarly specified by KUBERNETES_VERSION.

Once the cluster is up, for a web-based overview of the Kubernetes cluster, the command make dashboard will start the built-in dashboard and print the URL at which it can be accessed. Note, the command runs a proxy and must be kept open for the dashboard to remain accessible (ie. open a new shell to run the make dashboard command).

The application

The dashboard will only show the basic Kubernetes system components because we haven’t added anything of our on yet. To add the very simple “hello, world” application the command make apply can be used. This command will build (and make available to the cluster) the container image for the application and send a request to the Kubenetes API server to create the following:

Demonstration

NOTE: The deployment takes a few seconds to start for the first time, so you may see some 503 messages whilst containers are starting.

Once the Kubernetes resources have been created, the command make demo is provided which will repeatedly make HTTP requests to the web application running in our cluster. Each container that is part of our deployment will report its unique name as part of the HTTP response, which allows us to see the load-balancing “in action”.

To take the demonstration further, try the following:

Clean up

To delete the cluster, downloaded binaries and any Docker images created the command make clean is provided.

Notable omissions

Post-submission

Some features were added post-submission, either during the pairing interview or to make this repo more demonstrative of a complete approach to developing on Kubernetes clusters.

Namespaces, container build targets

In this repo, the coincidence of a namespace and Docker build target is called a “stage”. A stage represents a particular deployment environment for the application. Here we have stages debug, dev, test and prod which roughly correspond a typical development workflow.

Test

To demonstrate how one might add an integration test against this kind of Kubernetes workflow, a container is defined in test/Dockerfile that is executed outside the cluster, and makes requests to the service that is expected to be running. We use pytest because it’s awesome.

Development tooling/automations

With the debug and dev stages introduced above, it makes sense to create some development automations that simplify common tasks.

hotfix

A tool to copy files from the developers machine to those pods targeted in hotfix.yml; in this case anything labelled service: hello-world in either debug or dev namespaces. To start the tool, use make hotfix.

debug* targets

A couple of targets are provided to start a debugging session. They are perhaps most easily explored in action;

LICENSE

Copyright (c) 2020, Steady Supply Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.