I did this as a PoC for a company talk, to demonstrate how powerful can be the Kubernetes APIs when used also to build custom applications.
Personal note: When developing for Kubernetes, you have to deal with tons of REST APIs and complex relationship between them, this is where the GO ecosystem shines, you have framework and abstractions used to build Kubernetes itself and you are sure to use top-notch quality code; so if you plan to implement something serious with Kubernetes, my advice is to use GO as a first class citizen language of your system.
One of the goal of this project was to use just Kubernetes API without any external dependency (neither the storage), infact is noteworthy that
Configmaps are (ab)used as a persistent storage layer, using a simple technique of split/merge parts of files to save the games.
See it in action:
This project consists of 3 main components:
- A Docker image to run games based on Dosbox + noVNC + Pulseaudio/gStreamer
- A K3d Kubernetes cluster and Skaffold to manage it.
To run the controller it is just needed a working Docker environment.
make you will have end up with:
- A k3d kubernetes cluster
- Docker images loaded
- Game controller deployed
Files can be downloaded from any public http endpoint or from any public GCP cloud storage bucket.
The expect manifest to run a game is this:
apiVersion: retro.sparkfabrik.com/v1 kind: Game metadata: name: game-name spec: name: "Game name human friendly" zipUrl: "gs://my-gs-bucket/game.zip" dir: "GAME" exe: "GAME.EXE"
dir represent the directory of the unzipped game and
exe the binary to run.
To be clear, this is a structure we expect:
unzip game.zip > GAME - GAME.EXE - SOUND.MOD - VIDEO.MOD
Once you have the game up and running, you can access via the web browser by proxying the game service, like this:
kubectl port-forward svc/game-name 8080:8080 8081:8081
Finally you can access the game console on:
At this stage you will be presented with the dosbox command line and the command to run to execute the game.
IMPORTANT: To start the audio websocket, before to start the game and inside the dosbox cli, you have to press
ALT + sthis will start once the needed websocket, to transport the audio from the pulseaudio server to your browser.