This project details the deployment process of a Flask application named Twoge onto an AWS EKS cluster using Kubernetes. It includes continuous integration and delivery (CI/CD) through GitHub Actions, orchestrating the build and deployment process automatically upon code pushes to the repository.
Before you begin, ensure you have the following installed:
- Docker
- Kubernetes
- kubectl
- AWS CLI (configured for EKS)
- Minikube (for local testing)
- GitHub account (for CI/CD)
Below is the architecture diagram for the Twoge Flask application deployment using Kubernetes on AWS EKS, illustrating how components interact within the cloud environment.
-
Clone the Repository
git clone https://github.com/stephanlamoureux/twoge-kubernetes.git
-
Build the Docker Image
Navigate to the cloned repository and build the Docker image:
docker build -t twoge .
-
Run Docker Compose
Start the services defined in
docker-compose.yml
:docker-compose up -d
-
Environment Variables
Create a
.env
file based on the provided example to configure the database credentials:DB_USER=twoge DB_PASSWORD=twoge DB_NAME=twoge DB_PORT=5432 DB_HOST=twoge-db DB_TYPE=postgresql
-
Kubernetes Namespace
Apply the namespace configuration:
kubectl apply -f namespace.yml
-
Resource Quota
Set resource limits for the namespace:
kubectl apply -f quota.yml
-
Persistent Volume and Claim
Apply the PV and PVC to manage storage:
kubectl apply -f pv.yml kubectl apply -f pvc.yml
-
Deploy PostgreSQL
Deploy the PostgreSQL database with secrets and services:
kubectl apply -f postgres-deployment.yml kubectl apply -f postgres-secrets.yml kubectl apply -f postgres-service.yml
-
Deploy Twoge Application
Deploy the Twoge Flask application:
kubectl apply -f twoge-deployment.yml kubectl apply -f twoge-service.yml
-
Apply ConfigMap
Apply the configuration for the application:
kubectl apply -f twoge-configmap.yml
The project uses GitHub Actions for continuous integration and continuous deployment (CI/CD), automating the process of building the Docker image and deploying it to the AWS EKS cluster.
-
EKS-CICD.yml Workflow
The workflow defined in
EKS-CICD.yml
triggers on pushes to theeks
branch. It performs the following steps:-
CI Job:
- Checks out the repo.
- Sets up Docker buildx.
- Logs in to DockerHub.
- Builds and pushes the Docker image to DockerHub.
-
CD Job:
- Checks out the repo.
- Configures AWS credentials.
- Updates kubeconfig for EKS.
- Deploys the application to EKS using
kubectl apply
.
-
-
Secrets and Environment Variables
The workflow utilizes secrets for Docker and AWS credentials, ensuring secure access to external services without hardcoding sensitive information in the repository.
-
Launch a Local Server
For local testing with Minikube:
minikube service twoge-service --url -n steve
-
View Logs
Check the logs for a specific pod:
kubectl logs <pod-name> -n steve
-
Delete Pods
Remove specific pods:
kubectl delete pods <pod-name> -n steve
-
Cleanup
Delete all resources in the namespace:
kubectl delete --all -f . -n steve
-
Node Information
Get detailed information about the nodes:
kubectl describe nodes