# Deploying a classic 2048 game on EKS

In this blog, we will do a real-time project based on EKS. But before deep dive into the project let's know about the EKS and its features.

What is EKS?

EKS, abbreviated as "Elastic Kubernetes Service", is an AWS service managed by the Amazon Web Service. Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications.

With Amazon EKS, we can easily run K8s on AWS without having to manage any underlying infrastructure. It simplifies the process of setting up, operating, and scaling a K8s cluster. We can easily deploy, manage, and scale the containerized applications using Kubernetes while taking advantage of AWS services.

**The objective of the project:** *To install the 2048 game on the EKS cluster in AWS. The game will be deployed in the private subnet and will be accessed from the external world in the public subnet via the Application Load Balancer (ALB)*

**Prerequisites:**

* kubectl
    
    use the link: [https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/)
    
* eksctl
    
    ```bash
    sudo wget -O /usr/local/bin/eksctl https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz
    sudo chmod +x /usr/local/bin/eksctl
    file /usr/local/bin/eksctl
    eksctl version
    ```
    
* AWS CLI
    
    ```bash
    sudo apt update
    sudo apt install -y awscli
    ```
    

Download these tools on your machine if they are not installed. We can look for the official documentation for the installation of these tools.

Configure the AWS credentials

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705746287154/42d8865f-5889-4954-bd54-529af2c45bcb.png align="center")

Configure your account details then only we can access the AWS services and able to create the EKS cluster in AWS.

Once the credentials are successfully done then create the EKS cluster.

Create a cluster using Fargate

```bash
eksctl create cluster --name game-cluster --region us-east-1 --fargate
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705746784062/7d65ac0d-84b5-42e2-8572-6abb67b97b3e.png align="center")

Be patient and wait for the cluster to be created. It takes around 8-10 minutes to create the cluster.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705747672178/fa00542e-493f-4f8d-916a-43fdecaab5dd.png align="center")

Our EKS cluster is ready now.

Update the kube-config file

We need to update the kubectl to work with our EKS cluster.

```bash
aws eks update-kubeconfig --name game-cluster --region us-east-1
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705747951589/3f144775-fc25-499f-bd43-a287729b1584.png align="center")

The file is updated.

Let's create a deployment file for the 2048 game

First of all, let's create a fargate profile.

```bash
eksctl create fargateprofile \
    --cluster demo-cluster \
    --region us-east-1 \
    --name alb-sample-app \
    --namespace game-2048
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705749140411/9ba98b60-2040-4350-ab8c-0c0fa617eb87.png align="center")

We can verify in the compute section of the cluster whether the profile is created or not.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705749235579/ab6d85cf-24da-4a72-b3fe-16425fdb738b.png align="center")

The Fargate profile is created successfully and the namespace is game-2048. We can create the instances on both the namespaces.

Deploy the Deployment, Service and Ingress

```bash
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.5.4/docs/examples/2048/2048_full.yaml
```

This is taken from the official documentation of AWS. If you want to learn from official click [here.](https://docs.aws.amazon.com/eks/latest/userguide/alb-ingress.html)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705750197656/ba840002-f172-4a67-af80-a5927af4fbd4.png align="center")

We can see the pods are running and also the service is in a running state, we can see it is running on the node port but the external IP is not allocated. It means anybody within AWS VPC or having access to the VPC can communicate with the pod using the Node IP along with the port. But to access this game from the external world or by the customers we have deployed the ingress.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705750505525/24f15bbc-1d1e-4500-9065-06eb42528405.png align="center")

Ingress is created with the class **alb** and port 80 but not the address. Only with the address, the customers can access the game. The address is not allocated because the Ingress controller is not created.

So we will create an Ingress controller that will look after the Ingress resources and create and configure the entire load balancer.

Before creating the Ingress controller, configure the IAM OIDC provider.

```bash
eksctl utils associate-iam-oidc-provider --cluster $cluster_name --approve
#replace the cluster name
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705751139140/9943505c-f406-484f-80f4-6c736d3cf37d.png align="center")

IAM OIDC is integrated successfully.

Every controller in Kubernetes is a pod. So we will install an ALB controller and grant this to access the AWS services such as ALB.

Download IAM policy

```bash
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.5.4/docs/install/iam_policy.json
```

Create an IAM policy

```bash
aws iam create-policy \
    --policy-name AWSLoadBalancerControllerIAMPolicy \
    --policy-document file://iam_policy.json
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705751597342/aff84e19-e16a-43ff-8783-ea1db8cf8778.png align="center")

Create IAM Role

```bash
eksctl create iamserviceaccount \
  --cluster=<your-cluster-name> \
  --namespace=kube-system \
  --name=aws-load-balancer-controller \
  --role-name AmazonEKSLoadBalancerControllerRole \
  --attach-policy-arn=arn:aws:iam::<your-aws-account-id>:policy/AWSLoadBalancerControllerIAMPolicy \
  --approve
#replace the cluster name and the AWS account ID in above code
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705751890347/c512752c-ddfa-4ac6-ad5b-fe04ba0e52c7.png align="center")

The role is created successfully.

### **Deploy ALB controller**

Add the Helm repo

```bash
helm repo add eks https://aws.github.io/eks-charts
```

Update the repo

```bash
helm repo update eks
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705752434066/4654061d-9cb8-4e65-b95d-36481be710c2.png align="center")

Install the controller

```bash
helm install aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system \
  --set clusterName=<your-cluster-name> \
  --set serviceAccount.create=false \
  --set serviceAccount.name=aws-load-balancer-controller \
  --set region=<region> \
  --set vpcId=<your-vpc-id>
#replace cluster name, region, vpc-id
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705752498462/5494bd61-ee3a-41e9-a0db-12132822af3b.png align="center")

Load Balancer is installed perfectly without any errors.

Verify the Deployments

```bash
kubectl get deployment -n kube-system aws-load-balancer-controller
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705752759415/865676d0-50c0-48af-9208-87fd2f4f7d28.png align="center")

The load balancer controller is running with 2 replicas.

Let us see whether this load balancer controller has created an application load balancer or not.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705753515150/525539cf-8d92-45d3-a239-bf25603ff34e.png align="center")

We can see the load balancer was created by the load balancer controller just a few minutes ago.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705753639833/8ffb5084-7eae-4fc2-a1f3-1964c393a1bd.png align="center")

Watching this ingress resource, the load balancer controller created the load balancer. Copy the address: [k8s-game2048-ingress2-6d3ad9a3d9-1213836616.us-east-1.elb.amazonaws.com](http://k8s-game2048-ingress2-6d3ad9a3d9-1213836616.us-east-1.elb.amazonaws.com) and access it on the web browser.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705754580269/c816a135-103b-43fe-9719-0abc80a250dc.png align="center")

So our game is live and we can enjoy the game. Congratulations on completing the project smoothly.

> Note: Delete all the resouces once the project is done.

We celebrate the successful deployment of the classic 2048 game on an Amazon EKS cluster, showcasing the power and simplicity of managing containerized applications on AWS. By carefully installing tools like **kubectl, aws cli,** and **eksctl**, configuring AWS credentials, and creating an EKS cluster with Fargate profiles, we laid the foundation for a smooth deployment.

Utilizing K8s resources and the AWS Load Balancer Controller, we ensured secure external access to the game through an Application Load Balancer. The journey concluded with the satisfaction of witnessing the game go live. In the future, we will bring many more projects based on Kubernetes. Stay updated and keep learning.

Happy Learning!!
