Deploy Super Mario Game on AWS EKS

Deploy Super Mario Game on AWS EKS

Introduction:

This guide walks you through deploying a Super Mario game on AWS using Terraform and Kubernetes. Ensure you have an Ubuntu instance, the necessary IAM roles, terraform installed, and AWS CLI with Kubectl configured on your instance before starting.

Prerequisites:

  1. An Ubuntu Instance

  2. IAM role

  3. Terraform should be installed on the instance

  4. AWS CLI and KUBECTL on Instance

LET'S DEPLOY

STEP 1: Launch the Ubuntu instance

  • Sign in to AWS Console: Log in to your AWS Management Console.

  • Navigate to EC2 Dashboard: Go to the EC2 Dashboard by selecting "Services" in the top menu and then choosing "EC2" under the Compute section.

  • Launch Instance: Click on the "Launch Instance" button to start the instance creation process.

  • Choose an Amazon Machine Image (AMI): Select an appropriate AMI for your instance. For example, you can choose Ubuntu image.

  • Choose an Instance Type: In the "Choose Instance Type" step, select t2.micro as your instance type. Proceed by clicking "Next: Configure Instance Details."

  • Configure Instance Details:

    1. For "Number of Instances," set it to 1 (unless you need multiple instances).

    2. Configure additional settings like network, subnets, IAM role, etc., if necessary.

    3. For "Storage," click "Add New Volume" and set the size to 8GB (or modify the existing storage to 8GB).

    4. Click "Next: Add Tags" when you're done.

  • Add Tags (Optional): Add any desired tags to your instance. This step is optional, but it helps in organizing instances.

  • Configure Security Group:

    1. Choose an existing security group or create a new one.

    2. Ensure the security group has the necessary inbound/outbound rules to allow access as required.

  • Review and Launch: Review the configuration details. Ensure everything is set as desired.

  • Select Key Pair:

    1. Select "Choose an existing key pair" and choose the key pair from the dropdown.

    2. Acknowledge that you have access to the selected private key file.

    3. Click "Launch Instances" to create the instance.

  • Access the EC2 Instance: Once the instance is launched, you can access it using the key pair and the instance's public IP or DNS.

  • Ensure you have necessary permissions and follow best practices while configuring security groups and key pairs to maintain security for your EC2 instance.

STEP 2: Create an IAM role

  • Search for IAM in the AWS Console and click on "Roles."

  • .Click "Create Role," select entity type as AWS service (EC2), and choose Administrator Access for learning.

  • Provide a Name for Role and click on Create role.

  • The role is created.

  • Now Attach this role to Ec2 instance that we created earlier, so we can provision cluster from that instance.

  • Go to EC2 Dashboard and select the instance.

  • Click on Actions --> Security --> Modify IAM role.

  • Select the Role that was created earlier and click on Update IAM role.

STEP 3: Cluster provision

  • Clone the repository using the following command:
https://github.com/Akashdhengale/k8s-mario.git

  • Change to the 'k8s-mario' directory.
cd k8s-mario

Grant executable permission to the 'script.sh' file and execute it:

sudo chmod +x script.sh
./script.sh

  • This script automates the installation of Terraform, AWS CLI, Kubectl, and Docker.

  • Check the installed versions:

docker --version
aws --version
kubectl version --client
terraform --version

  • Now, navigate to the 'EKS-TF' directory and create an S3 bucket using the following command:
cd EKS-TF
aws s3api create-bucket --bucket <your-unique-bucket-name> --region us-east-1
  • Afterward, remember to replace the placeholder <your-unique-bucket-name> with your chosen bucket name and update the region in the 'backend.tf' file."

  • Run Terraform:
# Initialize Terraform
terraform init

# Validate and plan Terraform configuration
terraform validate
terraform plan

# Apply Terraform to provision the cluster
terraform apply --auto-approve

Completed in approximately 10 minutes.

  • Update Kubernetes Configuration:
# Update Kubernetes configuration, specifying the desired region
aws eks update-kubeconfig --name EKS_CLOUD --region ap-south-1

  • Change back to the k8s-Mario directory
cd ..
  • Apply Deployment and Service:
# Apply the deployment configuration
kubectl apply -f deployment.yaml

# Check the deployment status
kubectl get all

  • Apply the service configuration
kubectl apply -f service.yaml
kubectl get all

  • Describe the service and copy the LoadBalancer Ingress
kubectl describe service mario-service

  • Paste the Ingress link in a browser to play the Mario game

  • Let’s Go back to 1985 and play the game like children.

Destruction:

  • Let's remove the service and deployment.
kubectl get all
kubectl delete service mario-service
kubectl delete deployment mario-deployment

  • Destroy the Terraform cluster
terraform destroy --auto-approve

Conclusion:

The Super Mario project blends childhood memories with modern technology, utilizing tools like Terraform, AWS EKS, and Kubernetes. Dive into cloud gaming, relive childhood fun, and explore DevOps innovations in this exciting journey.

Did you find this article valuable?

Support Akash Dhengale by becoming a sponsor. Any amount is appreciated!