Sub topic 4
Creating Your First Cluster
This chapter assumes you know basic Kubernetes objects and kubectl. It also assumes you can use the AWS CLI and understand IAM, VPC, and EC2. You will define a cluster in a YAML file, create it with eksctl, and check that it works.
Why a Declarative Config
eksctl is a command line tool for creating and managing EKS clusters. You can pass many flags to eksctl create cluster. A config file is easier to review, store in version control, and rerun. It also records the cluster's settings in one place.
Behind the scenes, eksctl creates AWS CloudFormation stacks. One stack holds the cluster and its VPC. Each node group gets its own stack. If creation fails, look at the stack events in the CloudFormation console for the cause.
The Cluster Config
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: 4The file sets these values:
metadata.nameandmetadata.regiongive the cluster name and the AWS Region.managedNodeGroupsdefines a managed node group. AWS provisions and updates the EC2 instances in it.instanceTypeis the EC2 type for each node.desiredCapacityis the starting node count.minSizeandmaxSizeare the limits for the underlying Auto Scaling group.
Because the file has no vpc section, eksctl creates a new VPC with public and private subnets across multiple Availability Zones. The previous chapter explained how pods get VPC IP addresses, so plan for that address use if you bring your own VPC.
Create the Cluster
eksctl create cluster -f cluster.yaml
aws eks update-kubeconfig --name demo --region us-east-1
kubectl get nodesThe first command creates the control plane and the node group. This usually takes 15 to 20 minutes. The second command writes the cluster's endpoint and authentication settings into your kubeconfig. eksctl normally does this already, but running it again is harmless and is the method you will use on other machines. The third command should list two nodes in the Ready state.
Common Errors
| Symptom | Likely cause | What to check |
|---|---|---|
| `AccessDenied` or `UnauthorizedOperation` during creation | Your IAM identity lacks permissions for EKS, EC2, CloudFormation, or IAM | The policies on the identity you are using |
| `kubectl` returns `Unauthorized` or asks for credentials | The kubeconfig uses a different AWS identity from the one that created the cluster | `aws sts get-caller-identity` |
| Stack creation fails on capacity | The Region or Availability Zone lacks the instance type, or you hit a service quota | CloudFormation events and EC2 quotas |
| Nodes stay `NotReady` | Node networking or the VPC CNI add-on has a problem | `kubectl describe node` and the `aws-node` pods |
Exercise
You run kubectl get nodes from a new laptop and get an authentication error, although the cluster exists. Which command fixes your local setup, and what should you check if it still fails?
Show answer
Run aws eks update-kubeconfig --name demo --region us-east-1 to write the cluster connection details into your kubeconfig. If it still fails, run aws sts get-caller-identity to confirm you are using an AWS identity that has been granted access to the cluster. The creator of the cluster has access by default, and other identities need to be granted it.
Exercise
In the config above, what range of node counts can the node group have, and which field sets the starting count?
Show answer
The group can have between 1 node (minSize) and 4 nodes (maxSize). desiredCapacity: 2 sets the starting count.