This repository presents a Python application that server HTTP requests at the routes 8080:/
and 8080:/health
.
The first one returns local time in specified locations (the default ones are New York, Berlin and Tokyo) in HTML format, and the second one return status code 200 in JSON format.
We also provide the following:
- Dockerfile that defines the container that will run the Python application;
- Terraform templates to define and build the necessary infrastructure to run this app at an AWS EKS Cluster;
- Helm chart that defines the required Kubernetes objects to run this app at the Kubernetes cluster.
- Python 3.9 (Download here)
- Docker (Installation guide here)
- AWS CLI configured (Installation guide here)
- Terraform (Installation guide here)
- Kubectl (Installation guide here)
- Helm (Installation guide here)
-
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate
-
Install the python requirements:
pip install -r app/requirements.txt
-
Run the application:
python app/app.py
and you can check in your browser the HTTP server in action by accessing
localhost:8080
.
First, make sure that you have configured the AWS CLI profile that will be used to create the infrastructure. If you're not using the default one, specify int the infra/main.tf
file your profile name on the aws provider definition.
Secondly, create the infrastructure necessary for this terraform backend project. We're defining in the infra/backend.tf
file that this project will use an S3 bucket called wiliot-locations-tfstate
to store the terraform state and a DynamoDB Table called wiliot-locations-tf-lock
. Please make sure to follow the instructions here to set the right IAM permissions. If you want different names for these AWS resources, or use already created ones, feel free to edit the infra/backend.tf
file.
Then, to build the necessary infrastructure, do the following:
-
Initialize the Terraform working directory:
cd infra terraform init
-
Validate the templates:
terraform validate
-
Check which resources terraform will create, change or destroy by running:
terraform plan
-
Create (or update) the infrastructure by running:
terraform apply
-
Build the docker image by running the following:
docker build . -t wiliot
-
Push the docker image to ECR. To do it, follow the instructions here, and please, name the
tag
image aslatest
. -
if you are accessing the cluster for the first time, run the following:
aws eks update-kubeconfig — region <region> — name <eks-cluster-name> — profile <aws-profile>
then confirm thatt you have access to the Kubernetes cluster by running:
kubectl config current-context
-
Create the kubernetes objects by running the following:
helm install wiliot-chart helm \ --values helm/values.yaml \ -n location \ --create-namespace
or if you have changes at the helm chart that you want do deploy, run the following:
helm upgrade wiliot-chart helm --values helm/values.yaml -n location
-
Get the URL to access the app externally by running the following:
kubectl get services wiliot-chart \ --namespace location \ --output jsonpath='{.status.loadBalancer.ingress[0].hostname}'
-
Delete all the Kubernetes resources by running:
helm uninstall wiliot-chart -n location
-
Destroy the infrastructure by running:
terraform destroy