This project demonstrates deploying a simple Python application on Amazon Elastic Kubernetes Service (EKS). The application is built using Flask and is containerized using Docker. The Kubernetes deployment includes a service to expose the application.
- A Flask-based Python app.
- Dockerized application with a lightweight
python:3.9-slim
image. - Kubernetes deployment and service configurations.
- Runs on EKS.
app.py
: The Flask application.Dockerfile
: Instructions for building the Docker image.requirements.txt
: Python dependencies.deployment.yaml
: Kubernetes Deployment manifest.service.yaml
: Kubernetes Service manifest.get_helm.sh
: Helper script for setting up Helm (optional).
- Amazon EKS Cluster: Set up an EKS cluster and configure
kubectl
to connect to it. - Docker: Install Docker to build the container image.
- kubectl: Ensure you have the Kubernetes command-line tool installed.
- Helm (optional): If needed for additional setup tools.
Use eksctl
to create an EKS cluster with the necessary node groups.
# Create EKS cluster
eksctl create cluster \
--name flask-rps-cluster \
--version 1.26 \
--region <your-region> \
--nodegroup-name flask-rps-nodes \
--node-type t3.medium \
--nodes 2 \
--nodes-min 1 \
--nodes-max 3 \
--managed
--name
: Specifies the name of the cluster.--version
: Kubernetes version for the cluster.--region
: AWS region where the cluster will be created.--nodegroup-name
: Name of the managed node group.--node-type
: Instance type for the nodes (e.g.,t3.medium
).--nodes
: Number of desired nodes (initial size).--nodes-min
/--nodes-max
: Auto-scaling configuration for the node group.--managed
: Uses managed node groups for easier management.
After creating the cluster, update your kubeconfig
file:
aws eks --region <your-region> update-kubeconfig --name flask-rps-cluster
Verify connection to the cluster:
kubectl get nodes
Save the following deployment manifest to deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-rps-deployment
labels:
app: flask-rps
spec:
replicas: 2
selector:
matchLabels:
app: flask-rps
template:
metadata:
labels:
app: flask-rps
spec:
containers:
- name: flask-rps
image: ibraheemcisse/flask-rps-app:latest
ports:
- containerPort: 5000
Apply it using:
kubectl apply -f deployment.yaml
Save the following service manifest to service.yaml
:
apiVersion: v1
kind: Service
metadata:
name: flask-rps-service
spec:
type: LoadBalancer
selector:
app: flask-rps
ports:
- protocol: TCP
port: 80
targetPort: 5000
Apply it using:
kubectl apply -f service.yaml
Once the LoadBalancer
service is deployed, get its external IP:
kubectl get svc
Access your app at http://<external-ip>
.
- Add Horizontal Pod Autoscaler (HPA) for scaling.
- Implement an Ingress resource for better traffic management.
- Enhance security with NetworkPolicies and Secrets.