Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions website/docs/python/containers/about-multiservices.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The `builder` uses a Python base image, installs system dependencies, copies the

```dockerfile
# Use an official Python runtime as a parent image
FROM python:3.9-slim-buster as builder
FROM python:3.11-slim-buster as builder

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
Expand All @@ -37,7 +37,7 @@ The `runner` starts with a Python base image, installs system dependencies like

```dockerfile
# Use an official Python runtime as a parent image
FROM python:3.9-slim-buster as builder
FROM python:3.11-slim-buster as builder

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
Expand All @@ -50,7 +50,7 @@ WORKDIR /server
COPY ./server/requirements.txt /server/
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /server/wheels -r requirements.txt

FROM python:3.9-slim-buster as runner
FROM python:3.11-slim-buster as runner

WORKDIR /server

Expand Down Expand Up @@ -101,12 +101,12 @@ The **db** service uses the official PostgreSQL image available on DockerHub. It

```
db:
image: postgres:13
image: postgres:15
env_file:
- .env
volumes:
- ./server/db/init.sh:/docker-entrypoint-initdb.d/init.sh
- postgres_data:/var/lib/postgresql/data
- postgres_data:/var/lib/postgresql@15/data
networks:
- webnet
```
Expand Down
2 changes: 1 addition & 1 deletion website/docs/python/containers/upload-ecr.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This lab shows the process of pushing Docker images to Amazon ECR using the Fast
Create a new private Amazon ECR repository:

```bash
aws ecr create-repository --repository-name fastapi-microservices
aws --region ${AWS_REGION} ecr create-repository --repository-name fastapi-microservices
```

## 2. Logging into Amazon ECR
Expand Down
8 changes: 4 additions & 4 deletions website/docs/python/eks/about-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ The **[deploy-app-python.yaml](https://github.com/aws-samples/python-fastapi-dem

- **Service:** The service in the manifest exposes the FastAPI application running on the EKS cluster to the external world. It routes incoming traffic on port 80 to the FastAPI application's listening port (8000). The service uses a NodePort type which automatically allocates a port from the NodePort range (default: 30000-32767) and proxies traffic on each node from that port into the Service. This allows for the Service to be externally accessible to Application and Network Load Balancers.
- **Deployment:** The deployment in the manifest dictates how the FastAPI application should be deployed onto the EKS cluster. It specifies the number of replicas (i.e. the number of application instances that should be running), the container image to be used, and the necessary environment variables from a secret. It sets resource requests and limits for the containers to ensure the application gets the necessary resources.
- **Ingress:** The Ingress in the manifest provides HTTP route management for services within the EKS cluster. It routes incoming traffic to the FastAPI service based on the request path. In this scenario, all requests are directed to the FastAPI service. The Ingress configuration in this file is specifically set up for AWS using the AWS Load Balancer Controller, configuring an Application Load Balancer (ALB) that is internet-facing and employs an IP-based target type.
- **Ingress:** The Ingress in the manifest provides HTTP route management for services within the EKS cluster. It routes incoming traffic to the FastAPI service based on the request path. In this scenario, all requests are directed to the FastAPI service. When using Managed node groups, you'll need to use the AWS Load Balancer Controller, which configures an Application Load Balancer (ALB) that is internet-facing and employs an IP-based target type. On the other hand, when using EKS Auto Mode, you'll use the EKS Auto Mode instead, eliminating the need for separate installation and management of the AWS Load Balancer Controller.

## PostgreSQL - StatefulSet, Service, StorageClass, and VolumeClaimTemplates

## PostgreSQL - StatefulSet, Service, and VolumeClaimTemplates
The **[deploy-db-python.yaml](https://github.com/aws-samples/python-fastapi-demo-docker/blob/main/eks/deploy-db-python.yaml)** file is used for the deployment of the PostgreSQL database and consists of four primary resources:

- **StorageClass**: The StorageClass in the manifest is specific to AWS EBS (Elastic Block Store) and allows dynamic provisioning of storage for PersistentVolumeClaims. The EBS provisioner enables PersistentVolumes to have a stable and resilient storage solution for our PostgreSQL database.
- **Service:** The Service in the manifest exposes the PostgreSQL database within the EKS cluster, facilitating the FastAPI application to access it. The Service listens on port 5432, which is the default PostgreSQL port. The Service is headless (as indicated by `clusterIP: None`), meaning it enables direct access to the Pods in the StatefulSet rather than load balancing across them.
- **StatefulSet:** The StatefulSet in the manifest manages the PostgreSQL database deployment. A StatefulSet is used instead of a Deployment as it ensures each Pod receives a stable network identity and stable storage, which is essential for databases. The PostgreSQL container uses a Secret to obtain its environment variables and mounts a volume for persistent storage.
- **VolumeClaimTemplates**: The volumeClaimTemplates within the StatefulSet definition request a specific storage amount for the PostgreSQL database. It requests a storage capacity of 1Gi with [ReadWriteOnce](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes) access mode, and it uses the AWS EBS StorageClass defined in this manifest. This ensures that each Pod within the StatefulSet gets its own PersistentVolume, guaranteeing the database data remains persistent across pod restarts, and the data is accessible from any node in the EKS cluster.
- **VolumeClaimTemplates**: The volumeClaimTemplates within the StatefulSet definition request a specific storage amount for the PostgreSQL database. It requests a storage capacity of 1Gi with [ReadWriteOnce](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes) access mode, and it uses the AWS EBS StorageClass defined in this manifest. This ensures that each Pod within the StatefulSet gets its own PersistentVolume, guaranteeing the database data remains persistent across pod restarts, and the data is accessible from any node in the EKS cluster.
14 changes: 11 additions & 3 deletions website/docs/python/eks/access-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import GetEnvVars from '../../../src/includes/get-env-vars.md';

## Objective

This guide aims to guide you through the process of accessing your microservices deployed onto EKS cluster. By using ingress object we were able to expose FastAPI service through Application Loadbalancer. The Management of Application Loadbalancer is done by AWS Loadbalancer controller through ingress manifest.
This guide aims to guide you through the process of accessing your microservices deployed onto EKS cluster. By using ingress object we were able to expose FastAPI service through Application Loadbalancer. The management of the Application Load Balancer through ingress manifest is handled differently depending on your cluster configuration: for EKS Auto Mode clusters, the ALB is managed by EKS Auto Mode, while for clusters using Managed node groups, the ALB is managed by the AWS Load Balancer Controller.

## Prerequisites

Expand All @@ -23,6 +23,14 @@ Before we try to access our application, we need to ensure that all of our pods
kubectl get pods -n my-cool-app
```

The expected output should look like this:

``` bash
NAME READY STATUS RESTARTS AGE
fastapi-deployment-9776bd4c7-t8xkm 1/1 Running 0 99s
fastapi-postgres-0 1/1 Running 0 8m28s
```

All your pods should be in the "Running" state. If they're not, you will need to troubleshoot the deployment before proceeding.

## 2. Getting the ALB URL
Expand All @@ -42,7 +50,7 @@ fastapi-ingress <none> * k8s-mycoolap-fastapii-8114c40e9c-860636650.us

## 3. Accessing the FastAPI Service

In the previous lab exercise, we used the AWS Load Balancer Controller (LBC) to dynamically provision an [Application Load Balancer (ALB)](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html). Note that it takes several minutes or more before the ALB has finished provisioning.
In the previous lab exercise, we used EKS Auto Mode or AWS Load Balancer Controller (LBC) to dynamically provision an [Application Load Balancer (ALB)](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html). Note that it takes several minutes or more before the ALB has finished provisioning.

1. **Check the status**: Open the [Load Balancers](https://console.aws.amazon.com/ec2/#LoadBalancers:) page on the Amazon EC2 console and select the AWS Region in which your Amazon EKS cluster resides. Next, select your ALB name, such as `k8s-mycoolap-fastapii-8004c40e9c`.
2. **Open the app**: Open a new tab in your browser paste the ALB link, such as `k8s-mycoolap-fastapii-8114c40e9c-860636650.us-west-2.elb.amazonaws.com`. You should see the welcome page:
Expand All @@ -57,4 +65,4 @@ To confirm that everything is functioning as expected, attempt to add a book by

## Conclusion

This guide has walked you through the steps necessary to access the FastAPI service deployed on an EKS cluster. We've shown you how to check the status of your pods and verify your setup by interacting with the FastAPI service.
This guide has walked you through the steps necessary to access the FastAPI service deployed on an EKS cluster. We've shown you how to check the status of your pods and verify your setup by interacting with the FastAPI service.
Loading