Skip to content

Commit e8b0ea0

Browse files
author
Kenichiro Hiraiwa
committed
feat: support EKS Auto Mode and Karpenter
1 parent fb1dc64 commit e8b0ea0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+6843
-176
lines changed

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use an official Python runtime as a parent image
2-
FROM python:3.9-slim-buster as builder
2+
FROM python:3.11-slim-buster as builder
33

44
# Set environment variables
55
ENV PYTHONDONTWRITEBYTECODE=1 \
@@ -9,10 +9,10 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
99
WORKDIR /server
1010

1111
# Install system dependencies and Python dependencies
12-
COPY ./server/requirements.txt /server/
12+
COPY ./server/general/requirements.txt /server/
1313
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /server/wheels -r requirements.txt
1414

15-
FROM python:3.9-slim-buster as runner
15+
FROM python:3.11-slim-buster as runner
1616

1717
WORKDIR /server
1818

@@ -23,10 +23,10 @@ RUN pip install --no-cache-dir /server/wheels/* \
2323
&& pip install --no-cache-dir uvicorn
2424

2525
# Copy project
26-
COPY . /server/
26+
COPY ./server/general/ /server/
2727

2828
# Expose the port the app runs in
2929
EXPOSE 8000
3030

3131
# Define the command to start the container
32-
CMD ["uvicorn", "server.app.main:app", "--host", "0.0.0.0", "--port", "8000"]
32+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

Dockerfile.aws-secrets

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.11-slim-buster as builder
3+
4+
# Set environment variables
5+
ENV PYTHONDONTWRITEBYTECODE 1
6+
ENV PYTHONUNBUFFERED 1
7+
8+
# Set work directory
9+
WORKDIR /server
10+
11+
# Install system dependencies
12+
RUN apt-get update && apt-get install -y build-essential
13+
14+
# Install Python dependencies
15+
COPY ./server/aws-secrets/requirements.txt /server/
16+
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /server/wheels -r requirements.txt
17+
18+
FROM python:3.11-slim-buster as runner
19+
20+
WORKDIR /server
21+
22+
# Install system dependencies
23+
RUN apt-get update && apt-get install -y netcat
24+
25+
# Install Python dependencies
26+
COPY --from=builder /server/wheels /server/wheels
27+
COPY --from=builder /server/requirements.txt .
28+
RUN pip install --no-cache /server/wheels/*
29+
RUN pip install uvicorn
30+
31+
# Copy project
32+
COPY ./server/aws-secrets/ /server/
33+
34+
# Expose the port the app runs in
35+
EXPOSE 8000
36+
37+
# Define the command to start the container
38+
CMD uvicorn app.main:app --host 0.0.0.0 --port 8000

Dockerfile.opentelemetry

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.11-slim-buster as builder
3+
4+
# Set environment variables
5+
ENV PYTHONDONTWRITEBYTECODE 1
6+
ENV PYTHONUNBUFFERED 1
7+
8+
# Set work directory
9+
WORKDIR /server
10+
11+
# Install system dependencies
12+
RUN apt-get update && apt-get install -y build-essential
13+
14+
# Install Python dependencies
15+
COPY ./server/opentelemetry/requirements.txt /server/
16+
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /server/wheels -r requirements.txt
17+
18+
FROM python:3.11-slim-buster as runner
19+
20+
WORKDIR /server
21+
22+
# Install system dependencies
23+
RUN apt-get update && apt-get install -y netcat
24+
25+
# Install Python dependencies
26+
COPY --from=builder /server/wheels /server/wheels
27+
COPY --from=builder /server/requirements.txt .
28+
RUN pip install --no-cache /server/wheels/*
29+
RUN pip install uvicorn
30+
31+
# Copy project
32+
COPY ./server/opentelemetry/ /server/
33+
34+
# Expose the port the app runs in
35+
EXPOSE 8000
36+
37+
# Define the command to start the container
38+
CMD uvicorn app.main:app --host 0.0.0.0 --port 8000

docker-compose-opentelemetry.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
services:
2+
adotcollector:
3+
image: public.ecr.aws/aws-observability/aws-otel-collector:latest
4+
command: ["--config=/etc/adot-config.yaml"]
5+
env_file:
6+
- .env
7+
volumes:
8+
- ./server/opentelemetry/adot-collector-config/adot-config.yaml:/etc/adot-config.yaml
9+
- ~/.aws:/home/aoc/.aws
10+
networks:
11+
- webnet
12+
db:
13+
image: postgres:15
14+
env_file:
15+
- .env
16+
volumes:
17+
- ./server/db/init.sh:/docker-entrypoint-initdb.d/init.sh
18+
- postgres_data:/var/lib/postgresql@15/data # Persist PostgreSQL data
19+
networks:
20+
- webnet
21+
depends_on:
22+
- adotcollector
23+
web:
24+
build:
25+
context: .
26+
dockerfile: Dockerfile.opentelemetry
27+
image: fastapi-microservices:${IMAGE_VERSION}
28+
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
29+
volumes:
30+
- ./server/opentelemetry:/server
31+
ports:
32+
- 8000:8000
33+
depends_on:
34+
- db
35+
networks:
36+
- webnet
37+
env_file:
38+
- .env
39+
40+
networks:
41+
webnet:
42+
43+
volumes:
44+
postgres_data: # Define the volume for PostgreSQL data

docker-compose.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
version: '3.8'
2-
31
services:
42
db:
5-
image: postgres:13
3+
image: postgres:15
64
env_file:
75
- .env
86
volumes:
97
- ./server/db/init.sh:/docker-entrypoint-initdb.d/init.sh
10-
- postgres_data:/var/lib/postgresql/data # Persist PostgreSQL data
8+
- postgres_data:/var/lib/postgresql@15/data # Persist PostgreSQL data
119
networks:
1210
- webnet
1311

1412
web:
1513
build: .
1614
image: fastapi-microservices:${IMAGE_VERSION}
17-
command: uvicorn server.app.main:app --host 0.0.0.0 --port 8000
15+
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
1816
volumes:
19-
- .:/server
17+
- ./server/general:/server
2018
ports:
2119
- 8000:8000
2220
depends_on:
@@ -30,4 +28,4 @@ networks:
3028
webnet:
3129

3230
volumes:
33-
postgres_data: # Define the volume for PostgreSQL data
31+
postgres_data: # Define the volume for PostgreSQL data
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: fastapi-service
5+
namespace: my-cool-app
6+
spec:
7+
selector:
8+
app: fastapi-app
9+
ports:
10+
- protocol: TCP
11+
port: 80
12+
targetPort: 8000
13+
type: NodePort
14+
---
15+
apiVersion: apps/v1
16+
kind: Deployment
17+
metadata:
18+
name: fastapi-deployment
19+
namespace: my-cool-app
20+
spec:
21+
replicas: 1
22+
selector:
23+
matchLabels:
24+
app: fastapi-app
25+
template:
26+
metadata:
27+
labels:
28+
app: fastapi-app
29+
spec:
30+
containers:
31+
- name: web
32+
image: 012345678901.dkr.ecr.us-west-2.amazonaws.com/fastapi-microservices:1.0
33+
ports:
34+
- containerPort: 8000
35+
resources:
36+
requests:
37+
cpu: "200m"
38+
memory: "200Mi"
39+
limits:
40+
cpu: "1000m"
41+
memory: "1000Mi"
42+
serviceAccount: fastapi-deployment-sa
43+
---
44+
apiVersion: networking.k8s.io/v1
45+
kind: Ingress
46+
metadata:
47+
name: fastapi-ingress
48+
namespace: my-cool-app
49+
annotations:
50+
alb.ingress.kubernetes.io/scheme: internet-facing
51+
alb.ingress.kubernetes.io/target-type: ip
52+
spec:
53+
ingressClassName: alb
54+
rules:
55+
- http:
56+
paths:
57+
- path: /
58+
pathType: Prefix
59+
backend:
60+
service:
61+
name: fastapi-service
62+
port:
63+
number: 80

eks/create-automode-python.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: eksctl.io/v1alpha5
2+
kind: ClusterConfig
3+
4+
# The metadata section is for specifying essential details about your EKS cluster.
5+
metadata:
6+
# name: The name of your EKS cluster.
7+
name: automode-quickstart
8+
# region: The AWS region where your EKS cluster will be created.
9+
region: us-west-2
10+
# version: The Kubernetes version to use for your EKS cluster.
11+
version: "1.32"
12+
13+
autoModeConfig:
14+
# enabled: The cluster enables Auto Mode.
15+
enabled: true
16+
17+
# The IAM section is for managing IAM roles and service accounts for your cluster.
18+
iam:
19+
# withOIDC: Enable the creation of the OIDC provider associated with the cluster to allow for IAM Roles for Service Accounts (IRSA).
20+
withOIDC: true
21+
serviceAccounts:
22+
- metadata:
23+
name: adot-collector
24+
# this is to create the namespace my-cool-app
25+
namespace: my-cool-app
26+
labels: {aws-usage: "application"}
27+
attachPolicyARNs:
28+
- "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess"
29+
30+
# The cloudWatch section is for configuring logging for your cluster.
31+
cloudWatch:
32+
clusterLogging:
33+
# enableTypes: Which types of logs to enable. '*' represents all types.
34+
enableTypes: ["*"]
35+
# logRetentionInDays: The number of days to retain log events.
36+
logRetentionInDays: 30

eks/create-fargate-python.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.

eks/create-mng-python.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ metadata:
77
# name: The name of your EKS cluster.
88
name: managednode-quickstart
99
# region: The AWS region where your EKS cluster will be created.
10-
region: us-east-1
10+
region: us-west-2
1111
# version: The Kubernetes version to use for your EKS cluster.
12-
version: "1.29"
12+
version: "1.32"
1313

1414
# The IAM section is for managing IAM roles and service accounts for your cluster.
1515
iam:
@@ -28,7 +28,7 @@ iam:
2828
namespace: my-cool-app
2929
labels: {aws-usage: "application"}
3030
attachPolicyARNs:
31-
- "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess"
31+
- "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess"
3232

3333
# The managedNodeGroups section is for configuring your EKS managed node groups.
3434
managedNodeGroups:

eks/deploy-app-python.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ spec:
2929
spec:
3030
containers:
3131
- name: web
32-
image: 012345678901.dkr.ecr.us-east-1.amazonaws.com/fastapi-microservices:1.0
32+
image: 012345678901.dkr.ecr.us-west-2.amazonaws.com/fastapi-microservices:1.0
3333
ports:
3434
- containerPort: 8000
3535
envFrom:

0 commit comments

Comments
 (0)