Amazon Elastic Kubernetes Service (EKS) PROJECT-Game-2048🎮

Table of contents

❄️Introduction

In this project we are going to deploy this game 2048 app on Amazon Elastic Kubernetes Service (EKS) using AWS Fargate and we are also going to use ingress for this project and for this ingress resource we are gonna to create ingress controller for this project and ingress controller will create a Loadbalancer for us, using this Loadbalancer we will expose this app to access in the real world .So let's get started

📌Prereqisites

Before performing this project you need to install these command on you terminal :

kubectl

A command line tool for working with Kubernetes clusters. For more information, see Installing or updating kubectl.

LINK : https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html

eksctl

A command line tool for working with EKS clusters that automates many individual tasks. For more information, see Installing or updating.

LINK : https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html

AWS CLI

A command line tool for working with AWS services, including Amazon EKS. For more information, see Installing, updating, and uninstalling the AWS CLI in the AWS Command Line Interface User Guide. After installing the AWS CLI, we recommend that you also configure it. For more information, see Quick configuration with aws configure in the AWS Command Line Interface User Guide.

LINK : https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html

Once you installed these commands on your Terminal then do
aws configure

You can get your aws access and secret access key

You can get you AWS access and secret access key , just sign in you AWS Account and go to Security credentialsAccess keys

Why aws configure ??!!

The aws configure command helps you set up your AWS CLI by entering your credentials, choosing a default region, and picking how you want your AWS service results displayed.

📌 Setting up Your EKS cluster

You can create you cluster through AWS Console but here we are creating the cluster through CLI using fargate

eksctl create cluster --name demo-cluster-app --region ap-south-1 --fargate

Here, --region will be your region .

It will take some time to create ............

Once it's done then update you kube-config for this cluster

aws  aws eks update-kubeconfig --name demo-cluster-app  --region ap-south-1

Create the Fargate Profile

Using Fargate ,Profile this ensures that which pod will be run on fargate and which not. By using namespace and labels, the pod with certain label and namespace will only be deploy on the fargate

eksctl create fargateprofile \
    --cluster demo-cluster-app \
    --region ap-south-1 \
    --name alb-sample-app \
    --namespace game-2048

📌Create Manifest File -

full.yaml : This yaml file contain everthing that is required for the deployment on eks .It has namespace creation yaml file ,deployment service and ingress everthing is present inside in the single file

---
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: public.ecr.aws/l6m2t8p7/docker-2048:latest
        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/v1
kind: Ingress
metadata:
  namespace: game-2048
  name: ingress-2048
  annotations:
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
spec:
  ingressClassName: alb
  rules:
    - http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: service-2048
              port:
                number: 80

📌K8s Command

Check the number of nodes available.

kubectl get nodes

Now create the file full.yaml file and apply this file.

vim full.yaml
kubectl apply -f full.yaml

Now check the deployment,pods,service and ingress in this particular namespace game-2048.

!! IMPORTANT !!

Okay,Everything is running fine but you see in the ingress there is something like Address is there but there is nothing in the address no ip address ,no DNS name .So basically, this is saying that creation of ingress is not useful until you apply ingress-controller for this so when you apply ingress controller.So what basically ingress controller is doing is it is watching for the ingress resource and configuring the ingress resource and creating the load balancer according to that configuration, then in the Address section you will see FQDN(Fully Qualify Domain Name) will come up using this you can access your app from outside the world .So lets go for creating ingress-controller or alb-ingress-controller (because we are using the alb-controller for this project).

📌Installation of ALB-CONTROLLER using helm-cahrt

Before creating the alb-controller you have to do these steps so your alb-controller which is running as pod in kube-system namespace in kubernetes that can be talk to aws services to create alb-load-balancer.

✔️Configure-oidc-connector

check if there is an IAM OIDC provider configured already

eksctl utils associate-iam-oidc-provider --cluster <your-cluster-name> --approve

✔️setup alb add on

Download IAM policy

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

Create IAM Policy

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

Create IAM Role

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

✔️Deploy ALB controller

Add helm repo

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

Update the repo

helm repo update eks

Install

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>

you can get your vpc-id from AWS console in EKS, just go there and simply click on your eks cluster what you have created just now ,click on the cluster name and you will see the networking section from there you will get .

Verify that the deployments are running.

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

Now Do

kubectl get ingress -n game-2048

You will see in Address section there is FQDN has come up after creating the alb-ingress-controller .Now copy this FQDN (you can copy this from your terminal and also from your aws console in load balancer service that you have just created) and paste to your favourite browser.

Clap for yourself we have finally deploy this application on AWS-EKS:

Now enjoy your application:

📌DELETING UP YOUR EKS CLUSTER

  • It's easy to destroy clusters through the terminal if you are trying to destroy it.

      eksctl delete cluster --name <your-cluster-name>
    
0
Subscribe to my newsletter

Read articles from Chauhan Shreyash directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chauhan Shreyash
Chauhan Shreyash