Containerize DuckHunt which is a NodeJS app and deploy into a kubernetes cluster.
I'd like to spend sometime to shootout to Matt who published this nostagic, fun game and makes it publicyly avaialble for us. Please feel free to grab his complete source code by hitting the following orinigal link.
https://github.com/MattSurabian/DuckHunt-JS
you will have to clone this entire repo
git clone https://github.com/nutta3/DuckHunt-JS-K8s.git
you should have a copy of this repo on your local. You just have to change your directly to your local dir (where the Dockerfile is) and execute the following command by either using Docker / Podman in order to containerize the app.
docker build -t duckhunt-js:v1 .
if you use Podman, use the following command
podman build -t duckhunt-js:v1 .
it may take a little while to download all dependencies required by this nodeJS app.
at this point, you should have your own image created by now, simple execute the following command to see if you have the image created successfully.
docker image list
podman image list
the dunkhunt-js image should listed there.
now, we need to test it locally first before we deploy it to a kubernetes clusters.
docker run -d -p 80:80 duckhunt-js:v1
podman run -d -p 80:80 duckhunt-js:v1
It should take only a few seconds to start this containerized app (depends on your computer as well). So you can give a try by open a browser and try http://localhost
In this case, we will be using AKS - Azure Kubernetes Service which. Prior to the real deployment to the real cluster, we need to have this image that just created stored in the right place. We can use either Docker Hub or Azure Container Registry, in this tutorial we will be using ACR.
docker tag duckhunt-js:v1 <your Azure Container Registry's name>.azurecr.io/duckhunt:v1
podman tag duckhunt-js:v1 <your Azure Container Registry's name>.azurecr.io/duckhunt:v1
and upload it into Azure Container Registry by login first.
docker login <your ACR's name>.azurecr.io
podman login <your ACR's name>.azurecr.io
By using credential that you can retrive from Azure Portal, Look for access key blade in your Azure Container Registry.
after the login succeeded, let's make a push to the ACR
docker push <your ACR's name>.azurecr.io/duckhunt:v1
podman push <your ACR's name>.azurecr.io/duckhunt:v1
The image should be successfully stored in ACR by now, Check your ACR.
Now, let's deploy the image into AKS by using the pushed image and expose the deployment by using Load Balancer which we can later retrieve the public IP address and access to the DuckHunt deployed in AKS.
# create a deployment in kubernetes cluster by using the image pushed to ACR
kubectl create deployment duckhunt-js --image=<your ACR's name>.azurecr.io/duckhunt:v1
# expose the deployment by using LoadBalancer
kubectl expose deployment duckhunt-js --port=80 --target-port=80 --name=duckhunt-js-svc --type=LoadBalancer
AKS cluster should have the public IP address allocated just for this DuckHunt App, we can retrieve the public UP address from 'Services and ingresses'. Copy this and enter it to the browser, Bingo !! your DuckHunt JS has been successfully deployed on AKS.