News



Insights

Learn Kubernetes Fast: How to Use Fargate to Launch EKS and Create Your Own 2048 Game

eksctl is a CLI tool provided by AWS to manage EKS. It allows users to create EKS clusters with a single command.

If you haven't installed it yet, refer to this guide:
https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html


Step 1. Create an EKS Cluster

EKS currently supports deployment using Fargate and EC2 instances.

Create an EKS cluster with Fargate using eksctl:

$ eksctl create cluster --name <Cluster Name> --region region-code --fargate

Step 2. Verify kubectl

After creating the cluster, kubectl config will be automatically updated. Let's verify if kubectl is working properly:

$ kubectl get no
NAME                                                         STATUS   ROLES    AGE   VERSION
fargate-ip-192-168-106-11.ap-northeast-1.compute.internal    Ready    <none>   98s   v1.21.2-eks-06eac09
fargate-ip-192-168-147-176.ap-northeast-1.compute.internal   Ready    <none>   94s   v1.21.2-eks-06eac09

Step 3. Configure AWS IAM

Download the policy JSON file using curl:

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

Create the IAM policy:

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

To list all available policies:
aws iam list-policies

Associate the IAM OIDC provider:

$ eksctl utils associate-iam-oidc-provider --cluster <Cluster Name> --approve

Create an IAM service account:

  • Replace "111111111" in the example with your account ID.
$ eksctl create iamserviceaccount \
  --cluster=<Cluster Name> \
  --namespace=kube-system \
  --name=aws-load-balancer-controller \
  --attach-policy-arn=arn:aws:iam::111111111:policy/AWSLoadBalancerControllerIAMPolicy \
  --override-existing-serviceaccounts \
  --approve

Step 4. Install Load Balancer Controller

Install the load balancer controller using Helm:

If you haven't installed Helm, refer to this link:
https://helm.sh/docs/intro/install/

$ helm repo add eks https://aws.github.io/eks-charts
$ helm repo update
$ helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
  -n kube-system \
  --set clusterName=<Cluster Name> \
  --set serviceAccount.create=false \
  --set serviceAccount.name=aws-load-balancer-controller \
  --set region=<region-code> \
  --set vpcId=vpc-ooxxoxox

The load balancer controller Pods will initially appear in a Pending state in the kube-system namespace.

$ kubectl get po -n kube-system
NAME                                            READY   STATUS    RESTARTS   AGE
aws-load-balancer-controller-546c68c975-cnjss   0/1     Pending   0          13s
aws-load-balancer-controller-546c68c975-dktj9   0/1     Pending   0          13s
coredns-9f6f89c76-njp57                         1/1     Running   0          30m
coredns-9f6f89c76-qnldm                         1/1     Running   0          30m

Within about a minute, they will transition to Running:

$ kubectl get po -n kube-system
NAME                                            READY   STATUS    RESTARTS   AGE
aws-load-balancer-controller-546c68c975-cnjss   1/1     Running   0          69s
aws-load-balancer-controller-546c68c975-dktj9   1/1     Running   0          69s
coredns-9f6f89c76-njp57                         1/1     Running   0          31m
coredns-9f6f89c76-qnldm                         1/1     Running   0          31m

To deploy Pods on Fargate, you need to define a Fargate profile. Only Pods matching the specified criteria (e.g., Labels, Namespaces) will be launched on Fargate. Here's an example defining Pods under the "game-2048" namespace:

$ eksctl create fargateprofile \
    --cluster <Cluster Name> \
    --region region-code \
    --name alb-sample-app \
    --namespace game-2048

For more details on Fargate profiles, check the AWS documentation: https://docs.aws.amazon.com/eks/latest/userguide/fargate-profile.html

Step 5. Test ALB

Deploy the 2048 sample application:

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

After a while, you will see the ingress has been assigned an IP address:

$ kubectl get ing -n game-2048
NAME           CLASS   HOSTS   ADDRESS                                                                        PORTS   AGE
ingress-2048   alb     *       k8s-game2048-ingress2-44de7d92ff-1241231425.ap-northeast-1.elb.amazonaws.com   80      51s

Copy the "ADDRESS" to your browser, and you can start playing 2048!

Contact
Contact