Sub topic 4
Creating Your First Cluster
This chapter assumes you have the AWS CLI configured with credentials that can create EKS, EC2, IAM, and CloudFormation resources. It also assumes kubectl and eksctl are installed, and that you know the EKS control plane and data plane split from the earlier chapters.
By the end you will have a running cluster with one managed node group. You will know what eksctl creates, how your kubeconfig gets wired up, and how to diagnose the most common failures.
What eksctl Does for You
eksctl is a command-line tool for creating and managing EKS clusters. It reads a declarative config file and generates CloudFormation stacks. Those stacks create the AWS resources a cluster needs.
A single eksctl create cluster run normally builds:
- A VPC with public and private subnets across multiple Availability Zones, unless you point it at an existing VPC.
- The EKS control plane, with its IAM service role.
- A managed node group, which is an EC2 Auto Scaling group that EKS provisions and updates for you.
- An IAM role for the nodes, with the policies they need to join the cluster and pull images.
- Entries in your kubeconfig so
kubectlcan reach the new cluster.
Because everything runs through CloudFormation, you can see each piece in the console and delete it as a unit later.
Writing the Cluster Config
A config file makes the cluster reproducible and reviewable. You can commit it to version control and apply the same definition in another account or region.
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: demo
region: us-east-1
managedNodeGroups:
- name: ng-1
instanceType: m5.large
desiredCapacity: 2
minSize: 1
maxSize: 4Save this as cluster.yaml. The fields mean the following:
| Field | Meaning |
|---|---|
| `metadata.name` | The cluster name. It must be unique within the account and region. |
| `metadata.region` | The AWS region where everything is created. |
| `managedNodeGroups[].name` | The node group name. Use a name that describes its purpose. |
| `instanceType` | The EC2 instance type for every node in the group. |
| `desiredCapacity` | How many nodes to start with. |
| `minSize` and `maxSize` | The bounds the Auto Scaling group may move within. |
The minSize and maxSize values only set limits. Nothing in this config adds nodes when pods are pending. That requires an autoscaler, which a later chapter covers.
Fields You Did Not Set
Several settings have defaults, and you should know them:
- Kubernetes version. If you omit
metadata.version,eksctluses its default, which is a recent version supported by EKS. Pin the version explicitly if you want repeatable builds. - Availability Zones.
eksctlpicks zones for you. List them underavailabilityZonesif you need specific ones. - Node networking. Managed nodes land in public subnets by default. Add
privateNetworking: trueto the node group to place them in private subnets. - Volume size. Nodes get a default root volume. Set
volumeSizeif your images are large.
Creating the Cluster
Run the create command, then update your kubeconfig and check the nodes.
eksctl create cluster -f cluster.yaml
aws eks update-kubeconfig --name demo --region us-east-1
kubectl get nodesCreation usually takes 15 to 20 minutes. Most of that time goes to the control plane, which EKS provisions across multiple Availability Zones.
eksctl already writes a kubeconfig entry when it finishes. The explicit aws eks update-kubeconfig call is still useful. You run it on a different machine, or as a different user, whenever you need to reconnect to an existing cluster.
A healthy result looks like this:
NAME STATUS ROLES AGE VERSION
ip-192-168-12-34.ec2.internal Ready <none> 3m v1.31.0-eks-xxxx
ip-192-168-54-78.ec2.internal Ready <none> 3m v1.31.0-eks-xxxxTwo nodes in Ready status match desiredCapacity: 2. The version string will differ based on your cluster version.
How the kubeconfig Authenticates
The kubeconfig entry does not store a long-lived password. It contains an exec section that runs aws eks get-token. That command signs a request with your current AWS credentials and returns a short-lived token. The EKS API server validates it against IAM.
This has two practical consequences:
kubectlworks only while your AWS credentials are valid. An expired session produces an authentication error even though the kubeconfig has not changed.- The IAM principal that created the cluster gets administrator access to it. Another principal does not, until you grant access. The chapter on cluster access covers how.
Watching Progress
While eksctl runs, you can follow along in two places. The CloudFormation console shows stacks named eksctl-demo-cluster and eksctl-demo-nodegroup-ng-1. The eksctl output prints each step. If creation fails, the stack events in CloudFormation name the resource that failed and why.
Verifying the Cluster
Checking nodes proves the data plane joined the control plane. A few more commands confirm the basics:
eksctl get cluster --region us-east-1
eksctl get nodegroup --cluster demo --region us-east-1
kubectl get pods -n kube-systemThe kube-system namespace should show pods for CoreDNS, kube-proxy, and the Amazon VPC CNI (aws-node). If CoreDNS pods stay Pending, nodes are usually missing or not Ready.
Common Failures
| Symptom | Likely cause | What to check |
|---|---|---|
| `AccessDenied` or `UnauthorizedOperation` during creation | Your IAM principal lacks permissions for EKS, EC2, IAM, or CloudFormation | The error text names the denied action. Add it to your policy. |
| Stack creation fails with a limit error | An account quota, such as VPCs per region or Elastic IPs, is exhausted | Service Quotas console, then delete unused resources or request an increase |
| The node group stack times out | Nodes could not register with the control plane | Subnet routes to the internet or VPC endpoints, and the node IAM role |
| `kubectl` returns `You must be logged in to the server` | Expired credentials, or a different IAM principal than the creator | `aws sts get-caller-identity` and compare it with the creator |
| `kubectl` hangs or times out | The cluster endpoint is private, or your network cannot reach it | Endpoint access settings and your network path |
| Nodes show `NotReady` | The VPC CNI is not working, or the node is out of IP addresses | `kubectl describe node` and the `aws-node` pod logs |
Pitfall: Mixing Tools
Resources that eksctl creates belong to its CloudFormation stacks. If you change the VPC, node IAM role, or Auto Scaling group by hand, eksctl and CloudFormation do not know. A later update can fail or revert your change. Make changes through the config file and eksctl commands wherever you can.
Changing and Deleting the Cluster
You can adjust the node count of an existing group without rebuilding the cluster:
eksctl scale nodegroup --cluster demo --name ng-1 --nodes 3 --region us-east-1The new value must sit between minSize and maxSize. To change the instance type, you cannot edit the group in place. Create a new node group with the new type, move workloads over, then remove the old group.
To remove everything, run:
eksctl delete cluster -f cluster.yamlDelete any load balancers, persistent volumes, or other resources you created inside the cluster first. Resources that Kubernetes created outside the eksctl stacks can block VPC deletion and leave the stack in a failed state.
Exercise
You run kubectl get nodes the morning after creating a cluster and get You must be logged in to the server (Unauthorized). Your kubeconfig has not changed. Name two likely causes and the command you would run first.
Show answer
Likely causes are that your AWS session credentials have expired, or that you are now using a different IAM principal than the one that created the cluster. Run aws sts get-caller-identity first to see which principal you are using. Refresh your credentials if the session expired. If it is a different principal, grant it access to the cluster, because only the creator receives administrator access by default.
Exercise
A teammate wants to change the node group in cluster.yaml from m5.large to m5.xlarge by editing the file and rerunning eksctl create cluster -f cluster.yaml. Why will this not work, and what is the safer approach?
Show answer
create cluster tries to create a cluster that already exists, and a node group's instance type cannot be edited in place. The safer approach is to add a new managed node group with the m5.xlarge type, wait for its nodes to be Ready, drain the old nodes so pods move to the new ones, and then delete the old node group.