Kubernetes Labs · Lab 6 of 9

Amazon EKS: A Managed Cluster with an Application Load Balancer

Create an EKS cluster with eksctl (VPC, managed node group, Pod Identity), install the AWS Load Balancer Controller, and expose the app through an internet-facing Application Load Balancer that sends traffic straight to pod IPs.

Environment
AWS
Level
Intermediate
Time
About 60 min
Cost
≈ $0.30 per hour while it runs

You will build

A two-node EKS cluster in private subnets, the AWS Load Balancer Controller running with an IAM role through Pod Identity, and curl reaching your pods through an ALB.

Before you start

Members can save this page, take notes and track progress. See membership · Sign in

On Amazon EKS, AWS runs the control plane (API servers and etcd, replicated across availability zones) and you pay for it by the hour. You bring the nodes: here a managed node group of EC2 instances that EKS creates, patches and replaces for you. Everything else you learned on kind is the same Kubernetes.

UsersHTTPSAWS Region eu-west-1EKS control planemanaged by AWS (API, etcd)ECRcontainer imagesIAM + Pod Identityroles for podsVPC (3 Availability Zones)Public subnetsApplication Load Balancerfrom the IngressNAT gatewayoutbound internet for nodesPrivate subnetsManaged node groupt3.medium EC2, 2–4 nodesPodsweb × 2, LB controller, CoreDNSto pod IPsruns
EKS: AWS runs the control plane, your node group runs in private subnets, an ALB brings traffic in

The components

  • VPC with public and private subnets in three availability zones, created by eksctl. Public subnets hold load balancers and the NAT gateway; private subnets hold the nodes, which reach the internet only through NAT.
  • EKS control plane: managed by AWS; kubectl talks to its HTTPS endpoint, authenticated with your IAM identity.
  • Managed node group: EC2 instances in an Auto Scaling group, running kubelet and containerd.
  • Add-ons: vpc-cni gives pods real VPC IP addresses (so a load balancer can target pods directly), plus coredns, kube-proxy and the eks-pod-identity-agent.
  • EKS Pod Identity maps a Kubernetes service account to an IAM role, so a pod gets AWS credentials without access keys.
  • AWS Load Balancer Controller: watches Ingress objects and creates ALBs and target groups for them.
  • ECR: AWS's container registry. This lab uses a public image for simplicity; production pulls from ECR.

Cost: the control plane costs $0.10 per hour; two t3.medium nodes, the NAT gateway and the ALB bring the total to roughly $0.30 per hour, plus a little data transfer. Run the clean-up as soon as you are done.

About the outputs: the manifests in this lab were validated against a real Kubernetes 1.37 API server (kubectl apply --dry-run=server), and the dry-run output shown is real. The cloud commands were not run for you: they need your own account, and their output contains account IDs, names and addresses that differ for everyone. Those steps tell you what to check instead.

Project structure

eks/
├── cluster.yaml   # eksctl: VPC, add-ons, Pod Identity for the LB controller, managed node group
└── app.yaml       # namespace shop, Deployment, Service, Ingress (class alb)

Download starter filesDownload finished project

Steps

  1. 1Check your tools and identity

    Run
    aws --version
    eksctl version
    kubectl version --client
    helm version --short
    aws sts get-caller-identity
    
    Check:

    Every command prints a version, and get-caller-identity shows the account you mean to use.

  2. 2Describe the cluster

    One file creates everything. privateNetworking: true keeps nodes off the internet. The Pod Identity association creates the aws-load-balancer-controller service account and an IAM role with exactly the permissions that controller needs.

    cluster.yaml
    # eksctl creates the VPC (public + private subnets in 3 AZs), the control plane, a managed node group
    # and the IAM wiring for the AWS Load Balancer Controller.
    apiVersion: eksctl.io/v1alpha5
    kind: ClusterConfig
    metadata:
      name: shop-eks
      region: eu-west-1
    vpc:
      nat:
        gateway: Single          # one NAT gateway for the lab; HighlyAvailable (one per AZ) in production
    addons:
      - name: vpc-cni
      - name: coredns
      - name: kube-proxy
      - name: eks-pod-identity-agent
    iam:
      podIdentityAssociations:
        - namespace: kube-system
          serviceAccountName: aws-load-balancer-controller
          createServiceAccount: true
          wellKnownPolicies:
            awsLoadBalancerController: true
    managedNodeGroups:
      - name: general
        instanceType: t3.medium
        minSize: 2
        desiredCapacity: 2
        maxSize: 4
        privateNetworking: true   # nodes get no public IPs
        volumeSize: 20
    
  3. 3Create the cluster

    This takes 15–20 minutes. eksctl creates CloudFormation stacks for the VPC, the control plane, the node group and the IAM roles.

    Run
    eksctl create cluster -f cluster.yaml
    
    Check:

    The last lines say EKS cluster "shop-eks" in "eu-west-1" region is ready, and eksctl has added the cluster to your kubeconfig.

    Hint

    If creation fails, read the CloudFormation stack events in the console; a common cause is a service quota (VPCs, Elastic IPs) in a busy account.

  4. 4Look at the nodes

    Run
    kubectl get nodes -o wide
    kubectl get pods -n kube-system
    
    Check:

    Two Ready nodes with private INTERNAL-IPs and no EXTERNAL-IP; kube-system has aws-node (VPC CNI), coredns, kube-proxy and eks-pod-identity-agent pods. There are no control-plane pods: AWS runs those.

  5. 5Install the AWS Load Balancer Controller

    The controller is installed with Helm into kube-system, using the service account eksctl already created (so it gets its IAM role through Pod Identity).

    Run
    helm repo add eks https://aws.github.io/eks-charts
    helm repo update
    VPC_ID=$(aws eks describe-cluster --name shop-eks --region eu-west-1 --query cluster.resourcesVpcConfig.vpcId --output text)
    helm install aws-load-balancer-controller eks/aws-load-balancer-controller -n kube-system \
      --set clusterName=shop-eks --set region=eu-west-1 --set vpcId=$VPC_ID \
      --set serviceAccount.create=false --set serviceAccount.name=aws-load-balancer-controller
    kubectl -n kube-system rollout status deployment/aws-load-balancer-controller
    kubectl get ingressclass
    
    Check:

    The rollout finishes and kubectl get ingressclass lists alb.

  6. 6The app and its Ingress

    The Deployment and Service are the same as on kind; topologySpreadConstraints spread the pods over zones. The Ingress with class alb is picked up by the controller, which creates an internet-facing ALB. target-type: ip registers pod IPs directly in the target group, so traffic skips the node ports.

    Ingress webingressClassName: albAWS Load BalancerController (in cluster)Pod IdentityIAM role for the SAALB + target grouptargets = pod IPsAWS APIselasticloadbalancingwatchesgets credentialscreates
    How an Ingress becomes an ALB on EKS
    app.yaml
    apiVersion: v1
    kind: Namespace
    metadata:
      name: shop
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: web
      namespace: shop
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: web
      template:
        metadata:
          labels:
            app: web
        spec:
          topologySpreadConstraints:
            - maxSkew: 1
              topologyKey: topology.kubernetes.io/zone
              whenUnsatisfiable: ScheduleAnyway
              labelSelector:
                matchLabels:
                  app: web
          containers:
            - name: whoami
              image: traefik/whoami:v1.11.0
              ports:
                - name: http
                  containerPort: 80
              readinessProbe:
                httpGet:
                  path: /health
                  port: http
              resources:
                requests:
                  cpu: 50m
                  memory: 32Mi
                limits:
                  memory: 64Mi
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: web
      namespace: shop
    spec:
      selector:
        app: web
      ports:
        - name: http
          port: 80
          targetPort: http
    ---
    # The AWS Load Balancer Controller turns this into an internet-facing Application Load Balancer
    # that sends traffic straight to pod IPs (target-type: ip).
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: web
      namespace: shop
      annotations:
        alb.ingress.kubernetes.io/scheme: internet-facing
        alb.ingress.kubernetes.io/target-type: ip
        alb.ingress.kubernetes.io/healthcheck-path: /health
    spec:
      ingressClassName: alb
      rules:
        - http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: web
                    port:
                      name: http
    
  7. 7Validate before applying

    A client-side dry run catches typos and schema errors without changing anything.

    Run
    kubectl apply --dry-run=client -f app.yaml
    

    Expected output

    namespace/shop created (dry run)
    deployment.apps/web created (dry run)
    service/web created (dry run)
    ingress.networking.k8s.io/web created (dry run)
  8. 8Apply and wait for the load balancer

    Run
    kubectl apply -f app.yaml
    kubectl -n shop get ingress web --watch
    
    Check:

    After 1–3 minutes ADDRESS shows a name like k8s-shop-web-….eu-west-1.elb.amazonaws.com. Press Ctrl+C.

    Hint

    No address after five minutes? kubectl -n kube-system logs deployment/aws-load-balancer-controller shows why (usually IAM or subnet tags).

  9. 9Call the app through the ALB

    Run
    ALB=$(kubectl -n shop get ingress web -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
    for i in 1 2 3 4; do curl -s http://$ALB/ | grep Hostname; done
    kubectl get targetgroupbindings -n shop
    
    Check:

    Both web-… pod names appear (DNS can take a minute), and a TargetGroupBinding links the Service to the ALB's target group.

Clean up

Delete in this order, or the load balancer and its security groups are left behind and keep costing money:

kubectl delete -f app.yaml        # the controller deletes the ALB
# wait until no load balancer named k8s-shop-… is left:
aws elbv2 describe-load-balancers --region eu-west-1 --query "LoadBalancers[].LoadBalancerName"
eksctl delete cluster -f cluster.yaml --wait

Then check that nothing is left: aws ec2 describe-nat-gateways --region eu-west-1 --filter Name=state,Values=available shows no NAT gateway from the lab, and the CloudFormation console shows no eksctl-shop-eks-… stacks.

In production

eksctl is great for learning; production clusters are built from code that is reviewed and versioned like the apps.

What changes

In this lab In production
eksctl create cluster from a laptop Terraform (or CDK) in a pipeline, one state per environment, reviewed plans
Public API endpoint open to the internet Private endpoint, or public restricted to office/VPN CIDRs; access through IAM Identity Center roles mapped with EKS access entries
One NAT gateway One NAT gateway per AZ (or VPC endpoints for ECR, S3, STS) so one AZ failure doesn't cut egress
A fixed managed node group Karpenter or EKS Auto Mode adding right-sized nodes on demand, Spot for tolerant workloads
HTTP on the ALB HTTPS with an ACM certificate, HTTP redirect, AWS WAF, access logs to S3
Docker Hub image ECR with scanning and immutable tags, pulled by digest
Kubernetes version left as created Planned upgrades every few months, add-ons and node AMIs updated with them

Production checklist

  • Cluster, node groups, add-ons and IAM defined in Terraform/CDK, applied by CI
  • API endpoint private or IP-restricted; human access via SSO roles, never long-lived keys
  • Nodes in private subnets across three AZs; NAT per AZ or VPC endpoints
  • Pod Identity (or IRSA) for every pod that calls AWS; no access keys in Secrets
  • Load balancers terminate TLS (ACM), with WAF and access logging
  • Control-plane logs, Container Insights or Prometheus metrics, and alerts in place
  • Budget alerts on the account; a tested runbook for upgrades and node replacement

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake