Continuous Operations: How to Deploy Super Mario Bros on Kubernetes and Make It Self-Healing with ArgoCD

HD De Leon Barrios
5 min readOct 17, 2024

--

In today’s cloud-native world, maintaining application uptime is crucial. By leveraging tools like Kubernetes, ArgoCD, and Docker, we can create an infrastructure where every element is watched over by another, ensuring automatic healing and recovery.

In this practical exercise, we’ll deploy Super Mario Bros as a Docker container inside a Kubernetes Pod, showing how a Kubernetes deployment monitors the Pod and how ArgoCD keeps the deployment itself in check. This layered system ensures that even if something goes wrong — such as a Pod or deployment being deleted — it gets recreated automatically.

By the end, you’ll see how each part of the infrastructure works together to protect the core app, Mario Bros. Ⱄⱄ. .ⱄⰔ.

Step 1: Run Mario Bros in Docker

Let’s start by running the Mario Bros container from DockerHub:

To have Docker in you Windows 11, you may need to install WSL2 first, then Ubuntu, and Docker inside that Ubuntu

docker run -d -p 8600:8080 pengbai/docker-supermario

Now, open your browser and go to http://localhost:8600/ to play Super Mario in your local environment!

But what happens if this container stops or is removed?

  • List running containers: First, you can see the running Docker containers with:
docker ps
  • Kill the Mario container: Find the container ID or name from the output, and then kill it using:
docker kill <container_id_or_name>
  • You can confirm the container is killed by running docker ps again, which should no longer show the Mario container.

Let’s take it up a notch and have Kubernetes watch over this.

Step 2: Deploy Mario Bros on Kubernetes

Now we will deploy the Mario game into a Kubernetes cluster, which will help us monitor and automatically recreate the pod if it fails.

To have kubernetes in you Windows 11, you may need to install microk8s in WSL2 Ubuntu, and the kubectl binary.

1. Create a Namespace

First, we’ll create a dedicated namespace for Mario:

kubectl create ns mario-ns

2. Create a Deployment

Now, deploy Mario Bros using the following command:

kubectl create deployment mario-deploy --image=pengbai/docker-supermario --port=8080 --namespace=mario-ns

This creates a deployment that manages a pod running Mario Bros.

3. Port Forwarding to Access the Game

To access Mario Bros from your local machine:

kubectl get pods -n mario-ns

kubectl port-forward pods/mario-<pod-id> 8600:8080 -n mario-ns

#replace "<pod-id>" with the name of your POD

Visit http://localhost:8600/ again, and Mario should be up and running from the Kubernetes cluster!

Step 3: Test Self-Healing with Kubernetes

Now, what happens if you delete the pod? Let’s test this:

kubectl delete pod <pod-name> -n mario-ns

kunectl get pods -n mario-ns

Kubernetes will automatically create a new pod because the deployment ensures there’s always at least one pod running. This is a basic level of self-healing that Kubernetes provides.

However, what if someone accidentally (or intentionally) deletes the deployment itself? That’s where ArgoCD comes in.

Step 4: Add ArgoCD for Continuous Operation

To ensure the deployment is restored even if it’s deleted, we’ll use ArgoCD, which continuously monitors and restores Kubernetes resources.

  1. First, deploy ArgoCD in your cluster (if you haven’t already).
curl -sSL https://raw.githubusercontent.com/achede22/Laboratorios/main/argocd/1_instalar-ArgoCD.sh | bash

kubectl port-forward svc/argocd-server -n argocd 8080:443

2. login into ArgoCD via http

2. Then, add the Mario Bros deployment YAML to a Git repository. Here’s an example Mario Bros deployment YAML: GitHub Mario Kubernetes.

Add Your Deployment to ArgoCD:

In ArgoCD Console, create a new application:

  • App Name: mario-app
  • Project: default
  • Sync Policy: automatic

You can also use ArgoCD CLI:

# Clone Mario Bros kubernetes Repo
cd ~
git clone https://github.com/achede22/k8s-mario.git
cd k8s-mario

# Install Mario Bros in ArgoCD
argocd app create mario-app \
--repo https://github.com/achede22/k8s-mario.git \
--path . \
--dest-server https://kubernetes.default.svc \
--dest-namespace mario-ns \
--sync-policy automated

Point it to your repository containing the Mario deployment. ArgoCD will

now continuously watch this deployment.

Step 5: Continuous Operations

With ArgoCD, even if the entire deployment is deleted, it will be restored within seconds. You can try it yourself:

kubectl delete deployment mario-deploy -n mario-ns

ArgoCD will notice this and automatically redeploy Mario, ensuring your game is back online without any manual intervention.

If ArgoCD is deleted, there won’t be an immediate, built-in system to monitor and heal ArgoCD itself, but you can set up a Kubernetes CronJob or a Pipeline (using tools like Jenkins or GitLab CI) to monitor the existence of ArgoCD. In case it’s deleted, the job can redeploy ArgoCD via a script or Helm chart as you just did.

Automating with Python

In complex infrastructures like this, where many elements monitor and heal each other, Python becomes a key tool for automation. Whether it’s writing custom scripts to manage Kubernetes resources, triggering alerts, or interacting with APIs like ArgoCD’s, Python provides flexibility and power to automate tasks beyond what’s available out of the box.

Conclusion: A Layered System of Watchdogs

By the end of this journey, you’ve learned how to take Mario Bros from a simple Docker container to a fully self-healing Kubernetes deployment managed by ArgoCD. This setup showcases the power of modern DevOps practices, such as continuous operations and automatic problem resolution.

Each element in this ecosystem is monitored and healed by another. ArgoCD watches over Kubernetes, ensuring that deployments remain correct and healthy. In turn, a Kubernetes deployment monitors and automatically heals the Pods.

Inside the Pod, there’s the Docker container, and at the core of this entire infrastructure lies the most important part: the application. In this case, the app is none other than Mario Bros, showcasing how this architecture can protect and keep any critical application running.

Special mention to some Medium posts which inspired this exercise:

Deploying Mario Game on Docker

Deploying Mario Game on Kubernetes

Happy playing — and automating!

--

--

No responses yet