The application endpoints:
-
/
-
Accepts GET requests.
-
Returns a json body response
-
Example use:
curl 127.0.0.1:8080
-
Example response:
{"message": "Hello Smile"}
-
-
/healthy
-
Accepts a GET request
-
Returns 200 if the application is ready.
-
Returns 500 if the application is not ready
-
Example use:
curl 127.0.0.1:8080/healthy
-
The App is packaged as a docker image and can be deployed on kubernetes. The basic manifests required to deploy the application to a kubernetes cluster are provided in the k8s
folder
└── k8s
├── deployment.yaml
├── svc.yaml
├── hpa.yaml
├── namespace.yaml
└── sa.yaml
ServiceAccount
Deployment
Service
HorizontalPodAutoscaler
Namespace
VPC|Subnets|NatGateways
EKS Cluster
ECR Repository
IAM Resources
NOTE: Terraform state is stored locally !!
Docker >= 1.24
with ComposeTerraform >= 1.2.3
AWS cli >= 2.13.11
yq >= 4.40.5
kubectl >= 1.28.2
Tip: Use the helper script to run all deployment steps with 1 command. You must first set environment variables in step 1.
By default the script will use IMAGE_TAG=1.0.0
, to use a different tag run export IMAGE_TAG=<preferred tag>
first.
./helper.sh k8s-deploy
-
Set up AWS credentials. You can read how here
Recommended that you use the option of setting environment variables for this demo
export AWS_SECRET_ACCESS_KEY=<Actual Secret Access Key> export AWS_ACCESS_KEY_ID=<Actual Access Key> export TF_VAR_aws_region=<Actual AWS Region>
-
Change directory to the
terraform
foldercd terraform
-
Initialize Terraform configuration by using the command below
terraform init
-
Plan Terraform configuration by using the command below
terraform plan
-
Apply Terraform configuration by using the command below
terraform apply
Confirm the planned changes by entering
yes
Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes
-
Set the IMAGE environment variable
export IMAGE_REPO=$(terraform output -raw container_repository) export IMAGE_REGISTRY=$(echo ${IMAGE_REPO}| cut -d '/' -f1) export IMAGE_TAG=1.0.0 export IMAGE=$IMAGE_REPO:$IMAGE_TAG
-
Build and Push image to container registry
# change directory cd ../ # build image docker build -t simple-app:$IMAGE_TAG . # tag image docker tag simple-app:$IMAGE_TAG $IMAGE # login to image registry aws ecr get-login-password --region $TF_VAR_aws_region | docker login --username AWS --password-stdin $IMAGE_REGISTRY # push image to registry docker push $IMAGE
-
Deploy kubernetes manifests
# set image and tag in mainifest yq e -i '.spec.template.spec.containers[0].image=env(IMAGE)' k8s/deployment.yaml # set kube context aws eks update-kubeconfig --region $TF_VAR_aws_region --name main --alias main # apply namespace manifests kubectl apply -f k8s/namespace.yaml # apply other manifests kubectl apply -f k8s/
Tip: Use helper script to run all cleanup steps with 1 command.
./helper.sh k8s-clean
-
Follow the steps below to cleanup the created resources
# delete kubernetes resources kubectl delete -f k8s/ # Force delete ECR Repository using aws cli. (Terraform cannot force delete because the repository is not empty) aws ecr delete-repository --repository-name simple-app --force --region $TF_VAR_aws_region # Destroy terraform resources cd terraform terraform destroy
-
Confirm that you want to delete the resources
Do you really want to destroy all resources? Terraform will destroy all your managed infrastructure, as shown above. There is no undo. Only 'yes' will be accepted to confirm. Enter a value: yes
Docker
with Compose- Port (8080)
To deploy as a local docker container you can use the helper script provided by running the below command in the project root directory
./helper.sh run
The script will do the following:
- Builds the docker image with tag
simple-app:latest
- Runs a local container with the image
- Exposes the container for local network traffic on port
8080
Access the application on http://localhost:8080
You can clean up the local docker container by running
./helper.sh clean
python3
python3-pip
- Port (8080)
To run the app locally in debug mode you can use the helper script provided by running the below command in the project root directory
./helper.sh debug
The script will do the following:
- Runs the python app locally on port 8080
Access the application on http://localhost:8080
Some features that should be implemented in the future
- Add Node Autoscaling Capability to the cluster (Karpenter, Cluster Autoscaler)
- Implement a Service Mesh
- Observability Dashboard for monitoring resources in the cluster
- Policy As Code Tooling (OPA, Kyverno)
- Implement Topology Spread Strategy for Nodes across Multiple AZs
- Deploy an Ingress Controller (Possible use Mesh Gateway)