This guide provides step-by-step instructions to deploy a production-ready Amazon EKS cluster using Terraform. for the purpose of learning Kubernetes !
I used EKS Terraform Module : Documentation Link --> https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest
Before you begin, ensure you have:
- An AWS account with IAM administrator permissions
- A user with programmatic access (access key ID and secret access key)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
rm -rf awscliv2.zip awsTF_VERSION=$(curl -sL https://releases.hashicorp.com/terraform/index.json | jq -r '.versions[].builds[].version' | egrep -v 'rc|beta|alpha' | tail -1)
curl -LO "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip"
unzip terraform_${TF_VERSION}_linux_amd64.zip
sudo mv -f terraform /usr/local/bin/
rm terraform_${TF_VERSION}_linux_amd64.zipcurl -O https://s3.us-west-2.amazonaws.com/amazon-eks/1.28.3/2023-11-14/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv kubectl /usr/local/bin/aws configureEnter your
- AWS Access Key ID
- AWS Secret Access Key
- Default region name ( any region you want but prefer to use the one where you are deploying your cluster me in us-east-1)
- Default output format ( leave it for default )
- Clone the repository:
git clone https://github.com/AymaneK24/Deploying-EKS-Cluster-With-Terraform.git
cd Deploying-EKS-Cluster-With-Terraform- Initialize Terraform:
terraform init- Review the execution plan:
terraform plan- Deploy the infrastructure (takes approximately 30 minutes):
terraform applyAfter deployment completes:
- Configure kubectl:
aws eks update-kubeconfig --region us-east-1 --name KENBOUCH-EKS-Cluster- Verify cluster access:
kubectl cluster-info
kubectl get nodes
- Cluster Name: KENBOUCH-EKS-Cluster
- Kubernetes Version: 1.28
- Node Group:
- Instance type: t3.medium
- Number of nodes: 1 (fixed size)
I deployed on the cluster thr image of a netflix clone i already used in a previous project, you can use the image what ever you want, just make sure it's exposed on the port 80, if not change that in the dockerfile.
Go check the app.yaml file, and you will see the image i used it's aymanekh24/netflix , the name of the running container is netflix-container
then :
kubectl apply -f app.yaml
run this :
kubectl get svc
to see the running services, there you will also get the endpoint of the application Neflix (External-IP)
the example below is of deploying an nginx server after i did the same but changeed first the yaml to be compatible for my netflix application.
To destroy all resources when no longer needed:
terraform destroy- The EKS cluster creation typically takes 20-30 minutes to complete
- The Terraform module creates multiple AWS resources including VPC, subnets, IAM roles, and security groups, etc
- For production environments, consider modifying the node group configuration for high availability
You may encounter the following error when trying to access your cluster:
You must be logged in to the server (Unauthorized)
This occurs because AWS EKS requires explicit permission grants, even for IAM users with AdministratorAccess.
- Navigate to EKS Service → Your Cluster → Access
- Add a new access entry for your IAM user
- Assign these recommended policies:
AmazonEKSAdminPolicyAmazonEKSClusterAdminPolicy
-
First reset your kubeconfig:
rm ~/.kube/config -
Then update your configuration with proper permissions:
aws eks update-kubeconfig --region us-east-1 --name KENBOUCH-EKS-Cluster
-
Run The script i provided you after modifying it :
sh permission.sh
then run again 1 and 2 to be sure then you are good !
- AYou Will find the ARN in console in EKS Under Access Entries a default Role created
- Note the role ARN
- Configure kubectl with the role:
aws eks update-kubeconfig --region us-east-1 --name KENBOUCH-EKS-Cluster \ --role-arn arn:aws:iam::123456789012:role/EKSAdminRole
What i learned :
- AWS EKS has separate permission requirements from standard IAM policies
- AdministratorAccess IAM policy doesn't automatically grant EKS cluster access
- Always verify access entries in the EKS console after cluster creation
This permission setup only needs to be completed once per cluster. After proper configuration, you should have persistent access to manage your Kubernetes resources.
© Aymane Kenbouch





