Deploying Super Mario on Kubernetes with Jenkins CI/CD

·

5 min read

Deploying Super Mario on Kubernetes with Jenkins CI/CD

Hey everyone! 🎮 Remember the fun of 90’s gaming?Let’s hit pause on the present and take a journey back to those legendary moments! With the game now running on Kubernetes, it's time to power up and dive straight into the nostalgic world of Mario. Controllers in hand, let’s get ready to relive the magic!

Super Mario has been a fan-favorite for years, and now, we’re going to take it to the next level. In this guide, we’ll show you how to deploy Super Mario on Amazon's Elastic Kubernetes Service (EKS). By leveraging Kubernetes, we can bring scalability, reliability, and seamless management to the game’s deployment on AWS. This project is the perfect example of how modern DevOps practices can elevate even the most nostalgic experiences!

Prerequisites:

  • Ubuntu Instance

  • IAM Role

  • Terraform should be installed on the instance

AWS CLI and kubectl on Instance

Manual Approach vs CI/CD Automation:

In my blog post, I’ll explain the step-by-step process, following Ajay Kumar Yegireddi’s approach, who wrote about deploying Super Mario on Kubernetes. Ajay manually used Terraform and kubectl to provision the infrastructure and deploy the game. However, I’ve taken this a step further by automating the entire process with Jenkins CI/CD pipelines, allowing for a much more streamlined, scalable, and repeatable deployment.

Let’s dive into the difference between the manual approach and the automation process I implemented with Jenkins.


Manual Process (As per Ajay's Blog):

Ajay’s method involves logging into AWS and manually running commands to set up an Ubuntu instance on AWS, configuring the IAM role, and manually running Terraform scripts (terraform init, terraform plan, terraform apply) to provision the Kubernetes infrastructure on AWS EKS. After the infrastructure is provisioned, Ajay uses kubectl to manually deploy the game to the Kubernetes cluster.

Steps Followed:

  1. Launch Ubuntu EC2 instance – Set up AWS EC2 instance for running Terraform and kubectl.

  2. IAM Role – Created an IAM role to give permissions to EC2 instances for provisioning AWS resources.

  3. Terraform – Manually ran terraform init, terraform validate, terraform plan, and terraform apply to provision the EKS infrastructure.

  4. Kubernetes Deployment – Applied Kubernetes manifests (deployment.yaml, service.yaml) using kubectl to deploy Super Mario on EKS.

  5. Cleanup – Finally, Ajay manually destroyed the resources using terraform destroy.

While this process works perfectly, it's time-consuming, error-prone, and not ideal for repeatability.


My CI/CD Approach:

I’ve enhanced the process by creating a Jenkins CI/CD pipeline that automates every step of the deployment, including the provisioning of Terraform-managed infrastructure and Kubernetes deployments. This approach ensures that the game can be deployed quickly, efficiently, and consistently, and is easily repeatable for any future updates.

Key Automation Stages in My Jenkins Pipeline:

  1. Docker Image Build and Push – The Docker image for the Super Mario game is pulled from a public Docker Hub repository, tagged, and then pushed to a private Docker registry (Docker Hub) for further use in Kubernetes deployments.

  2. Terraform Setup – Using a Jenkins pipeline, I automate running the terraform init, terraform plan, and terraform apply commands to create the infrastructure on AWS EKS. I make sure the AWS credentials are securely passed into Jenkins using credentials stored in the Jenkins secret manager.

  3. EKS Cluster Setup – The Jenkins pipeline retrieves the EKS cluster name dynamically from Terraform outputs and configures the Kubernetes CLI (kubectl) to interact with the provisioned EKS cluster.

  4. Kubernetes Deployment – I automate the kubectl apply -f command to deploy the game onto the EKS cluster and expose it via a service. This step eliminates the need for any manual configuration and guarantees that the deployment is repeatable.

  5. Cleanup – The pipeline also includes a cleanup stage that destroys Kubernetes resources and Terraform-managed infrastructure automatically. This ensures the environment is clean after each test or deployment cycle.


Steps Involved in My CI/CD Pipeline:

  1. Docker Image Build and Push:

    • Pull the latest Super Mario game image from the source.

    • Tag the image with the proper name for my registry.

    • Push it to Docker Hub for use in Kubernetes.

  2. Terraform Infrastructure Setup:

    • Initialize Terraform and apply the configuration to provision the infrastructure on AWS EKS.

    • Use terraform plan to validate changes and terraform apply to provision the resources.

  3. Kubernetes Deployment:

    • Deploy the game using kubectl and ensure the game is accessible via a load balancer.

    • Apply the deployment and service YAML files.

  4. CI/CD Automation:

    • All these steps are automated within a Jenkins pipeline, which ensures repeatability, scalability, and reliability.
  5. Clean Up:

    • Resources created during testing are cleaned up automatically using Jenkins to remove Kubernetes services and deployments, as well as destroy the Terraform-managed infrastructure.

Instructions to Run Locally:

  1. Clone this repository:
git clone https://github.com/soumyatata/P2-Super-Mario-K8s-Deployment.git
  1. Install Jenkins, Docker, Terraform, and kubectl on your machine.

Note : All commands are available in script.sh

  1. Set up AWS credentials in Jenkins for AWSCredentials and Docker registry credentials as docker.

  2. Run the Jenkins pipeline to deploy the Super Mario game automatically.


Reference:

  • Ajay Kumar Yegireddi's Article – Deploying Super Mario on Kubernetes: Ajay’s article gives a manual step-by-step guide to deploying Super Mario on Kubernetes using Terraform and EKS. My project automates the entire workflow with Jenkins CI/CD pipelines for seamless deployments.

Conclusion:

By using a Jenkins CI/CD pipeline, I’ve transformed Ajay’s manual process into an automated, reliable, and scalable workflow. This not only makes deployments faster but also ensures that every step in the deployment process is repeatable, transparent, and error-free. Whether you’re working on a small project or scaling it to handle more complex environments, CI/CD pipelines are a game-changer in today’s DevOps landscape.

Until next time, keep gaming and keep automating!

Â