This lab is provided as part of AWS Innovate Modern Applications Edition, click here to explore the full list of hands-on labs.
âšī¸ You will run this lab in your own AWS account. Please follow directions at the end of the lab to remove resources to avoid future costs.
Kubernetes Ingress is an API resource that allows you manage external or internal HTTP(S) access to Kubernetes services running in a cluster. Amazon Elastic Load Balancing Application Load Balancer (ALB) is a popular AWS service that load balances incoming traffic at the application layer (layer 7) across multiple targets. The lab walks through the steps of setting up ALB Ingress controller, deploying sample application (game 2048) and exposing the application publicly via ALB.
How Kubernetes Ingress works with aws-alb-ingress-controller
The following diagram details the AWS components that the aws-alb-ingress-controller creates whenever an Ingress resource is defined by the user. The Ingress resource routes ingress traffic from the Application Load Balancer(ALB) to the Kubernetes cluster.
- Log in your AWS Account
- Click this link and open a new browser tab
- Click Next again to the stack review page, tick I acknowledge that AWS CloudFormation might create IAM resources box and click Create stack.
- Wait for a few minutes for stack creation to complete.
- Select the stack and note down the outputs (Cloud9EnvironmentId & InstanceProfile) on outputs tab for next step.
- Launch AWS EC2 Console.
- Use stack output value of Cloud9EnvironmentId as filter to find the Cloud9 instance.
- Right click the instance, Security -> Modify IAM Role.
- Choose the profile name matches to the InstanceProfile value from the stack output, and click Apply.
- Launch AWS Cloud9 Console
- Locate the Cloud9 environment created for this lab and click "Open IDE". The environment title should start with EKSCloud9.
- At top menu of Cloud9 IDE, click AWS Cloud9 and choose Preferences.
- At left menu AWS SETTINGS, click Credentials.
- Disable AWS managed temporary credentials:
Run commands below on Cloud9 Terminal to clone this lab repository and bootstrap the lab:
git clone https://github.com/phonghuule/eks-2048-game.git
cd eks-2048-game/setup
./bootstrap.sh
The bootstrap.sh script will:
-
Upgrade AWS CLI to latest version.
-
Install kubectl, eksctl.
-
Create an EKS cluster with eksctl.
-
Set up IAM roles for service accounts for ALB Ingress Controller.
Note: If the script is stuck at creating SSH Key Pair, please hit enter, the script will continue
In Cloud 9 environment, maximize the Terminal, and load the profile with this command:
source ~/.bash_profile
Create a Kubernetes service account named alb-ingress-controller in the kube-system namespace, a cluster role, and a cluster role binding for the ALB Ingress Controller to use with the following command.
sudo chmod +x /home/ec2-user/bin/kubectl
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.4/docs/examples/rbac-role.yaml
ALB Ingress Controller needs to know the EKS cluster name. Run the command below to download, update the deployment manifest and deploy the ALB Ingress Controller .
curl -sS "https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.4/docs/examples/alb-ingress-controller.yaml" \
| sed "s/# - --cluster-name=devCluster/- --cluster-name=eks-alb-2048game/g" \
| kubectl apply -f -
Confirm that the ALB Ingress Controller is running with the following command.
kubectl get pods -n kube-system
Expected output:
NAME READY STATUS RESTARTS AGE
alb-ingress-controller-55b5bbcb5b-bc8q9 1/1 Running 0 56s
Create a namespace for 2048 game.
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.4/docs/examples/2048/2048-namespace.yaml
Verify the namespace has been created:
kubectl get ns
Expected output:
NAME STATUS AGE
2048-game Active 42h
default Active 42h
kube-node-lease Active 42h
kube-public Active 42h
kube-system Active 42h
Create a deployment to run 2048 game application pods.
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.4/docs/examples/2048/2048-deployment.yaml
Verify the deployment has been created:
kubectl get deployment -n 2048-game
Expected output:
NAME READY UP-TO-DATE AVAILABLE AGE
2048-deployment 5/5 5 5 42h
Create a service to abstract 2048 game application pods.
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.4/docs/examples/2048/2048-service.yaml
Verify the service has been created:
kubectl get service -n 2048-game
Expected output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service-2048 NodePort 10.100.49.101 <none> 80:32667/TCP 42h
Deploy ALB Ingress resource to expose 2048 Game via AWS Application Load Balancer.
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.4/docs/examples/2048/2048-ingress.yaml
After a few minutes, verify that the Ingress resource was created with the following command.
kubectl get ingress/2048-ingress -n 2048-game
Expected output:
NAME HOSTS ADDRESS PORTS AGE
2048-ingress * 7dfe79d3-2048game-2048ingr-6fa0-35333457.ap-southeast-2.elb.amazonaws.com 80 41h
To debug, run the following command to view the Ingress controller log:
kubectl logs -n kube-system deployment.apps/alb-ingress-controller
Navigate to AWS Console Load Balancer page to see the Load Balancer created by ALB Ingress Controller according to the Ingress resource. Wait for Load Balancer to be active before heading to next step.
Open a browser and navigate to the ALB endpoint (shown in ADDRESS field from the previous command kubectl get ingress/2048-ingress -n 2048-game
output or from AWS Load Balancer Console) to see the 2048 game application.
Run cleanup.sh from Cloud 9 Terminal to delete EKS cluster and its resources. Cleanup script will:
- Delete all the resources installed in previous steps.
- Delete the EKS cluster created via bootstrap script.
./cleanup.sh
Double check the EKS Cluster stack created by eksctl was deleted:
- Launch AWS CloudFormation Console
- Check if the stack eksctl-eks-alb-2048game-cluster still exists.
- If exists, click this stack, in the stack details pane, choose Delete.
- Select Delete stack when prompted.
Delete the Cloud 9 CloudFormation stack named EKS-ALB-2048-Game from AWS Console:
- Launch AWS CloudFormation Console
- Select stack EKS-ALB-2048-Game.
- In the stack details pane, choose Delete.
- Select Delete stack when prompted.
Please help us to provide your feedback here. Participants who complete the surveys from AWS Innovate Online Conference - Modern Applications Edition will receive a gift code for USD25 in AWS credits. AWS credits will be sent via email by 30 November, 2021.