This is an example Kubernetes application that hosts an HTML5 Pac-Man game with Node.js as the web server and backend to read and write data to a MongoDB database.
The Pac-Man game is a modified version of the open source Pac-Man game written in HTML5 with Javascript. You can get the modified Pac-Man game source code here.
Node.js is used as the server side component to host the Pac-Man game application. It uses a few packages such as the Express web application framework as well as the MongoDB driver for the backend Node.js API.
MongoDB is used as the backend database to store the Pac-Man game's high score user data.
Clone this repo which contains the Kubernetes configs and Dockerfile resources.
git clone https://github.com/font/k8s-example-apps.git
cd k8s-example-apps/pacman-nodejs-app
The Dockerfile performs the following steps:
- It is based on Node.js LTS Version 6 (Boron).
- It then clones the Pac-Man game into the configured application directory.
- Exposes port 8080 for the web server.
- Starts the Node.js application using
npm start
.
To build the image run:
cd docker
docker build -t <user>/pacman-nodejs-app .
cd ..
You can test the image by running:
docker run -p 8000:8080 <user>/pacman-nodejs-app
And going to http://localhost:8000/
to see if you get the Pac-Man game.
Create a Quay account which allows unlimited storage and serving of public repositories.
Run the following docker
command to sign in:
$ docker login quay.io
Username: myusername
Password: mypassword
You'll want to tag your previously created Docker image to use the URL and then push it:
docker tag <user>/pacman-nodejs-app quay.io/YOUR_USERNAME/pacman-nodejs-app
docker push quay.io/YOUR_USERNAME/pacman-nodejs-app
Once you've pushed your image, you'll need to update the Kubernetes resources to point to your image before you continue with the rest of the guides.
sed -i 's/ifont/YOUR_USERNAME/' deployments/pacman-deployment*.yaml
Go the settings
tab for your repository and modify the Repository Visibilty
to make the repository public. To navigate directly there, replace <username>
with your username:
https://quay.io/repository//pacman-nodejs-app?tab=settings
Afer pushing, make sure to make your repository public on quay.io
.
You'll need to create 1 to at least 3 Kubernetes cluster(s) depending on whether you want to try out the Pac-Man app on 1 cluster, or try it out on multiple clusters. Below are links that will guide you through it.
Follow the instructions in the below links to test out different federation use-cases.
- Pac-Man application deployed on GKE k8s federated cluster
- Pac-Man application deployed on multiple public cloud providers in a federation: GKE, AWS, and Azure
- Pac-Man application portability: deploy on AWS, GKE, and Azure, then move away from AWS
- Pac-Man application portability: deploy on GKE and Azure, then swap Azure with AWS