1 minute read

Are you a fan of classic video games and looking to deploy a fun project using Kubernetes? This post will walk you through deploying a Mario Bros on a Kuberntes cluster.

The associated code is available on GitHub

Prerequisites

Before you proceed, ensure you have access to a Kubernetes cluster. If you don’t have one set up yet, you can follow our previous post to deploy a Kubernetes cluster on AWS EKS using Terraform.

Components Overview

1. Deployment

The deployment manages the Mario Bros application instances:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mario-deployment
spec:
  replicas: 2  # You can adjust the number of replicas as needed
  selector:
    matchLabels:
      app: mario
  template:
    metadata:
      labels:
        app: mario
    spec:
      containers:
      - name: mario-container
        image: sevenajay/mario:latest 
        ports:
        - containerPort: 80

This configuration sets up 2 replicas, meaning there will be two different pods running the game. The containers expose port 80.

2. Service

The service exposes the Mario Bros application to external traffic:

apiVersion: v1
kind: Service
metadata:
  name: mario-service
spec:
  type: LoadBalancer
  selector:
    app: mario
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

This service is of type LoadBalancer and maps the container’s port 80 to external traffic on port 80.

mario_bros_helm_chart.drawio.svg

Deploying the game

To deploy the game, apply the necessary Kubernetes manifests:

kubectl apply -f k8s_mario/deployment.yaml
kubectl apply -f k8s_mario/service.yaml

Verify that the deployment was successful and all components are running:

kubectl get all

Testing the game

Once the deployment is complete, retrieve the LoadBalancer Ingress URL:

kubectl describe service mario-service

Copy and paste the URL into your browser to access the game. Get ready for some nostalgic gaming fun!

mario-bros-game

Cleaning up

After enjoying the game, clean up the resources by deleting the deployment and service:

kubectl delete service mario-service
kubectl delete deployment mario-deployment

With this, you’ve successfully deployed and enjoyed a classic game on your Kubernetes cluster. Until next time, happy gaming!