Notejam flask application with postgres DB on RDS. Kubernetes Deployment on AWS EKS by provisioning with Terraform. Github Actions to build docker images to be pushed to AWS ECR.
# update dotenv file under notejam-flask with your credentials and run docker-compose
mv notejam-flask/dotenv notejam-flask/.env
docker-compose --env-file notejam-flask/.env up -d
- notejam application can be visited at port 5000
- You can run tests in docker container:
docker exec -it notejam_web sh
python tests.py
- Update terraform.tfvars with your own config variables and ssh-key. When ready, initiate terraform:
terraform -chdir=terraform init
- Make all the scripts executable:
find . -maxdepth 1 -type f -name "*.sh" -exec chmod +x {} \;
- Create AWS Secret for DB Credentials:
./1_create_db_creds.sh
- Create Route 53 DNS Zone if not exists:
./2_route53.sh
- Provision AWS with terraform:
terraform -chdir=terraform apply
- There is a bastion server provisioned as well to login to EKS worker nodes through private network. Login with your ssh-key that you've created:
ssh -i "ssh-key" ubuntu@$(terraform -chdir=terraform output -raw bastion_public_ip)
- Kubectl config setup:
./3_EKS_setup.sh
- Check that you are able to connect to k8s cluster:
kubectl get nodes
- Check your access to RDS
# Note the db_endpoint and port
terraform -chdir=terraform output db_endpoint
# Run a temporary busybox pod
kubectl run -it --rm busybox --image=busybox --restart=Never -- sh
# Check if you can connect to db_endpoint instance with telnet
telnet db_endpoint port
- Login to AWS ECR service:
aws ecr get-login-password --region $(terraform -chdir=terraform output -raw aws_region) \
| docker login --username AWS --password-stdin $(terraform -chdir=terraform output -raw registry_backend)
- Associate EKS cluster with OpenID Connect Provider (Guide):
./4_OIDC_associate.sh
- Install cert-manager (Guide)
./5_cert_manager.sh
- make sure that pods are in Running state:
kubectl -n cert-manager get pods
- Install Load Balancer Controller (Guide):
./6_LB_controller.sh
- Create cert-manager cluster issuer (Guide and Link):
./7_cluster_issuer.sh
- Create Namespaces:
kubectl apply -f k8s/namespaces.yaml
- Create Secrets for Postgres Credentials (Alternatively, a more robust and secure solution would be to use AWS Secrets Manager service → Guide):
./8_k8s_secrets.sh
- This will be created under 'staging' namespace since I will be deploying the application under this namespace. This should be modified to be used in a CI/CD system.
- Github actions will build a notejam image and push to AWS ECR after each git push to master branch.
- Setting up the github actions scripts are based on this guide
- Run
deploy_k8s_alb.sh
to create a deployment and expose it with a k8s service and ALB. - Import the Key and Cert to ACM and add FQDN to Route53
# Run below script to push the key and cert to ACM in ingress file:
./9_sync_tls_resources.sh
Run below to update DNS record to point to ALB:
./10_route53_recordset.sh