2020-08-27 19:37:16 +10:00
..
2020-07-22 22:53:06 +10:00

Getting Started with Amazon EKS using Terraform

More resources:

Terraform provider for AWS here

Amazon CLI

You can get the Amazon CLI on Docker-Hub
We'll need the Amazon CLI to gather information so we can build our Terraform file.

# Run Amazon CLI
docker run -it --rm -v ${PWD}:/work -w /work --entrypoint /bin/sh amazon/aws-cli:2.0.43

# some handy tools :)
yum install -y jq gzip nano tar git unzip wget

Login to Amazon

# Access your "My Security Credentials" section in your profile. 
# Create an access key

aws configure

Default region name: ap-southeast-2
Default output format: json

Terraform CLI

# Get Terraform

curl -o /tmp/terraform.zip -LO https://releases.hashicorp.com/terraform/0.13.1/terraform_0.13.1_linux_amd64.zip
unzip /tmp/terraform.zip
chmod +x terraform && mv terraform /usr/local/bin/
terraform

Generate SSH key for our EC2 workers

ssh-keygen -t rsa -b 4096 -N 'VeryStrongSecret123!' -C "your_email@example.com" -q -f  ~/.ssh/id_rsa
SSH_KEY=$(cat ~/.ssh/id_rsa.pub)

Terraform Amazon Kubernetes Provider

Documentation on all the Kubernetes fields for terraform here

cd kubernetes/cloud/amazon/terraform

terraform init

terraform plan
terraform apply

Lets see what we deployed

# grab our EKS config
aws eks update-kubeconfig --name getting-started-eks --region ap-southeast-2

# Get kubectl

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x ./kubectl
mv ./kubectl /usr/local/bin/kubectl

kubectl get svc

Clean up

terraform destroy