In this blog I will be deploying the iconic Super Mario game on AWS EKS, and I'm here to guide you through the process step by step.
A big shoutout to the creator and maintainer of the Docker image (kaminskypavel/mario) on Docker Hub.
Keep in mind that using certain AWS services for these tasks may result in associated costs.
To get started, make sure you have AWS CLI installed on your machine. If you haven't installed it yet, refer to the AWS Official Documentation for installation instructions.
Once AWS CLI is set up, configure a role on your machine using the AWS CLI. Detailed steps can be found in the same documentation as above
Now, let's address the prerequisites: EKSCTL, kubectl, and Git. Ensure you have these tools installed before moving forward. If you need assistance, you can follow the official documentation links provided below:
EKSCTL Installation Guide
Kubectl Installation Guide
Next, acquire the YAML files essential for cluster creation, deployment and service. You have two options: clone the repository or manually create the files. Ensure you preserve the file names for consistency, or adjust them as the tutorial progresses.
1. Clone the Repository:
If you prefer to clone the repository, use the following command:
git clone https://github.com/balavi7/eks-mario-game
This will copy all the necessary files to your local machine.
2. Create Files Manually:
If you choose to create the files manually, follow these steps:
For the cluster configuration, create a file named ekctl-config.yml.
For the deployment configuration, create a file named deployment.yml.
For the service configuration, create a file named service.yml
You can use your preferred text editor or IDE to craft these YAML files. Ensure the contents align with the specifications outlined in the tutorial.
Whether you clone the repository or create the files manually, maintaining the file names is crucial for a seamless tutorial experience
Let's create the first manifest file "ekctl-config.yml" and add the below content inside
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: mario-cluster
region: ap-south-1
nodeGroups:
- name: ng-1
desiredCapacity: 2
instanceType: t3.small
Once saved this file, lets run the file and create the cluster
eksctl create cluster -f eksctl-config.yaml
This will take upto 15 minutes depending upon speed of the internet. Once the cluster is created you will see the output something like the below screenshot
Once cluster is ready, we need to update kubectl for this newly created cluster, the command is as follows
aws eks --region ap-south-1 update-kubeconfig --name mario-cluster
In which mario-cluster is the name of the cluster, once you run the above command you should get the output which will look like the below screenshot
Once done with updating kubectl, lets create the deployment file. Copy the below contents inside the deployment.yml file
apiVersion: apps/v1
kind: Deployment
metadata:
name: mario
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: mario
image: kaminskypavel/mario
ports:
- name: mario
containerPort: 8080
Once you have saved the file, execute the file using the below command
kubectl apply -f deployment.yaml
Now the application has been created, next step is to create a service for this application so that it can be accessed publicly. Copy the below contents and paste inside the service.yml file
apiVersion: v1
kind: Service
metadata:
name: mario-service
labels:
app: my-app
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: my-app
type: LoadBalancer
Save the file, and you'll use it in the upcoming steps to expose and access your application using the Load Balancer.
Execute the file using the below command
kubectl apply -f service.yaml
Once service is created run the following command and get the load balancer DNS
kubectl get svc
Copy the DNS value and paste in into a new browser.
Congratulations! You've successfully deployed the Mario game on Amazon EKS. Your journey from configuring the environment to deploying the application showcased your skills in orchestrating a resilient and scalable Kubernetes cluster.๐๐
Do not forget to delete all the services once you're done with the demo
eksctl delete cluster --name mario-cluster
kubectl delete --all deployments,svc,pods
Cheers to conquering new heights in the world of cloud-native applications and Kubernetes mastery!