Skip to content
Merged
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
37 changes: 0 additions & 37 deletions .github/workflows/build.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
build
.gradle
.vscode

*.log
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# MAC
**/.DS_Store

# internal
*internal*

# k8s
python-ping-api.yaml

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
104 changes: 2 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,2 @@
# Python sample project for EKS

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=DevSecOpsSamples_eks-python-api&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=DevSecOpsSamples_eks-python-api) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=DevSecOpsSamples_eks-python-api&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=DevSecOpsSamples_eks-python-api)

The sample project to deploy Python REST API application, Service, HorizontalPodAutoscaler, Ingress on EKS.

- [app.py](app/app.py)
- [Dockerfile](app/Dockerfile)
- [python-ping-api-template.yaml](app/python-ping-api-template.yaml)

---

## Prerequisites

### Installation

- [Installing or updating the latest version of the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)

### Set AWS configurations

Set AWS configurations with `aws configure` for default region and keys:

```bash
aws configure
```

```bash
AWS Access Key ID [None]: <enter-your-access-key>
AWS Secret Access Key [None]: <enter-your-secret-key>
Default region name [None]: us-east-1
Default output format [None]:
```

```bash
aws configure get default.region
us-east-1
```

---

## Create an EKS cluster and deploy AWS Load Balancer Controller

Refer to the https://github.com/DevSecOpsSamples/eks-eksctl page.

## Set environment variables

```bash
REGION=$(aws configure get default.region)
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
CLUSTER_NAME=$(kubectl config current-context | cut -d '@' -f2 | cut -d '.' -f1)
echo "REGION: ${REGION}, ACCOUNT_ID: ${ACCOUNT_ID}, CLUSTER_NAME: ${CLUSTER_NAME}"
```

## Deploy python-ping-api

Build and push to ECR:

```bash
cd ../app
docker build -t python-ping-api . --platform linux/amd64

docker tag python-ping-api:latest ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/python-ping-api:latest

aws ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com

docker push ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/python-ping-api:latest
```

Create and deploy K8s Deployment, Service, HorizontalPodAutoscaler, Ingress using the [python-ping-api-template.yaml](app/python-ping-api-template.yaml) template file.

```bash

sed -e "s|<account-id>|${ACCOUNT_ID}|g" python-ping-api-template.yaml | sed -e "s|<region>|${REGION}|g" > python-ping-api.yaml
cat python-ping-api.yaml

kubectl apply -f python-ping-api.yaml
```

It may take around 5 minutes to create a load balancer, including health checking.

Confirm that Pod and ALB logs.

```bash
kubectl logs -l app=python-ping-api

kubectl describe pods

kubectl logs -f $(kubectl get po -n kube-system | egrep -o 'aws-load-balancer-controller-[A-Za-z0-9-]+') -n kube-system
```

---

## Cleanup

```bash
kubectl delete -f app/python-ping-api.yaml

```

## References

- [Application load balancing on Amazon EKS](https://docs.aws.amazon.com/eks/latest/userguide/alb-ingress.html)
# _eks-python-api
Python REST API sample for EKS
14 changes: 0 additions & 14 deletions app/Dockerfile

This file was deleted.

37 changes: 0 additions & 37 deletions app/app.py

This file was deleted.

17 changes: 0 additions & 17 deletions app/build.sh

This file was deleted.

2 changes: 0 additions & 2 deletions app/gunicorn.config.py

This file was deleted.

101 changes: 0 additions & 101 deletions app/python-ping-api-template.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions app/requirements.txt

This file was deleted.

26 changes: 0 additions & 26 deletions build.gradle

This file was deleted.

Binary file removed gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 0 additions & 5 deletions gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Loading