GoKubernetes - Demo application for Kubernetes Up and Running

Overview

Demo application for "Kubernetes Up and Running"

screenshot

Running

kubectl run --restart=Never --image=gcr.io/kuar-demo/kuard-amd64:blue kuard
kubectl port-forward kuard 8080:8080

Open your browser to http://localhost:8080.

Building

We have ~3 ways to build. This has changed slightly from when the book is published so I'd view this as authoritative.

Insert Binary

This aligns with what is in the book. You need to build the binary to run somehow and then insert it into a Docker image. The easiest way to do this is to use the fully automated make system to build the binary and then create a Dockerfile for creating an image.

Create the binary by typing make at the command line. This'll build a docker image and then run it to compile the binary.

Now create a minimal Dockerfile to contain that binary:

FROM alpine
COPY bin/blue/amd64/kuard /kuard
ENTRYPOINT [ "/kuard" ]

Overwrite Dockerfile with this and then run docker build -t kuard-amd64:blue .. Run with docker run --rm -ti --name kuard --publish 8080:8080 kuard-amd64:blue.

To upload to a registry you'll have to tag it and push to your registry. Refer to your registry documentation for details.

Multi-stage Dockerfile

A new feature of Docker, since the book was published, is a "multi-stage" build. This is a way to run build multiple images and then copy files between them.

The Dockerfile at the root of this repo is an example of that. It creates one image to build kuard and then another image for running kuard.

You can easily build an image with docker build -t kuard-amd64:blue .. Run with docker run --rm -ti --name kuard --publish 8080:8080 kuard-amd64:blue.

To upload to a registry you'll have to tag it and push to your registry. Refer to your registry documentation for details.

Fancy Makefile for automated build and push

This will build and push container images to a registry. This builds a set of images with "fake versions" (see below) to be able to play with upgrades.

make all-push REGISTRY=<my-gcr-registry>

If you are having trouble, try issuing a make clean to reset stuff.

KeyGen Workload

To help simulate batch workers, we have a synthetic workload of generating 4096 bit RSA keys. This can be configured through the UI or the command line.

--keygen-enable               Enable KeyGen workload
--keygen-exit-code int        Exit code when workload complete
--keygen-exit-on-complete     Exit after workload is complete
--keygen-memq-queue string    The MemQ server queue to use. If MemQ is used, other limits are ignored.
--keygen-memq-server string   The MemQ server to draw work items from.  If MemQ is used, other limits are ignored.
--keygen-num-to-gen int       The number of keys to generate. Set to 0 for infinite
--keygen-time-to-run int      The target run time in seconds. Set to 0 for infinite

MemQ server

We also have a simple in memory queue with REST API. This is based heavily on https://github.com/kelseyhightower/memq.

The API is as follows with URLs being relative to <server addr>/memq/server. See pkg/memq/types.go for the data structures returned.

Method Url Desc
GET /stats Get stats on all queues
PUT /queues/:queue Create a queue
DELETE /queues/:queue Delete a queue
POST /queues/:queue/drain Discard all items in queue
POST /queues/:queue/enqueue Add item to queue. Body is plain text. Response is message object.
POST /queues/:queue/dequeue Grab an item off the queue and return it. Returns a 204 "No Content" if queue is empty.

Versions

Images built will automatically have the git version (based on tag) applied. In addition, there is an idea of a "fake version". This is used so that we can use the same basic server to demonstrate upgrade scenarios.

Originally (and in the Kubernetes Up & Running book) we had 1, 2, and 3. This confused people so going forward we will be using colors instead: blue, green and purple. This translates into the following container images:

gcr.io/kuar-demo/kuard-amd64:v0.9-blue
gcr.io/kuar-demo/kuard-amd64:blue
gcr.io/kuar-demo/kuard-amd64:v0.9-green
gcr.io/kuar-demo/kuard-amd64:green
gcr.io/kuar-demo/kuard-amd64:v0.9-purple
gcr.io/kuar-demo/kuard-amd64:purple

(Another way to think about it is that :blue is essentially :latest-blue)

We also build versions for arm, arm64, and ppc64le. Just substitute the appropriate architecture in the image name. These aren't as well tested as the amd64 version but seem to work okay.

Development

If you just want to do Go server development, you can build the client as part of a build make. It'll drop the result in to sitedata/built/.

If you want to do both Go server and React.js client dev, you need to do the following:

  1. Have Node installed
  2. In one terminal
  • cd client
  • npm install
  • npm run start
  • This will start a debug node server on localhost:8081. It'll proxy all unhandled requests to localhost:8080
  1. In another terminal
  • Ensure that $GOPATH is set to the directory with your go source code and binaries + ensure that $GOPATH is part of $PATH.
  • go get -u github.com/jteeuwen/go-bindata/...
  • go generate ./pkg/...
  • GO111MODULE=on go run cmd/kuard/*.go --debug
  1. Open your browser to http://localhost:8081.

This should support live reload of any changes to the client. The Go server will need to be exited and restarted to see changes.

TODO

  • Make file system browser better. Show size, permissions, etc. Might be able to do this by faking out an index.html as part of the http.FileSystem stuff.
  • Clean up form for keygen workload. It is too big and the form build doesn't have enough flexibility to really shrink it down.
  • Get rid of go-bindata as it is abandoned.
You might also like...
A simple application, demo at this point, on how to pull a backup from Collibra on prem (say for Cohesity backup)
A simple application, demo at this point, on how to pull a backup from Collibra on prem (say for Cohesity backup)

go-get-collibra-backup Introduction This repository is a very simple go application that's intended, at this point, more of a demonstration about how

A demo repository that shows CI/CD integration using DroneCI + ArgoCD + Kubernetes.
A demo repository that shows CI/CD integration using DroneCI + ArgoCD + Kubernetes.

CI/CD Demo This is the demo repo for my blog post. This tutorial shows how to build CI/CD pipeline with DroneCI and ArgoCD. In this demo, we use Drone

A kubernetes operator demo generated by code-generator, it only watches cr's events

intro a small operator demo which only watches car cr's events. environment: ubuntu-20.04-amd64 k3s-1.21 docker-20.10.7 go-1.17 tools code-generator d

Kubernetes Admission Controller Demo: Validating Webhook for Namespace lifecycle events

Kubernetes Admission Controller Based on How to build a Kubernetes Webhook | Admission controllers Local Kuberbetes cluster # create kubernetes cluste

A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod
A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod

GPU Mounter GPU Mounter is a kubernetes plugin which enables add or remove GPU resources for running Pods. This Introduction(In Chinese) is recommende

Kubedock is a minimal implementation of the docker api that will orchestrate containers on a Kubernetes cluster, rather than running containers locally.

Kubedock Kubedock is an minimal implementation of the docker api that will orchestrate containers on a kubernetes cluster, rather than running contain

Set of Kubernetes solutions for reusing idle resources of nodes by running extra batch jobs

Caelus Caelus is a set of Kubernetes solutions for reusing idle resources of nodes by running extra batch jobs, these resources come from the underuti

Cmsnr - cmsnr (pronounced "commissioner") is a lightweight framework for running OPA in a sidecar alongside your applications in Kubernetes.

cmsnr Description cmsnr (pronounced "commissioner") is a lightweight framework for running OPA in a sidecar alongside your applications in Kubernetes.

Linux provisioning scripts + application deployment tools. Suitable for self-hosting and hobby-scale application deployments.

Apollo Linux provisioning scripts + application deployment tools. Suitable for self-hosting and hobby-scale application deployments. Philosophy Linux-

Owner
ilyaNEW
ilyaNEW
The OCI Service Operator for Kubernetes (OSOK) makes it easy to connect and manage OCI services from a cloud native application running in a Kubernetes environment.

OCI Service Operator for Kubernetes Introduction The OCI Service Operator for Kubernetes (OSOK) makes it easy to create, manage, and connect to Oracle

Oracle 24 Sep 27, 2022
Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes.

Carrier is a Kubernetes controller for running and scaling game servers on Kubernetes. This project is inspired by agones. Introduction Genera

Open Cloud-native Game-application Initiative 31 Nov 25, 2022
kitex running in kubernetes cluster and discover each other in kubernetes Service way

Using kitex in kubernetes Kitex [kaɪt'eks] is a high-performance and strong-extensibility Golang RPC framework. This go module helps you to build mult

adolli 1 Feb 21, 2022
A very simple, silly little kubectl plugin / utility that guesses which language an application running in a kubernetes pod was written in.

A very simple, silly little kubectl plugin / utility that guesses which language an application running in a kubernetes pod was written in.

Tom Granot 2 Mar 9, 2022
KEDA is a Kubernetes-based Event Driven Autoscaling component. It provides event driven scale for any container running in Kubernetes

Kubernetes-based Event Driven Autoscaling KEDA allows for fine-grained autoscaling (including to/from zero) for event driven Kubernetes workloads. KED

KEDA 5.9k Jan 7, 2023
False-sharing-demo - Demo for performance effects of CPU cache false-sharing

Example of CPU cache false-sharing in Go. A simple example where 2 integer varia

glebarez 3 Aug 28, 2022
Automating Kubernetes Rollouts with Argo and Prometheus. Checkout the demo URL below

observe-argo-rollout Demo for Automating and Monitoring Kubernetes Rollouts with Argo and Prometheus Performing Demo The demo can be found on Katacoda

null 33 Nov 16, 2022
PolarDB Stack is a DBaaS implementation for PolarDB-for-Postgres, as an operator creates and manages PolarDB/PostgreSQL clusters running in Kubernetes. It provides re-construct, failover swtich-over, scale up/out, high-available capabilities for each clusters.

PolarDB Stack开源版生命周期 1 系统概述 PolarDB是阿里云自研的云原生关系型数据库,采用了基于Shared-Storage的存储计算分离架构。数据库由传统的Share-Nothing,转变成了Shared-Storage架构。由原来的N份计算+N份存储,转变成了N份计算+1份存储

null 23 Nov 8, 2022
Hot-swap Kubernetes clusters while keeping your microservices up and running.

Okra Okra is a Kubernetes controller and a set of CRDs which provide advanced multi-cluster appilcation rollout capabilities, such as canary deploymen

Yusuke Kuoka 46 Nov 23, 2022
Kubernetes OS Server - Kubernetes Extension API server exposing OS configuration like sysctl via Kubernetes API

KOSS is a Extension API Server which exposes OS properties and functionality using Kubernetes API, so it can be accessed using e.g. kubectl. At the moment this is highly experimental and only managing sysctl is supported. To make things actually usable, you must run KOSS binary as root on the machine you will be managing.

Mateusz Gozdek 3 May 19, 2021