Agentic AI with Java: Live Cohort
KubernetesEKS Cluster Setup

Installing kubectl, AWS CLI and eksctl for EKS

Compare the ways to get a Kubernetes cluster, launch an Ubuntu EC2 instance as your EKS host, and install the AWS CLI, kubectl and eksctl with a verified script.

Before we can create anything on Kubernetes, we need a cluster, and before we can create the cluster, we need a machine with the right tools on it. This lesson sets up that machine. It takes about 15 minutes and you only do it once.

Ways to get a Kubernetes cluster

There are many ways to run Kubernetes. They fall into three groups.

OptionWhat it isWhere it fits
minikube (also kind, k3d)A single-node cluster on your laptopLearning and local testing, never production
kubeadmOfficial tool to bootstrap a cluster on servers you ownOn-premises or self-managed clusters. You install, upgrade and back up everything yourself
kOpsTool to create and manage production clusters, mostly on AWSWas popular before managed services matured, used less now
Managed KubernetesThe cloud provider runs the control plane for youMost production clusters today

Managed options exist on every major cloud: Amazon EKS (Elastic Kubernetes Service), Azure AKS, Google GKE and Oracle OKE. With a managed service, all the control plane components from the architecture lesson (API server, etcd, scheduler, controller manager) are installed, patched and kept highly available by the provider.

We use EKS for the whole course.

The plan

We will not click through the EKS console to create the cluster. That path involves creating a VPC, subnets, IAM roles, a cluster, a node group and add-ons by hand, and missing one step gives you a cluster that does not work. Instead we use a command line tool that does all of it in one go.

Your laptop --SSH--> EC2 "EKS home server" (Ubuntu)
                       |- aws     : talks to AWS, provides credentials
                       |- eksctl  : creates / deletes the EKS cluster
                       '- kubectl : talks to Kubernetes once the cluster exists
ToolMade byPurpose
AWS CLI v2AWSCommand line access to every AWS service. eksctl and kubectl use its credentials, and kubectl uses aws eks get-token to log in to EKS
eksctlOriginally Weaveworks, now maintained under AWSCreates, scales and deletes EKS clusters, using CloudFormation behind the scenes
kubectlKubernetes projectThe client for every Kubernetes cluster: create, list, describe, delete resources

Why an EC2 instance instead of your laptop?

You can install these three tools on Windows, macOS or Linux and work from your laptop. We use a small Ubuntu EC2 instance so everyone gets the same operating system and the same commands, and because an IAM role on the instance can give it AWS permissions without storing access keys on your laptop. If you prefer your laptop, the official install pages are linked at the end.

Step 1: Launch the EKS home server

Open EC2 in the right region

Sign in to the AWS console, search for EC2 and click Launch instance. Check the region in the top right. We use Asia Pacific (Mumbai) ap-south-1. Use the same region for the EC2 instance and the cluster.

Name and operating system

Name it EKS-HOME-Server. Under Application and OS Images pick Ubuntu, then Ubuntu Server 26.04 LTS, the image used in the lecture (24.04 LTS works the same way). The install script below is written for Ubuntu.

Instance type

t3.micro is enough. This machine only runs command line tools; the real work happens on the cluster. Pick whichever type your account marks as Free tier eligible.

Key pair

Click Create new key pair, name it kubernetes-keypair, keep RSA and .pem, and create it. The file downloads once and cannot be downloaded again. Move it to a folder where you keep your keys.

Network settings

Create a new security group and keep Allow SSH traffic ticked. Without it you cannot connect. For better security choose My IP as the source instead of Anywhere.

Storage and launch

The default 8 GB disk is enough. Click Launch instance and wait until the state is Running.

Step 2: Connect with SSH

Select the instance, click Connect, open the SSH client tab and copy the example command. Open Git Bash (Windows) or Terminal (macOS, Linux) in the folder where the .pem file is, then run:

chmod 400 kubernetes-keypair.pem
ssh -i "kubernetes-keypair.pem" ubuntu@<public-dns-of-your-instance>

The default user on Ubuntu AMIs is ubuntu. Type yes the first time when SSH asks about the host fingerprint. If you get stuck, Connecting to an EC2 Instance Using Git Bash in the Linux course walks through SSH in detail, and vi Editor Basics covers the editor we use next.

Step 3: Install the three tools

In the lecture, the script came from an AI assistant using a prompt like "create a production-ready, idempotent bash script to install kubectl, AWS CLI v2 and eksctl on Ubuntu, with verification steps". The first version failed with unzip: command not found, and after a fix it installed everything. That is a fine way to work, but always check generated commands against the official install pages, because AI tools often reproduce old flags.

What went wrong in the recorded script

The generated script ran kubectl version --client --short. The --short flag was removed in kubectl 1.28, so the verification step printed error: unknown flag: --short. Use kubectl version --client instead. The script below is built only from the official AWS, Kubernetes and eksctl instructions.

Create the script:

vi install-kubernetes-tools.sh

Press i for insert mode, paste the following, then press Esc and type :wq to save and quit.

install-kubernetes-tools.sh
#!/usr/bin/env bash
# Installs AWS CLI v2, kubectl and eksctl on Ubuntu (x86_64 / amd64)
set -euo pipefail

echo "=== Installing prerequisites ==="
sudo apt-get update -y
sudo apt-get install -y curl unzip tar

cd /tmp

echo "=== AWS CLI v2 ==="
curl -sSL "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip
unzip -q -o awscliv2.zip
sudo ./aws/install --update
rm -rf aws awscliv2.zip

echo "=== kubectl (latest stable) ==="
KVER=$(curl -L -s https://dl.k8s.io/release/stable.txt)
curl -sSLO "https://dl.k8s.io/release/${KVER}/bin/linux/amd64/kubectl"
curl -sSLO "https://dl.k8s.io/release/${KVER}/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
rm -f kubectl kubectl.sha256

echo "=== eksctl (latest) ==="
PLATFORM=$(uname -s)_amd64
curl -sSLO "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_${PLATFORM}.tar.gz"
curl -sSL "https://github.com/eksctl-io/eksctl/releases/latest/download/eksctl_checksums.txt" | grep "${PLATFORM}" | sha256sum --check
tar -xzf "eksctl_${PLATFORM}.tar.gz" -C /tmp && rm "eksctl_${PLATFORM}.tar.gz"
sudo install -m 0755 /tmp/eksctl /usr/local/bin && rm /tmp/eksctl

echo "=== Versions ==="
aws --version
kubectl version --client
eksctl version

Make it executable and run it:

chmod +x install-kubernetes-tools.sh
./install-kubernetes-tools.sh
LineWhy it is there
set -euo pipefailStop at the first error instead of carrying on with a half-installed system
apt-get install unzipThe AWS CLI comes as a zip file. Fresh Ubuntu images do not include unzip, which is exactly the error seen in the lecture
./aws/install --updateInstalls the CLI, or updates it if it is already there, so the script is safe to run twice
stable.txtReturns the latest stable Kubernetes version, for example v1.37.1
sha256sum --checkConfirms the downloaded binary was not corrupted or tampered with
install -m 0755 ... /usr/local/binCopies the binary into a folder on your PATH with execute permission

When it finishes you should see something like this (your versions will be newer or older):

aws-cli/2.x.x Python/3.x.x Linux/... exe/x86_64.ubuntu.24
Client Version: v1.37.1
Kustomize Version: v5.x.x
0.231.0

kubectl version skew

kubectl is supported within one minor version of the cluster. A 1.37 kubectl works with 1.36, 1.37 and 1.38 clusters. If you create an older cluster later, download a matching kubectl. The Amazon EKS install page lists a download link for every EKS version.

Step 4: Give the tools AWS credentials

eksctl needs permission to create a VPC, IAM roles, CloudFormation stacks, EC2 instances and the EKS cluster. There are two ways to give it that permission.

The way shown in the lecture: aws configure with access keys

The lecture creates an access key from the Security credentials page and runs:

aws configure
AWS Access Key ID [None]: <your access key id>
AWS Secret Access Key [None]: <your secret access key>
Default region name [None]: ap-south-1
Default output format [None]: json

This works, but be careful:

  • Never create access keys for the root user. If you are signed in as root, create an IAM user first (see IAM: root vs IAM user) and create the key for that user.
  • The keys are saved in plain text in ~/.aws/credentials on the EC2 instance. Anyone who gets into that machine gets your AWS account.
  • Never paste keys into screenshots, chat messages or Git repositories.

The better way: an IAM role on the EC2 instance

The next lesson attaches an IAM role to this EC2 instance. A role gives the instance temporary credentials that rotate automatically, and nothing secret is stored on disk. If you use the role, you do not need access keys at all. Just set the region:

aws configure set region ap-south-1

Keys override the role

The AWS CLI checks ~/.aws/credentials before it checks the instance role. If you ran aws configure with keys earlier and later attach a role, the keys still win. Delete the keys from the file, and deactivate them in IAM, if you switch to the role.

Whichever method you choose, confirm who you are before creating anything:

aws sts get-caller-identity

It prints the user or role ARN that eksctl will use. AWS recommends that you create and manage the cluster as this same identity throughout.

Common errors

Cost note

The t3.micro EKS home server is small, and free tier eligible on most new accounts. When you take a break of several days, stop it from the EC2 console rather than terminating it. The tools stay installed and you only pay for the 8 GB disk while it is stopped. The expensive part is the EKS cluster, which we create and delete in the next lesson.

Try It Yourself

  1. Launch the EKS home server and install all three tools with the script above.
  2. Run aws --version, kubectl version --client and eksctl version and note the versions.
  3. Run kubectl get nodes now, before any cluster exists. Read the error and explain why it happens (hint: there is no kubeconfig yet).
  4. Run aws sts get-caller-identity and identify whether you are using an IAM user or a role.
  5. Run the script a second time and confirm it completes without errors.

Official references


Written By: Shramik Masti

How is this guide?

Last updated on