Using EKS and Gitlab CI to deploy applications
Setup EKS using Terraform and Ansible. Deploy applications on EKS using Gitlab CI and Helm.
Last updated
Setup EKS using Terraform and Ansible. Deploy applications on EKS using Gitlab CI and Helm.
Last updated
The main goal is to have a production-ready environment, showcasing AWS architecture, Terraform, Ansible, Kubernetes (EKS), Gitlab CI, DockerHub and Helm.
Key aspects:
All resources are managed in code. Even the bootstrap of the project .
HA where applicable (EKS Load Balancer)
The application is deployed from code.
The process described on this tutorial show how to:
Terraform: leverage an S3 bucket to store states ();
Terraform: leverage a DynamoDB table to store locks ();
Terraform: leverage a Virtual Machine ();
Ansible: setup VM swap, hostname and packages. Also, create a Docker container which runs the EKS setup process, setup kubeconfig and Helm ().
Gitlab CI: run a pipeline to build () a Docker image and push to DockerHub ();
Gitlab CI: deploy the Docker image on K8s using Helm ( and ).
AWS
Terraform
Ansible
Gitlab CI
Dockerhub
EKS
K8s
Helm
Make sure you have an AWS account. AWS will host the Kubernetes cluster (EKS) and a small Virtual Machine.
Make sure you have a Gitlab account to commit your code and use pipelines.
The stack bootstrap is done using Docker, so make sure you have Docker installed on your workstation.
You need to create an IAM user which will be used with Terraform.
Login to you AWS console, go to Services, IAM.
Go to Users, Add user.
Add a user called iac
(stands for Infra as Code) with Programmatic Access.
Attach AdministratorAccess and click on Next: Tags button.
Optionally add tags then click on Next: Review.
Review and create user.
Click on Show
in Secret access key
section. Copy and save in a safe place your Access key ID
and Secret access key
.
From now on, the Access key ID
and Secret access key
will be referenced in this tutorial as iac IAM user credentials
.
Use your iac IAM user credentials.
Once your have your AWS credentials setup, run the Terraform scripts.
At this point, if you go to you AWS console, you should have:
An S3 bucket;
A DynamoDB table;
A Virtual Machine.
eintopf
also has Ansible playbooks and roles do setup the infrastructure. The playbook playbooks/mgmt.yaml
setup a Virtual Machine with a Docker container. This container is responsible for setting up the EKS cluster.
At this point, if you go to you AWS console, you should have:
An EKS cluster.
You can copy the kubeconfig
file content and paste and save it in a safe place, specially if you want o use kubectl
from your workstation and not form the VM.
To convert the kubeconfig
content in the format to be used on Gitlab CI variable, run:
Push a change and watch the deployment logs.
Clone or fork eintopf
repository (Terraform and Ansible scripts):
Follow the instructions here:
To do so, follow the instructions here:
First, make sure you have ansible-vault configured:
Then, setup the infrastructure:
Also, the Virtual Machine called mgmt
hosts a Docker container called devops
. Inside this container you will find you Kubernetes cluster kubeconfig
file, which is used with kubectl
and also must be configured on your Gitlab CI variables to run the deployment test. More info here:
Clone or fork the following repo:
Setup the required variables to run the pipeline: