Amazon EKS in Production with Terraform›Build · Cheat sheet & self-check
Learning Hub / Cloud — OpenStack, AWS & EKS / Amazon EKS in Production with Terraform

Build · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

01 · EKS architecture & mental model

Inspect a cluster

aws eks list-clustersClusters in the region
aws eks describe-cluster --name prod --query 'cluster.[version,status,endpoint,resourcesVpcConfig.endpointPublicAccess,resourcesVpcConfig.endpointPrivateAccess]'Version, status, endpoint access
aws eks update-kubeconfig --name prod --region eu-west-1Add the cluster to your kubeconfig
aws eks list-addons --cluster-name prodInstalled EKS add-ons
aws eks list-nodegroups --cluster-name prodManaged node groups

02 · Remote state: S3, locking, env-per-tfvars

State

terraform init -backend-config=backend-prod.hclInitialise against an environment's backend
terraform state listResources tracked in state
terraform state show module.eks.aws_eks_cluster.this[0]One resource's recorded attributes
terraform force-unlock <lock-id>Remove a stale lock (only when sure nobody is running!)

Plans & drift

terraform plan -var-file=prod.tfvars -out=prod.planPlan and save it
terraform apply prod.planApply exactly what was planned
terraform plan -detailed-exitcodeExit 0 = no changes, 2 = changes (drift), 1 = error

03 · The multi-provider chicken-and-egg

Patterns

exec { command = "aws" args = ["eks", "get-token", …] }Fresh tokens during long applies
data "terraform_remote_state" "cluster" { … }Read the cluster layer's outputs from another stack
terraform apply -target=module.eksEmergency only: bootstrap one part first

Useful commands

aws eks get-token --cluster-name prod | jq -r .status.expirationTimestampWhen does this token expire?
terraform providersWhich providers each module uses

04 · VPC CNI & IP planning

Inspect

kubectl -n kube-system get ds aws-node -o jsonpath='{.spec.template.spec.containers[0].env}' | jqVPC CNI settings (env vars)
kubectl get nodes -o custom-columns=NAME:.metadata.name,PODS:.status.allocatable.podsMax pods per node
aws ec2 describe-subnets --subnet-ids <id> --query 'Subnets[].AvailableIpAddressCount'Free IPs left in a subnet

Key settings

ENABLE_PREFIX_DELEGATION=trueAssign /28 prefixes to ENIs (more pods per node)
AWS_VPC_K8S_CNI_CUSTOM_NETWORK_CFG=truePods use subnets from ENIConfig (e.g. a secondary CIDR)
WARM_IP_TARGET / WARM_PREFIX_TARGETHow many spare IPs/prefixes each node keeps ready