Deploying Super Mario Game on Kubernetes (EKS)
Mario is widely considered the most famous video game character in history. He has appeared in a variety of merchandise, such as clothing and collectible items, and people and places have been nicknamed after him. He has also inspired a considerable amount of unofficial media.
Steps:
- Ec2 Instance
- IAM role
- Cluster Provision
- Terraform
- Elastic Kubernetes Service (Amazon EKS)
buymeacoffee ☕ 👈 Click the link
Create a Ec2 Instance
- Sign in to AWS Console
- Navigate to EC2 Dashboard
- Launch Instance
- Choose an Amazon Machine Image (AMI) → you can choose “Ubuntu” image.
- Choose an Instance Type → Select
t2.micro
as your instance type. - Configure Instance Details
- Add Tags (Optional)
- Configure Security Group
- Review and Launch
- Select Key Pair
- Access the EC2 Instance
Create IAM role
Identity and Access Management (IAM) is a web service that helps you securely control access to AWS resources. With IAM, you can centrally manage permissions that control which AWS resources users can access.
Role → Create role → AWS service → Service (Ec2) → Permission (Administrator access) → Create a role
Attach this role to Ec2 instance
Actions → Security → Modify IAM role
Select the Role that created earlier and click on Update IAM role.
Cluster provision
- Now clone this Repo.
git clone https://github.com/Ibrahimsi/k8s-mario.git - Provide the executable permission to script.sh file, and run it
chmod +x script.sh
Run the Script
./script.sh
This script will install AWS cli, Kubectl, Terraform
./script.sh run the command
#!/bin/bash
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt-get install unzip -y
unzip awscliv2.zip
sudo ./aws/install
# Install kubectl
sudo apt update
sudo apt install curl -y
curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
# Install Terraform
sudo apt install wget -y
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform -y
echo "Installation completed successfully."
Check Version
aws --version
kubectl version --client
terraform --version
Change directory into the EKS-TF
NOTE: Don’t forgot to change the s3 bucket name in the backend.tf file
Terraform
Initializes the Terraform working directory, downloading any necessary provider plugins
terraform init
Terraform Validate runs checks that verify whether a configuration is syntactically valid and internally consistent, regardless of any provided variables or existing state.
terraform validate
Terraform plan command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.
When Terraform creates a plan it → Reads the current state of any already-existing remote objects to make sure that the Terraform state is up-to-date.
Run terraform apply to provision cluster
terraform apply --auto-approve
It will take more than 10 minutes
Elastic Kubernetes Service (Amazon EKS)
Elastic Kubernetes Service (Amazon EKS) is a managed Kubernetes service that makes it easy for you to run Kubernetes on AWS and on-premises.
EKS provides an integrated console for Kubernetes clusters. Cluster operators and application developers can use EKS as a single place to organize, visualize, and troubleshoot your Kubernetes applications running on Amazon EKS.
The EKS console is hosted by AWS and is available automatically for all EKS cluster
Update the Kubernetes configuration and make sure change your desired region.
aws eks update-kubeconfig --name EKS_CLOUD --region ap-south-1
Kubernetes Deployment tells Kubernetes how to create or modify instances of the pods that hold a containerized application. Deployments can help to efficiently scale the number of replica pods, enable the rollout of updated code in a controlled manner, or roll back to an earlier deployment version if necessary.
kubectl apply -f deployment.yaml #to check the deployment
kubectl get all
List down all the pods, services, statefulsets etc…,
Service.yaml is a method for exposing a network application that is running as one or more Pods in your cluster.
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 and you will see the Mario game.
Remove the service and deployment first
kubectl delete service mario-service
kubectl delete deployment mario-deployment
Destroy the cluster
terraform destroy --auto-approve
Thank you 🙏 for taking the time to read our blog.