AWS from zero · Part 5: Containers and infrastructure as code · Lesson 29 of 38 · about 70 minutes

EKS: Kubernetes on AWS, built with Terraform

An EKS cluster for Juniper & Rye's menu, built from Terraform: Kubernetes 1.37 locked to standard support, two small Arm nodes, an API only your IP can reach, and the menu behind a load balancer Kubernetes made itself. 18 resources in about 10 minutes, 30 copies asked for and only 16 fitting because each node holds 11 pods, and a destroy that only works once Kubernetes has cleaned up after itself.

By the end you'll know

  • What EKS runs for you, and what you still run: the control plane, nodes, add-ons and your apps
  • Why every Kubernetes version on EKS has an end date, and how to avoid paying five times as much after it
  • How kubectl signs in to EKS, and how EKS decides who may use it
  • Why a small node can only hold a handful of pods, and what the scheduler says when it's full
  • Why some AWS resources are made by Kubernetes, not Terraform, and how that changes the order you tear down

Before you start

  • You need: the juniper-rye profile, signed in, Lesson 20's virtual environment, Docker running, Terraform 1.11 or newer, kubectl, and the AWS CLI. On a Mac: brew install kubectl awscli.
  • This lesson builds on three others. Lesson 28 covers the state bucket and the plan-then-apply habit used here. Lesson 27 ran the same menu on ECS, and compares ECS, EKS and your own machine. The Kubernetes track covers Deployments, Services and requests and limits; this lesson is about running them on AWS.
  • The lab: lesson-29 in the practice folder: lab.py and a terraform folder. Everything is named jr-lesson29-* and tagged lesson=29.
  • kubectl uses a kubeconfig of the lab's own, ./kubeconfig in the lesson folder, through python lab.py k. Your own ~/.kube/config, and any other clusters in it, are never touched.
  • Where you run things: your own machine, labeled (Your machine).
  • Every output below is from a real run on November 15, 2026, with Terraform 1.11.3 and the AWS provider 6.73.0. Long outputs are trimmed to the part that matters; each block is a continuous piece of the real output.

An EKS cluster bills by the hour, even when it's idle

The cluster itself is $0.10 an hour before a single node runs, about $73 a month, and on extended support it's $0.50 an hour. With the nodes and the load balancer, this lab is about 18 cents an hour. Build, explore and destroy in one sitting, and run check at the end. The Terraform here locks the cluster to standard support so it can never drift into the expensive kind.

The short version

  • EKS runs Kubernetes' control plane for you; you choose and pay for the nodes, and you deploy the apps.
  • Each Kubernetes version gets about 14 months of standard support, then costs five times as much. Upgrade, or let EKS upgrade for you.
  • kubectl signs in with your AWS identity, and EKS access entries decide what that identity may do.
  • Every pod gets a real address in your VPC, so a node holds only as many pods as it has addresses: 11 on a t4g.small.
  • Kubernetes makes some AWS resources itself, like load balancers. Delete them through Kubernetes before Terraform destroys the network.

What this lesson costs

PartCost, in us-east-2
The EKS cluster, standard support$0.10 an hour
Two t4g.small nodes, Arm$0.0168 an hour each
Their 20 GB disks$0.08 per GB a month: about half a cent an hour together
The Classic Load Balancer Kubernetes makes$0.025 an hour
Four public IPv4 addresses$0.005 an hour each
This lesson, about 90 minutesAbout 27 cents, from credits

What EKS runs, and what you run

A Kubernetes cluster has two halves. The control plane is the brain: the API server kubectl talks to, the database that remembers everything, and the scheduler that decides where pods go. The nodes are the computers that run your pods. On your laptop with kind, both halves are containers on one machine. On EKS, AWS runs the control plane across several zones, patches it and keeps it available; you choose the nodes and everything that runs on them.

EKS is a bakery franchise. Head office, the control plane, takes the orders, keeps the books and decides which kitchen bakes what. You never see head office and you pay it a flat fee every hour it's open, busy or not. The kitchens, the nodes, are yours: you pick how many and how big, and you pay for each one.
PartIsWho runs itIn the lab
Control planeThe API server, its database and the schedulerAWS, outside your VPCKubernetes 1.37, $0.10 an hour
NodesEC2 instances that run podsYou choose; a managed node group launches and replaces themTwo t4g.small, Arm
Add-onsThe cluster's own pods: networking, DNS, traffic rulesAWS publishes them; you choose versionsvpc-cni, kube-proxy, coredns
Your appsDeployments, Services and the restYou, with kubectl or a pipelineThe menu, 2 copies

Versions, and what they cost

Kubernetes releases a new minor version about three times a year, and EKS supports each one for a fixed time. When standard support ends, a cluster still on that version moves to extended support, at a higher price, unless you've said otherwise.

(Your machine)

BASH
cd ~/Apps/aws-practice/lesson-29
source ../lesson-20/.venv/bin/activate
python lab.py fence
OUTPUT
== Tools on your machine
  terraform  1.11.3
  kubectl    v1.33.3
  aws CLI    aws-cli/2.39.7
  docker     linux/arm64 29.9.2
== Kubernetes versions EKS offers today
  1.37  standard support  standard support ends 2027-11-30   <- the default for new clusters
  1.36  standard support  standard support ends 2027-08-01
  1.35  standard support  standard support ends 2027-03-26
  1.34  standard support  standard support ends 2026-12-01
  1.33  extended support  standard support ends 2026-07-28
== What it costs in us-east-2 (from the Price List API)
  EKS cluster, standard support, an hour         $0.1
  EKS cluster, extended support, an hour         $0.5
  t4g.small node (2 vCPU, 2 GiB, Arm), an hour   $0.0168
  gp3 disk, per GB a month                       $0.08
  Classic Load Balancer, an hour                 $0.025
  Public IPv4 address in use, an hour            $0.005
== While it runs: about $0.183 an hour
  the cluster $0.10; 2 nodes $0.0336; their disks $0.0044; the load balancer $0.0250; 4 public IPs $0.020
  building takes about 15 minutes and destroying about 10: a 90-minute sitting is about $0.27
  on extended support the cluster alone would be $0.50 an hour: 5 times as much

A cluster made on 1.34 that day had two weeks of standard support left. After December 1, 2026, it would have cost $0.50 an hour instead of $0.10: about $365 a month instead of $73, for the same cluster doing the same work. That's the most common surprise on an EKS bill.

The Terraform blocks it with one setting:

HCL
  # STANDARD: when this version's standard support ends, EKS upgrades the cluster
  # instead of moving it to extended support, which costs five times as much an hour.
  upgrade_policy {
    support_type = "STANDARD"
  }

With STANDARD, a cluster that reaches the end of standard support is upgraded by EKS to the next version rather than billed for extended support. That's the right default for anything you can upgrade without warning. For production, the better habit is upgrading yourself, a version at a time, a few times a year, before EKS has to.

The kubectl here was 1.33, and the cluster 1.37. kubectl is supported only one minor version either side of the cluster; this run worked, but a newer kubectl avoids odd errors: brew upgrade kubectl.

Build it

The state bucket, the image and the plan-then-apply habit are Lesson 28's, unchanged:

BASH
python lab.py state
python lab.py image
python lab.py tf init -backend-config=backend.hcl
python lab.py tf validate
python lab.py tf plan -out=tfplan
OUTPUT
== A bucket for Terraform's state: jr-lesson29-state-f2829cd3
== jr-lesson29-state-f2829cd3: versioned, encrypted, private; backend.hcl written
== my-ip.auto.tfvars: allowed_cidr = "your IP/32": the only address that can reach the cluster's API
== version.auto.tfvars: kubernetes_version = "1.37", EKS's default today; standard support to 2027-11-30
== The image repository, made outside Terraform
  pushed jr-lesson29-menu:v1, built for Arm like the nodes

The state step asked EKS for today's default version and wrote it into a variables file, so the version is chosen once, on purpose, and recorded, not left to whatever EKS picks. The plan, for the cluster itself:

OUTPUT
  # aws_eks_cluster.this will be created
  + resource "aws_eks_cluster" "this" {
      + arn                           = (known after apply)
      + bootstrap_self_managed_addons = false
      + certificate_authority         = (known after apply)
      + cluster_id                    = (known after apply)
      + created_at                    = (known after apply)
      + deletion_protection           = (known after apply)
      + endpoint                      = (known after apply)
      + id                            = (known after apply)
      + identity                      = (known after apply)
      + name                          = "jr-lesson29"
      + platform_version              = (known after apply)
      + region                        = "us-east-2"
      + role_arn                      = (known after apply)
      + status                        = (known after apply)
      + tags_all                      = {
          + "lesson"     = "29"
          + "managed_by" = "terraform"
          + "owner"      = "juniper-rye"
        }
      + version                       = "1.37"

      + access_config {
          + authentication_mode                         = "API"
          + bootstrap_cluster_creator_admin_permissions = true
        }

      + compute_config (known after apply)

      + control_plane_scaling_config (known after apply)

      + kube_api_server_config (known after apply)

      + kube_controller_manager_config (known after apply)

      + kube_scheduler_config (known after apply)

      + kubernetes_network_config (known after apply)

      + storage_config (known after apply)

      + upgrade_policy {
          + support_type = "STANDARD"
        }

      + vpc_config {
          + cluster_security_group_id = (known after apply)
          + control_plane_egress_mode = (known after apply)
          + endpoint_private_access   = true
          + endpoint_public_access    = true
          + public_access_cidrs       = [
              + "your IP/32",
            ]
          + subnet_ids                = (known after apply)
          + vpc_id                    = (known after apply)
        }
    }
OUTPUT
Plan: 18 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + cluster_name       = "jr-lesson29"
  + kubernetes_version = "1.37"
  + node_count         = 2
  + support_type       = "STANDARD"
SettingWhy
public_access_cidrs: your IP/32The Kubernetes API answers only your address. Without it, anyone on the internet can reach the login page of your cluster.
endpoint_private_accessNodes reach the API from inside the VPC, so locking the public side to your IP doesn't lock them out
authentication_mode = "API"Who may use kubectl is managed with EKS access entries, through AWS, instead of a file inside the cluster
bootstrap_self_managed_addons = falseThe cluster's own pods come from managed add-ons Terraform lists, with versions EKS keeps track of
upgrade_policy: STANDARDNever billed for extended support
BASH
python lab.py tf apply tfplan
OUTPUT
aws_eks_cluster.this: Creation complete after 8m3s [id=jr-lesson29]
aws_eks_addon.kube_proxy: Creating...
aws_eks_addon.vpc_cni: Creating...
aws_eks_addon.vpc_cni: Creation complete after 7s [id=jr-lesson29:vpc-cni]
aws_eks_addon.kube_proxy: Creation complete after 7s [id=jr-lesson29:kube-proxy]
aws_eks_node_group.default: Creating...
aws_eks_node_group.default: Still creating... [10s elapsed]
aws_eks_node_group.default: Still creating... [20s elapsed]
aws_eks_node_group.default: Still creating... [30s elapsed]
aws_eks_node_group.default: Still creating... [40s elapsed]
aws_eks_node_group.default: Still creating... [50s elapsed]
aws_eks_node_group.default: Still creating... [1m0s elapsed]
aws_eks_node_group.default: Still creating... [1m10s elapsed]
aws_eks_node_group.default: Still creating... [1m21s elapsed]
aws_eks_node_group.default: Still creating... [1m31s elapsed]
aws_eks_node_group.default: Still creating... [1m41s elapsed]
aws_eks_node_group.default: Still creating... [1m51s elapsed]
aws_eks_node_group.default: Creation complete after 1m58s [id=jr-lesson29:jr-lesson29-nodes]
aws_eks_addon.coredns: Creating...
aws_eks_addon.coredns: Still creating... [10s elapsed]
aws_eks_addon.coredns: Creation complete after 14s [id=jr-lesson29:coredns]

Apply complete! Resources: 18 added, 0 changed, 0 destroyed.

Outputs:

cluster_name = "jr-lesson29"
kubernetes_version = "1.37"
node_count = 2
support_type = "STANDARD"

The control plane took 8 minutes; everything else, about 2. The order is the interesting part, and it comes from depends_on in the code. A node isn't Ready until it has pod networking, so the vpc-cni and kube-proxy add-ons go first, then the nodes. CoreDNS runs as ordinary pods, so it can only start once there are nodes for it to run on, and goes last. Get that order wrong and the apply sits waiting on a node that never becomes Ready.

Connect with kubectl

The EKS cluster the lab buildsYour machine runs kubectl and Terraform, and reaches the EKS control plane, which AWS runs outside your VPC, from your IP only. Inside a VPC with two public subnets in two zones, there is one t4g.small node in each zone, each holding up to 11 pods: the menu, plus aws-node, kube-proxy and CoreDNS. The nodes reach the control plane through its private endpoint. A Classic Load Balancer, made by Kubernetes rather than Terraform, sends your requests to the nodes.Your machinekubectl, Terraformyour IP onlyEKS control plane, run by AWSAPI server, cluster database, schedulerVPC 10.29.0.0/16: two public subnetsus-east-2aus-east-2bnodes use the private APINode: t4g.smallup to 11 pods: the menu,aws-node, kube-proxy,CoreDNSNode: t4g.smallup to 11 pods: the menu,aws-node, kube-proxy,CoreDNSLoad balancermade by Kubernetes,your IP onlyTerraform made everything here except the load balancer, which Kubernetes made and must delete.
The control plane lives in AWS's own account; the nodes and their pods live in your VPC, with the load balancer in front of them.
BASH
python lab.py kubeconfig
python lab.py k get nodes -o wide
python lab.py k -n kube-system get pods
OUTPUT
  Added new context jr-lesson29 to ./kubeconfig
== kubectl in this lab uses ./kubeconfig only; your ~/.kube/config is untouched
== How kubectl signs in: it runs aws eks get-token with the juniper-rye profile for each call
NAME                                        STATUS   ROLES    AGE   VERSION               INTERNAL-IP   EXTERNAL-IP     OS-IMAGE                        KERNEL-VERSION                             CONTAINER-RUNTIME
ip-10-29-0-18.us-east-2.compute.internal    Ready    <none>   67s   v1.37.1-eks-9adbfea   10.29.0.18    3.138.178.186   Amazon Linux 2023.12.20261112   6.18.62-127.179.amzn2023.aarch64 (arm64)   containerd://2.3.7+unknown
ip-10-29-1-223.us-east-2.compute.internal   Ready    <none>   67s   v1.37.1-eks-9adbfea   10.29.1.223   3.135.231.78    Amazon Linux 2023.12.20261112   6.18.62-127.179.amzn2023.aarch64 (arm64)   containerd://2.3.7+unknown
NAME                       READY   STATUS    RESTARTS   AGE
aws-node-bc5v9             2/2     Running   0          68s
aws-node-zd5sl             2/2     Running   0          68s
coredns-598bf5b859-bftfx   1/1     Running   0          13s
coredns-598bf5b859-pnlrf   1/1     Running   0          13s
kube-proxy-cn2cl           1/1     Running   0          68s
kube-proxy-ctqkv           1/1     Running   0          68s

kubectl has no password for EKS. aws eks update-kubeconfig wrote a kubeconfig that tells kubectl to run aws eks get-token before each call: the AWS CLI signs a short-lived token with your juniper-rye sign-in, and EKS checks it. When your AWS sign-in expires, so does kubectl's.

Two nodes, one per zone, each named after its private address in the VPC. In kube-system, the add-ons: aws-node is the VPC CNI, one per node, which gives pods their network addresses; kube-proxy, one per node, routes Service traffic; CoreDNS, two copies, answers DNS for the cluster.

Who may use kubectl

BASH
python lab.py access
OUTPUT
== Who may use kubectl on jr-lesson29 (EKS access entries)
  role/aws-service-role/eks.amazonaws.com/AWSServiceRoleForAmazonEKS
      type STANDARD; Kubernetes groups eks:managed; policies AmazonEKSClusterInsightsPolicy, AmazonEKSEventPolicy, AmazonEKSPodIdentityPolicy
  role/jr-lesson29-node-role
      type EC2_LINUX; Kubernetes groups system:nodes; policies none
  role/managed/AccountFullAccessRole
      type STANDARD; Kubernetes groups none; policies AmazonEKSClusterAdminPolicy

An access entry ties an AWS identity to what it may do inside Kubernetes. Three are here: EKS's own service role, so AWS can manage the cluster; the node role, so nodes can join as system:nodes; and the role you signed in with, made cluster admin because you created the cluster, and its access_config says to make the creator an admin.

EntryIsMay do
AWSServiceRoleForAmazonEKSEKS itselfRead events and insights, and run Pod Identity
jr-lesson29-node-roleEvery nodeJoin the cluster and run its pods
Your sign-in roleWhoever ran applyEverything: AmazonEKSClusterAdminPolicy

Older clusters kept this in a ConfigMap called aws-auth, inside the cluster; one bad edit there could lock everyone out. Access entries live in AWS, are managed with the AWS API or Terraform, and can't be broken from inside Kubernetes. For a teammate, you'd add an access entry for their role, with a narrower policy such as AmazonEKSViewPolicy.

Deploy the menu

The cluster is the platform; what runs on it is deployed with kubectl, the way a pipeline would. The deploy step writes menu.yaml, a Deployment of 2 copies spread across zones and a Service of type LoadBalancer open to your IP only, and applies it:

BASH
python lab.py deploy
python lab.py call
OUTPUT
== menu.yaml: a Deployment of 2, spread across zones, and a Service of type LoadBalancer for your IP/32
deployment.apps/menu created
service/menu created
Waiting for deployment "menu" rollout to finish: 0 of 2 updated replicas are available...
Waiting for deployment "menu" rollout to finish: 1 of 2 updated replicas are available...
deployment "menu" successfully rolled out
  rolled out in 4 seconds
== Waiting for AWS to make the load balancer Kubernetes asked for
  a118788d9d3204d479e757f9f9a6be7a-2135254127.us-east-2.elb.amazonaws.com after 1 seconds
NAME                    READY   STATUS    RESTARTS   AGE   IP            NODE                                        NOMINATED NODE   READINESS GATES
menu-785cf46557-qbvcg   1/1     Running   0          5s    10.29.1.111   ip-10-29-1-223.us-east-2.compute.internal   <none>           <none>
menu-785cf46557-r6n9m   1/1     Running   0          5s    10.29.0.19    ip-10-29-0-18.us-east-2.compute.internal    <none>           <none>
== GET http://a118788d9d3204d479e757f9f9a6be7a-2135254127.us-east-2.elb.amazonaws.com/ ten times
  not answering yet (URLError); a new load balancer's address can take a few minutes
  not answering yet (URLError); a new load balancer's address can take a few minutes
  not answering yet (URLError); a new load balancer's address can take a few minutes
  not answering yet (URLError); a new load balancer's address can take a few minutes
  not answering yet (URLError); a new load balancer's address can take a few minutes
  v1  menu-785cf46557-qbvcg    on ip-10-29-1-223.us-east-2.compute.internal    answered 6
  v1  menu-785cf46557-r6n9m    on ip-10-29-0-18.us-east-2.compute.internal     answered 4

Look at the pods' addresses: 10.29.1.111 and 10.29.0.19, from the VPC's own subnets. On EKS, the VPC CNI gives every pod a real VPC address, the same kind a server gets. Anything in the VPC can reach a pod directly, and security groups and flow logs see pod traffic as it is. It also has a limit, which the next section runs into.

Nobody wrote a load balancer into the Terraform, yet one exists. A Service of type LoadBalancer asks the cluster for one, and EKS's built-in controller made a Classic Load Balancer in the tagged public subnets, with its security group limited by loadBalancerSourceRanges to your IP. Its address was known in a second; it answered about 75 seconds later, once its DNS name and health checks caught up. Terraform has no record of it at all, which matters at the end.

How many pods fit?

BASH
python lab.py squeeze
OUTPUT
== Asking for 30 copies of the menu
deployment.apps/menu scaled
== The menu's pods: 14 pending, 16 running
== Pods per node, out of what each node allows
  ip-10-29-0-18.us-east-2.compute.internal     us-east-2a  11 of 11 pods
  ip-10-29-1-223.us-east-2.compute.internal    us-east-2b  11 of 11 pods
== Why the rest are Pending (the scheduler's message)
  0/2 nodes are available: 2 Too many pods. preemption: 0/2 nodes are available: 2 No preemption victims found for incoming pod.

Each node was full at 11 pods, though each was nowhere near out of CPU or memory. 30 copies asked for 750m of CPU in all, less than half of one node's. The limit was addresses. Because every pod gets a VPC address, a node can only run as many pods as it has addresses to give out, and a t4g.small has 3 network cards with 4 addresses each, one of which each card keeps for itself:

StepCount
Network cards on a t4g.small3
Addresses per card, less the card's own4 - 1 = 3
Addresses for pods3 × 3 = 9
Plus 2 pods that use the node's own address (aws-node, kube-proxy)11 pods per node
Less the add-ons on each node: aws-node, kube-proxy, one CoreDNS8 left for the menu, 16 on two nodes

The scheduler's message says it plainly: 2 Too many pods, not too little CPU or memory. Bigger instance types have more network cards and more addresses each, so the limit grows with size. The VPC CNI can also give each card whole blocks of addresses, called prefix delegation, which raises a small node's limit to 110; real clusters often turn it on.

Add a node with Terraform

BASH
python lab.py tf plan -var node_count=3 -out=tfplan
python lab.py tf apply tfplan
python lab.py pods
OUTPUT
  # aws_eks_node_group.default will be updated in-place
  ~ resource "aws_eks_node_group" "default" {
        id                     = "jr-lesson29:jr-lesson29-nodes"
        tags                   = {}
        # (17 unchanged attributes hidden)

      ~ scaling_config {
          ~ desired_size = 2 -> 3
            # (2 unchanged attributes hidden)
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
OUTPUT
aws_eks_node_group.default: Modifying... [id=jr-lesson29:jr-lesson29-nodes]
aws_eks_node_group.default: Modifications complete after 4s [id=jr-lesson29:jr-lesson29-nodes]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Outputs:

cluster_name = "jr-lesson29"
kubernetes_version = "1.37"
node_count = 3
support_type = "STANDARD"
== The menu's pods: 14 pending, 16 running
== Pods per node, out of what each node allows
  ip-10-29-0-18.us-east-2.compute.internal     us-east-2a  11 of 11 pods
  ip-10-29-1-223.us-east-2.compute.internal    us-east-2b  11 of 11 pods

Terraform finished in 4 seconds, and nothing had changed yet. The apply changed the node group's desired size, which is all Terraform does here. The node group then launched an instance, which had to boot, join the cluster and start its own aws-node and kube-proxy before the scheduler could put anything on it: a minute or two. pods ran straight after the apply, so it still saw two nodes and 14 pods waiting.

That's worth remembering beyond this lab: Terraform reporting done means AWS accepted the change, not that the capacity is ready. For the ECS service in Lesson 28, wait_for_steady_state made Terraform wait for healthy copies; a node group has no such wait. Run python lab.py pods again a minute or two later and you'll see a third node with 11 more places, 9 of them for the menu.

In real clusters, nobody runs Terraform to add a node when pods are Pending. Karpenter or the Cluster Autoscaler watches for exactly the message above and adds nodes on its own, then removes them when they're empty; Terraform sets the limits.

Take it down

BASH
python lab.py undeploy
python lab.py tf plan -destroy -var node_count=3 -out=tfplan
python lab.py tf apply tfplan
python lab.py delete
OUTPUT
== Deleting the menu; Kubernetes deletes the load balancer it made
deployment.apps "menu" deleted
service "menu" deleted
  the load balancer is gone after 0 seconds

undeploy has to come first. The load balancer Kubernetes made sits in the VPC, with its own network cards and security group, and Terraform knows nothing about it. Destroy the network first and the VPC can't be deleted while the load balancer is in it: the destroy fails, or hangs, and the load balancer keeps billing with nothing managing it. The lab's tf step refuses a destroy while the Service exists, for exactly this reason.

The load balancer was already gone when kubectl delete returned because a Service of type LoadBalancer carries a finalizer: Kubernetes won't finish deleting the Service until its controller has deleted the load balancer. Deleting through Kubernetes is what makes that cleanup happen.

The destroy's last minutes:

OUTPUT
module.network.aws_internet_gateway.this: Destruction complete after 1m40s
aws_eks_node_group.default: Still destroying... [id=jr-lesson29:jr-lesson29-nodes, 1m40s elapsed]
aws_eks_node_group.default: Still destroying... [id=jr-lesson29:jr-lesson29-nodes, 1m50s elapsed]
aws_eks_node_group.default: Still destroying... [id=jr-lesson29:jr-lesson29-nodes, 2m0s elapsed]
aws_eks_node_group.default: Destruction complete after 2m6s
aws_iam_role_policy_attachment.node["arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"]: Destroying... [id=jr-lesson29-node-role/arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy]
aws_iam_role_policy_attachment.node["arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"]: Destroying... [id=jr-lesson29-node-role/arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy]
aws_iam_role_policy_attachment.node["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"]: Destroying... [id=jr-lesson29-node-role/arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly]
aws_eks_addon.vpc_cni: Destroying... [id=jr-lesson29:vpc-cni]
aws_eks_addon.kube_proxy: Destroying... [id=jr-lesson29:kube-proxy]
aws_iam_role_policy_attachment.node["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"]: Destruction complete after 0s
aws_iam_role_policy_attachment.node["arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"]: Destruction complete after 0s
aws_iam_role_policy_attachment.node["arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"]: Destruction complete after 0s
aws_iam_role.node: Destroying... [id=jr-lesson29-node-role]
aws_iam_role.node: Destruction complete after 0s
aws_eks_addon.kube_proxy: Destruction complete after 1s
aws_eks_addon.vpc_cni: Destruction complete after 1s
aws_eks_cluster.this: Destroying... [id=jr-lesson29]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 10s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 20s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 30s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 40s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 50s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 1m0s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 1m10s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 1m20s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 1m30s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 1m40s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 1m50s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 2m0s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 2m10s elapsed]
aws_eks_cluster.this: Still destroying... [id=jr-lesson29, 2m20s elapsed]
aws_eks_cluster.this: Destruction complete after 2m28s
aws_iam_role_policy_attachment.cluster: Destroying... [id=jr-lesson29-cluster-role/arn:aws:iam::aws:policy/AmazonEKSClusterPolicy]
module.network.aws_subnet.public[0]: Destroying... [id=subnet-0dddaaadbe1b1baf3]
module.network.aws_subnet.public[1]: Destroying... [id=subnet-0e79722e7e2feb94e]
aws_iam_role_policy_attachment.cluster: Destruction complete after 0s
aws_iam_role.cluster: Destroying... [id=jr-lesson29-cluster-role]
aws_iam_role.cluster: Destruction complete after 0s
module.network.aws_subnet.public[1]: Destruction complete after 0s
module.network.aws_subnet.public[0]: Destruction complete after 1s
module.network.aws_vpc.this: Destroying... [id=vpc-0b2a43667057702f9]
module.network.aws_vpc.this: Destruction complete after 0s

Apply complete! Resources: 0 added, 0 changed, 18 destroyed.
== Deleting the repository and its images
== Deleting the state bucket jr-lesson29-state-f2829cd3, every version of every file in it
== Removed backend.hcl, the .auto.tfvars files, kubeconfig, menu.yaml, the saved plan and .terraform
== Removing 1 image tags from your machine, and the registry login
== Anything left from Lesson 29
  nothing: all clear

The building order in reverse: CoreDNS, then the nodes, then the networking add-ons, then the cluster, then the network. The internet gateway waited 1m40s while the nodes, and their public addresses, went away.

By hand: kubectl and the AWS CLI, without the helper

(Your machine) Write a kubeconfig for this cluster only, and use it:

BASH
cd ~/Apps/aws-practice/lesson-29
aws eks update-kubeconfig --name jr-lesson29 --region us-east-2 --profile juniper-rye \
  --kubeconfig ./kubeconfig --alias jr-lesson29
export KUBECONFIG=./kubeconfig AWS_PROFILE=juniper-rye

kubectl get nodes -o wide
kubectl get nodes -o custom-columns=NAME:.metadata.name,ZONE:.metadata.labels.topology\\.kubernetes\\.io/zone,PODS:.status.allocatable.pods
kubectl get events --field-selector reason=FailedScheduling

Versions, and who may use the cluster:

BASH
aws eks describe-cluster-versions --region us-east-2 \
  --query "clusterVersions[].[clusterVersion,versionStatus,endOfStandardSupportDate]" --output table
aws eks list-access-entries --cluster-name jr-lesson29 --region us-east-2

Clean up in the right order: Kubernetes' resources first, then Terraform's:

BASH
kubectl delete -f menu.yaml --wait=true
cd terraform
terraform plan -destroy -out=tfplan
terraform apply tfplan

In real systems

  • Nodes live in private subnets, reaching the internet through NAT, with only load balancers public. The API endpoint is often private-only, reached over a VPN.
  • Traffic comes in through the AWS Load Balancer Controller, which makes Application or Network Load Balancers from Ingress or Gateway API objects; the Classic Load Balancer made here is the old built-in way. The Kubernetes track's Gateway API lesson covers the Kubernetes side.
  • Karpenter or the Cluster Autoscaler adds and removes nodes as pods need them.
  • Apps get AWS permissions with EKS Pod Identity, a role per service account, never the node's role.
  • Versions are upgraded on a schedule, a few times a year: control plane, then add-ons, then nodes, tested in a lower environment first.
  • Apps are deployed by GitOps, with a tool like Argo CD watching a Git repository, not kubectl from a laptop.
  • EKS Auto Mode is an option that also manages nodes, add-ons and load balancers, for an extra fee per node; it trades control for less to run.

Spot the problem

Work out what's wrong before you read the explanation.

"Our test cluster's bill went up five times overnight." A team's test cluster cost about $73 a month for its control plane. One month it's $365, with nothing changed: same nodes, same apps, nobody touched it. What's wrong? The cluster's Kubernetes version reached the end of standard support, and the cluster moved to extended support, at $0.50 an hour instead of $0.10. Nothing changed is the problem: nobody upgraded it. The fix: set the upgrade policy's support type to STANDARD, so EKS upgrades the cluster instead of moving it to extended support, and put upgrades on the calendar before each end date. Then check: run aws eks describe-cluster-versions; how many months of standard support does the cluster's version have left, and is the cluster's support type STANDARD?

Keep this

RememberWhy
The control plane bills by the hour$0.10 an hour with nothing running
Every version has an end dateExtended support was 5 times the price
upgrade_policy: STANDARDNever billed for extended support
API open to your IP onlyNodes use the private endpoint
Access entries decide who uses kubectlIn AWS, not a ConfigMap in the cluster
Networking add-ons before nodes, DNS afterNodes need networking to be Ready; DNS needs nodes
Pods get VPC addressesA t4g.small held 11 pods, then "Too many pods"
Terraform done isn't capacity readyThe node group changed in 4 seconds; the node took minutes
Delete Kubernetes' resources firstIts load balancer would block destroying the VPC

Where you are now

Juniper & Rye's menu has run on Kubernetes in AWS: an EKS cluster on 1.37, locked to standard support, with an API only you could reach and two small Arm nodes, all from Terraform, and the menu deployed with kubectl behind a load balancer Kubernetes made itself. You saw why a small node fills up at 11 pods, added a node with one changed value, and tore it down in the order that leaves nothing behind. Next, Lesson 30 compares Terraform with AWS's own tools for the same job: CloudFormation and the CDK.

Check yourself

  1. What does the $0.10 an hour EKS fee pay for?

  2. What does upgrade_policy with support_type STANDARD do when a version's standard support ends?

  3. Why was the coredns add-on created last?

  4. How does kubectl sign in to the EKS cluster?

  5. With 30 copies asked for, why were 14 Pending?

  6. Terraform changed node_count to 3 in 4 seconds. Why did pods still show 2 nodes?

  7. Why must the menu be undeployed before Terraform destroys everything?

Key terms

  • EKS (Elastic Kubernetes Service): Kubernetes with the control plane run by AWS.
  • Control plane: the API server, cluster database and scheduler; on EKS, run by AWS.
  • Node: a computer that runs pods; here, an EC2 instance.
  • Managed node group: a group of nodes EKS launches, updates and replaces for you.
  • Add-on: a piece of the cluster's own software EKS publishes, like the VPC CNI or CoreDNS.
  • VPC CNI: the add-on that gives each pod an address in your VPC.
  • Standard support: about 14 months during which a Kubernetes version costs the normal hourly fee.
  • Extended support: a further year on an old version, at five times the price here.
  • Access entry: an EKS record tying an AWS identity to what it may do in the cluster.
  • kubeconfig: the file that tells kubectl which cluster to use and how to sign in.
  • Finalizer: a marker that stops Kubernetes deleting an object until some cleanup has finished.
  • Prefix delegation: giving each network card blocks of addresses, so a node can hold more pods.

Go deeper