In this article we will be deploying famous 2048 Game on AWS-EKS cluster .Post successful deployment we would be able to play game.
Before proceeding we nee to have working AWS account as there will be nominal charges for this deployment.
Let we proceed to deploy the same as below Step-by-Step.
Step1=> Creating IAM Role for Cluster Communication.
In this step we will be creating IAM Role for EKS cluster communication.This is required to setup EKS .Follow as below.
Search for IAM in search box and Click IAM and click on Roles
Step2=> Creating IAM Role for WorkerNode Communication.
Click on IAM and then click on Roles as below
Select EC2 as below "as we are going to create Role for EC2 communication.
Select below policies and click Next .
- AmazonEKSWorkerNodePolicy
- AmazonEC2ContainerRegistryReadOnly
- AmazonEKS_CNI_Policy
Name this Role as "eksWorkerNodeRole" and check for confirmation page.
As of now 2 Roles have been created now.
Step3=> Creating Security Groups for Application Communication.
In this step we will create Security Groups and that will be used for inbound communication and allow http and 8080 ports as below.
Search for EC2 in AWS Console and then click on Security Groups as below.
Step 4=> Creating EKS Cluster.
Go to search box and look for EKS and launch
Name EKS cluster as "eksGameCluster" and select default kube version.
We need to select pre-created Cluster service Role which we did in last step.
Step 5=> Adding WorkerNodes to EKS Cluster.
Post creation of Cluster we will add Dataplane / worker node as below.
Click on "compute" under cluster section as below and click Add Node group.
After that enter Worker node name as "eksWorkerNodes" and select already created Role which we did in last steps.
Leave other options unchanged and click Next.
Select Compute and scaling as below and click Next.
select predefined VPC as below and click Next
After few minutes we will see below confirmation and screen.
At this stage our Control plane and Data Plane created now. Let we proceed to create deployment in next step.
Step 6=> Authenticating Cluster.
To authenticate cluster we need to invoke AWS Cloud shell.Open AWS console and look for Cloudshell on Top right corner and open the same.New shell login will be prompted .Now in this shell we need to execute below commands.
[cloudshell-user@ip-10-130-68-164 ~]$ aws sts get-caller-identity
Create a kubeconfig file where it stores the credentials for EKS:
--kubeconfig configuration allows you to connect to your cluster using the kubectl command line.
aws eks update-kubeconfig --region region-code --name my-cluster
[cloudshell-user@ip-10-130-68-164 ~]$ aws eks update-kubeconfig --region us-east-1 --name eksGameCluster
We also need to install nano as below.
[cloudshell-user@ip-10-130-68-164 ~]$sudo yum install nano -y
Step 7=> Deploying Application and Creating Load Balancer on Cluster.
In this step we will create 2 YAML file and will deploy the same as below while being in AWS Cloudshell.
Create a new POD in EKS for the 2048 game
# clean up the files in cloudshell (Optional)
rm *.*
# create the config file in YAML to deploy 2048 game pod into the cluster
nano 2048-pod.yaml
### code starts ###
apiVersion: v1
kind: Pod
metadata:
name: 2048-pod
labels:
app: 2048-ws
spec:
containers:
- name: 2048-container
image: blackicebird/2048
ports:
- containerPort: 80
### code ends ###
# apply the config file to create the pod
kubectl apply -f 2048-pod.yaml
#pod/2048-pod created
# view the newly created pod
kubectl get pods
Setup Load Balancer Service
nano mygame-svc.yaml
### code starts ###
apiVersion: v1
kind: Service
metadata:
name: mygame-svc
spec:
selector:
app: 2048-ws
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
### code ends ###
# apply the config file
kubectl apply -f mygame-svc.yaml
# view details of the modified service
kubectl describe svc mygame-svc
Step 6=> Testing Application.
# Go to EC2 console. get the DNS name of ELB and paste the DNS into address bar of the browser
# It will show the 2048 game. You can play.
Step 7=> Removing all Services and Cleaning Deployments.
Post successfulle deployment ensure to remove all component to avoid charging.
We need to delete components.
-> Delete worker Nodes to EKS Cluster -->eksWorkerNodes
-> Delete Cluter IAM Roles --> eksClusterRole
-> Delete Security Groups --> eksSecurityGroup
-> Delete WorkerNode IAM Role --> eksWorkerNodeRole
-> Delete EKS Cluster -->eksGameCluster
-> Delete LoadBalancer
# Clean up all the resources created in the task
kubectl get pods
kubectl delete -f 2048-pod.yaml
kubectl get services
kubectl delete -f mygame-svc.yaml



















No comments:
Post a Comment