This Terraform repository provides an example setup for deploying an Amazon EKS cluster into an existing VPC. The setup includes configurations to allow pods within the EKS cluster to assume IAM roles, enabling them to access AWS resources such as S3 buckets.
Before you begin, ensure you have the following prerequisites in place:
- Terraform installed on your machine.
- AWS CLI installed and configured with your AWS credentials.
- An existing VPC with subnets where you plan to deploy the EKS cluster.
- An S3 bucket created that you want to grant access to from the pods in the EKS cluster.
Follow these steps to deploy the EKS cluster and configure pod IAM role assumption:
-
Clone the Repository:
Clone this repository to your local machine using the following commands:
git clone https://github.com/travka/terraform-eks-task.git cd terraform-eks-task
-
Configure Variables:
Open the
variables.tf
file and adjust the variables according to your preferences and requirements. You can modify the EKS cluster's region, name, version, VPC CIDR block, and other settings. Make sure to review and customize the variables before proceeding. -
Initialize Terraform:
Initialize Terraform to download the required provider plugins and modules:
terraform init
-
Deploy the EKS Cluster:
Deploy the EKS cluster and related resources using Terraform:
terraform apply
-
Configure kubectl:
Configure
kubectl
to work with the newly created EKS cluster:aws eks --region <your-region> update-kubeconfig --name <eks-cluster-name>
-
Deploy a Sample Pod:
Use the following sample YAML configuration (
sample-pod.yaml
) to deploy a pod within the EKS cluster. Replace<your-service-account-name>
with the actual service account name:apiVersion: v1 kind: Pod metadata: name: sample-pod spec: containers: - name: sample-container image: amazonlinux:latest command: ["sleep", "3600"] automountServiceAccountToken: true serviceAccountName: <your-service-account-name>
Apply the sample pod configuration:
kubectl apply -f sample-pod.yaml
-
Verify S3 Access:
Verify that the pod can access the specified S3 bucket:
kubectl exec -it sample-pod -- aws s3 ls s3://your-bucket-name
-
Clean Up:
When you're done experimenting, don't forget to clean up the resources:
terraform destroy
- For more information on configuring pods to assume IAM roles and accessing S3 buckets, refer to the official AWS documentation.
- Explore Terraform's documentation for advanced configurations and customizations: Terraform Documentation.
Maintained by travka