How to create a Kubernetes development environment on AWS.

Cesar Augusto
4 min readDec 30, 2023

--

Hey folks :)

Today I’d like to show you how to create a simple Kubernetes development environment on AWS using Infrastructure as Code (IaC) with Terraform and Ansible.

To follow this article, I’ll use the repository

The repository above is a fork from this excellent repository https://github.com/cleitinif/kubernetes-cluster-setup but with some changes made to run in WSl2 local environment.

In this article, we’ll use an AWS account and a WSL2 local environment to run this.

If you haven’t an AWS account, please create one to follow this article.

1 — User Programmatic access

The first thing that we need to do is create a programmatic access with AdmistratorAccess on AWS. If you already have one, jump this step.

Click on Security Credentials and create an access key

Copy the value and save this to use in the next steps

2 — Configuring the local environment

To configure the local environment W, we need to install Terraform, Ansible, and Kubectl. Follow the steps below.

Terraform install

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

sudo apt update && sudo apt install terraform

Ansible install

sudo apt install ansible -y

Kubectl install

To install kubectl, follow the official guide at

3 — Executing Terraform script

After completing step 2, we need to configure our terraform script to use the access key created above. If you know how to use terraform, this can be done using environment variables also. For easier configuration, we’ll change the script by adding these keys

Replace the properties access_key and secret_Key.

After replacing these properties, execute the command below and await.

If you already haven't make tool installed, please install it.

sudo apt install make
make apply
make apply will synchronize wsl2 time with the host machine and execute terraform commands.

After executing the “make apply”, we expect this result

As expected, the nodes were created on AWS

4- Executing Ansible scripts to Install and Configure Kubernetes

According to the readme of the repository forked, we need to change the Ansible script with IPs in Output terraform scripts

aws_instances = [
"0.0.0.0", # control plane node
"0.0.0.0", # worker node
]

Access the file inventory.yaml and make the change below.

After making the change, run the command below. This command will execute all Ansible files necessary to install and configure nodes with Kubernetes.

make kubernetes
Await until all files are done.

Done! All files were executed and the Kubernetes was configured. Let's verify by running the command below.

kubectl get nodes

Now we can see the nodes running on AWS.

4 — Destroying the environment

To destroy the environment created, let’s run the command below.

make destroy

The command make destroy will run terraform destroy. It will destroy all resources created.

All resources were removed

That’s all folks :)

Final Tip

Would you like to run a GitOps on this environment? Please, see my article below.

--

--

Cesar Augusto

Software & Solutions Architect | Software Engineer | 6X Microsoft Azure Certified | 4X AWS Certified