Amazon EKS — First Cluster — Practice Exercises

3 minute read

Chapter 3 — Practice Exercises

Test your cluster creation skills with these 5 exercises.


Exercise 1: Create and Verify

Question: Create an EKS cluster named practice in us-west-2 with 2 t3.small nodes. Then run 3 commands to verify it’s working. Finally, delete the cluster.

Show Solution
# Create cluster
$ eksctl create cluster \
    --name practice \
    --region us-west-2 \
    --node-type t3.small \
    --nodes 2

# Verify (3 commands)
$ kubectl get nodes                    # Both nodes should be Ready
$ kubectl get pods -n kube-system      # All system pods Running
$ kubectl cluster-info                 # Shows API server endpoint

# Delete cluster
$ eksctl delete cluster --name practice --region us-west-2

Note: t3.small has only 2 GB RAM and supports max ~11 pods. Fine for practice, but use t3.medium or larger for real workloads.


Exercise 2: Config File Cluster

Question: Write an eksctl config file that creates a cluster named config-demo with: Kubernetes 1.29, 3 m5.large nodes in private subnets, OIDC enabled, and CloudWatch logging for API and audit logs.

Show Solution
# config-demo.yaml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: config-demo
  region: us-east-1
  version: "1.29"

iam:
  withOIDC: true

managedNodeGroups:
  - name: workers
    instanceType: m5.large
    desiredCapacity: 3
    minSize: 2
    maxSize: 5
    privateNetworking: true
    volumeSize: 30

cloudWatch:
  clusterLogging:
    enableTypes:
      - api
      - audit
# Create
$ eksctl create cluster -f config-demo.yaml

# Verify OIDC
$ aws eks describe-cluster --name config-demo --query 'cluster.identity.oidc.issuer'

# Delete
$ eksctl delete cluster --name config-demo --region us-east-1

Exercise 3: Multiple Contexts

Question: Explain how to configure kubectl to work with 3 different EKS clusters (dev, staging, prod) and switch between them. What’s the risk of having multiple contexts?

Show Solution
# Add all three clusters with aliases
$ aws eks update-kubeconfig --name dev-cluster --region us-east-1 --alias dev
$ aws eks update-kubeconfig --name staging-cluster --region us-east-1 --alias staging
$ aws eks update-kubeconfig --name prod-cluster --region us-east-1 --alias prod

# List contexts
$ kubectl config get-contexts

# Switch between them
$ kubectl config use-context dev
$ kubectl config use-context staging
$ kubectl config use-context prod

# Check current context
$ kubectl config current-context

Risk of multiple contexts:

  • Running commands on the wrong cluster (e.g., kubectl delete on prod instead of dev)

Mitigation:

  • Always check kubectl config current-context before destructive commands
  • Use tools like kubectx for easier switching
  • Use kubectl prompt plugins that show current context in your terminal prompt
  • Use separate kubeconfig files per cluster: export KUBECONFIG=~/.kube/config-dev

Exercise 4: Cost Optimization

Question: Your manager wants to reduce the EKS development cluster cost from $250/month. Currently: 1 EKS cluster, 3 m5.large On-Demand nodes, 3 NAT Gateways. Suggest 4 specific changes and estimate the new monthly cost.

Show Solution

Current cost breakdown:

EKS cluster:                 $73
3x m5.large (On-Demand):     $210  (3 × $0.096/hr × 730)
3x NAT Gateways:             $96   (3 × $32)
Total:                       $379/month  (oops, already over $250!)

4 changes:

  1. Use Spot instances — Switch to Spot for dev workloads
    • m5.large Spot: ~$0.035/hr = $77 for 3 nodes (save $133)
  2. Single NAT Gateway — Acceptable for dev (not HA, but cheaper)
    • 1 NAT GW: $32 (save $64)
  3. Downsize to t3.medium — 2 vCPU, 4 GB is enough for dev
    • 3x t3.medium Spot: ~$45 (save $165 vs m5.large On-Demand)
  4. Delete cluster outside work hours — Use a script to create/delete
    • If running 10 hrs/day, 5 days/week: ~35% of month
    • Saves ~65% on compute and cluster fees

New cost (running 24/7 with changes 1-3):

EKS cluster:                 $73
3x t3.medium (Spot):         $45
1x NAT Gateway:              $32
Total:                       $150/month (40% savings!)

With change 4 (work hours only):

Total: ~$55/month (85% savings!)

Exercise 5: Troubleshoot Failed Creation

Question: You run eksctl create cluster and after 20 minutes it fails with: “ResourceStatus: CREATE_FAILED, ResourceStatusReason: The maximum number of VPCs has been reached.” What happened and how do you fix it?

Show Solution

What happened:

  • Each AWS region has a default VPC limit of 5 VPCs
  • eksctl creates a new VPC for each cluster
  • You’ve hit the limit (probably have existing VPCs)

Fix options:

  1. Delete unused VPCs:
    # List VPCs
    $ aws ec2 describe-vpcs --query 'Vpcs[*].{ID:VpcId, CIDR:CidrBlock, Default:IsDefault}' --output table
       
    # Delete unused VPC (must delete subnets, IGW, etc. first)
    $ aws ec2 delete-vpc --vpc-id vpc-xxxxx
    
  2. Request a VPC limit increase:
    # Check current limit
    $ aws service-quotas get-service-quota --service-code vpc --quota-code L-F678F1CE
       
    # Request increase
    $ aws service-quotas request-service-quota-increase \
        --service-code vpc \
        --quota-code L-F678F1CE \
        --desired-value 10
    
  3. Use an existing VPC (best practice for production):
    # cluster.yaml
    vpc:
      id: vpc-0abc123def456
      subnets:
        private:
          us-east-1a: { id: subnet-0abc }
          us-east-1b: { id: subnet-0def }
        public:
          us-east-1a: { id: subnet-0ghi }
          us-east-1b: { id: subnet-0jkl }
    
  4. Use a different region:
    $ eksctl create cluster --name demo --region us-west-2
    

What’s Next?

Congratulations on completing the Foundations section! 🎉

Next up: Chapter 4 — Architecture Deep Dive where we explore EKS internals in detail.