🚀 Deployed 2048 Game App on Amazon EKS with Fargate with Custom Domain & ALB Ingress!


Pre-requisites
Before starting, ensure you have the following tools installed on your system:
AWS CLI: This tool allows you to interact with various AWS services directly from your command line. It’s essential for configuring your AWS environment.
eksctl: A user-friendly command-line tool that simplifies the creation and management of Amazon EKS (Elastic Kubernetes Service) clusters. It automates tasks like cluster creation and management, making it easier to work with Kubernetes on AWS.
kubectl: The Kubernetes command-line tool for managing and interacting with your Kubernetes clusters. It is used for deploying applications, inspecting cluster resources, and managing the Kubernetes environment.
Step 1: Create EKS Cluster Using AWS Fargate
In this step, we'll create an EKS cluster using AWS Fargate, which allows you to run containers without the need to manage the underlying EC2 instances. This provides a serverless experience for Kubernetes workloads, making it easy to scale and manage.
eksctl create cluster --name demo-cluster --region us-east-1 –fargate
Verify EKS cluster is created in AWS console
Fargate profile - default
Step 2: Update KubeConfig
After creating the EKS cluster, update your kubeconfig file to interact with the Kubernetes cluster using kubectl. Run the following command:
aws eks update-kubeconfig --name<cluster name> --region <region>
This updates your local configuration to authenticate and manage the EKS cluster.
Step 3: Creating a Fargate Profile
To run our application in Fargate, we need to create a Fargate profile that attaches to our namespace. Use the following command:
create fargate profile with flag --namespace
eksctl create fargateprofile --cluster demo-cluster --region us-east-1 --name=alb-simple-app --namespace game-2048
Verify in console new fargate profile is created
Step 4: Deploying the 2048 Application using yaml files -
Now, let’s deploy the 2048 application. This involves creating a Kubernetes Pod, a service for the Pod, and an Ingress resource to allow traffic to reach our application. To deploy everything at once, run:
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.5.4/docs/examples/2048/2048_full.yaml
yaml files
apiVersion: v1
kind: Namespace
metadata:
name: game-2048
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: game-2048
name: deployment-2048
spec:
selector:
matchLabels:
app.kubernetes.io/name: app-2048
replicas: 5
template:
metadata:
labels:
app.kubernetes.io/name: app-2048
spec:
containers:
- image: alexwhen/docker-2048
imagePullPolicy: Always
name: app-2048
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
namespace: game-2048
name: service-2048
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
type: NodePort
selector:
app.kubernetes.io/name: app-2048
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
namespace: game-2048
name: ingress-2048
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
rules:
- http:
paths:
- path: /*
backend:
serviceName: service-2048
servicePort: 80
Verify pods and services are running
Verify ingress resource is created
Address is not created because we have not yet created any ingress controller yet.
Step 5: Creating an IAM OIDC Provider
To allow the ALB Controller to access the Application Load Balancer, we need to create an IAM OIDC Provider. Run the following command.
eksctl utils associate-iam-oidc-provider --cluster $cluster_name --approve
This command links an IAM OIDC identity provider with your EKS cluster (demo-cluster), enabling Kubernetes service accounts to assume IAM roles. The --approve flag automatically approves the association without prompting.
Step 6: Creating a Service Account with IAM Role and Policy
Next, we’ll create a service account linked to an IAM role and policy that allows the ALB Controller to access the Load Balancer. Use the following command:
Download IAM policy
If you are using linux then use below command.
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.11.0/docs/install/iam_policy.json
IAM policy is created
Create IAM Role
eksctl create iamserviceaccount --cluster=demo-cluster --namespace=kube-system --name=aws-load-balancer-controller --role-name AmazonEKSLoadBalancerControllerRole --attach-policy-arn=arn:aws:iam:: <your-aws-account-id>:policy/AWSLoadBalancerControllerIAMPolicy --approve
Make sure to replace <your-aws-account-id> with your actual AWS account ID.
Step 7: Creating the ALB Controller Using Helm Charts
Deploy ALB controller
using helm we deploy alb controller in AWS.
Add helm repo
helm repo add eks https://aws.github.io/eks-charts
Update the repo
helm repo update eks
Finally, install the ALB Controller:
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>
Verify that the deployments are running.
kubectl get deployment -n kube-system aws-load-balancer-controller
ALB controller is created. Now we get the address in ingress
kubectl get ingress -n game-2048
Verify in console
Step 8: Accessing the 2048 game
Once everything is set up, you can access your 2048 game application deployed on EKS. You should see a URL generated for the ALB. Open it in your web browser, and enjoy playing the game!
Step 9: (Optional) Purchase a Custom Domain
For a more professional setup and easier access, you can optionally purchase a custom domain from a domain registrar (e.g., Spaceship, Route 53, GoDaddy). This allows you to access your application using a user-friendly URL instead of the default Load Balancer DNS name.
Step 10: Create hosted zone in AWS Route 53
Create a public hosted zone in AWS Route 53 for your custom domain to manage DNS records and route traffic to your application. This step enables you to link your domain with AWS services.
Click on create record
Step 11: Update Nameservers in Domain Registrar
Update the nameserver records in your Domain Registrar to match those provided by AWS Route 53 for proper DNS routing.
Step 12: Configure Ingress with Custom Domain
Modify the ingress.yaml file to include your custom domain under the host field for proper routing through the ALB.
update host in ingress.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: game-2048
name: ingress-2048
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing apply
alb.ingress.kubernetes.io/target-type: ip
spec:
ingressClassName: alb
rules:
- host: <your-custom-domain>
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-2048
port:
number: 80
Step 13: Verify Ingress Hostname Update
After updating ingress.yaml, run the following command to check the controller logs and verify that the custom hostname is recognized by the AWS Load Balancer Controller:
kubectl logs aws-load-balancer-controller-97c4789fb-t7p8n -n kube-system
Step 14: Verify DNS Propagation and ALB Configuration
Use whatsmydns.net to check if your domain's DNS is propagated correctly and pointing to the correct IP. Also, verify that your ALB listener and rules are properly configured to route traffic to your domain.
Note: DNS propagation may take anywhere from 3 to 48 hours, so please be patient before accessing the application.
Step 15: Access the 2048 Game on Custom Domain
Once DNS propagation is complete, access your 2048 game via the custom domain (e.g., www.abhijitshenolikar.shop).
Step 16: Deleting the EKS Cluster
Run the command eksctl delete cluster --name demo-cluster --region us-east-1 to permanently delete the EKS cluster named demo-cluster in the us-east-1 region, removing all associated resources.
Conclusion
You’ve successfully deployed the 2048 Game App on Amazon EKS with Fargate, a custom domain, and ALB Ingress. Reach out if you have any questions!
Subscribe to my newsletter
Read articles from Abhijit Shenolikar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
