Skip to content

Commit

Permalink
Add k8s and healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
vectornguyen76 committed Nov 24, 2023
1 parent 8a3d1ba commit cda37b7
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ architectures
*.csv
data.csv

helm-charts

image-search-engine/assets/uploaded_images/*
!image-search-engine/assets/uploaded_images/.gitkeep

Expand Down
8 changes: 1 addition & 7 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
JWT_ALG=HS256
JWT_EXP=21000
JWT_SECRET=SECRET
DATABASE_URL=postgresql+asyncpg://db_user:db_password@localhost/db_dev

SITE_DOMAIN=127.0.0.1
SECURE_COOKIES=false

CORS_HEADERS=["*"]
CORS_ORIGINS=["http://localhost:3000"]
ENVIRONMENT=DEVELOP

TEXT_SEARCH_URL=http://localhost:8000
IMAGE_SEARCH_URL=http://localhost:7000
8 changes: 0 additions & 8 deletions backend/.env.local
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
JWT_ALG=HS256
JWT_EXP=21000
JWT_SECRET=SECRET
DATABASE_URL=postgresql+asyncpg://db_user:db_password@db_service/db_dev

SITE_DOMAIN=127.0.0.1
SECURE_COOKIES=false

ENVIRONMENT=LOCAL

CORS_HEADERS=["*"]
CORS_ORIGINS=["http://localhost:3000"]

TEXT_SEARCH_URL=http://text-search-engine:8000
IMAGE_SEARCH_URL=http://image-search-engine:7000

Expand Down
6 changes: 3 additions & 3 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ async def startup_event():
await service.init_user(email=settings.ADMIN_EMAIL)


@app.get("/healthcheck", include_in_schema=False)
async def healthcheck() -> dict[str, str]:
return {"status": "ok"}
@app.get("/healthz")
async def healthcheck() -> bool:
return True


app.include_router(auth_router, prefix="/auth", tags=["Auth"])
Expand Down
2 changes: 1 addition & 1 deletion backend/src/auth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class AuthConfig(BaseSettings):
JWT_ALG: str
JWT_ALG: str = "HS256"
JWT_SECRET: str
JWT_EXP: int = 5 # minutes

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ services:

backend_service:
container_name: backend_container
image: backend_image
image: vectornguyen76/backend_image
build:
context: ./backend
dockerfile: Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion image-search-engine/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)


@app.get("/")
@app.get("/healthz")
def healthcheck() -> bool:
"""Check the server's status."""
return True
Expand Down
23 changes: 23 additions & 0 deletions kubernetes/backend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-deployment
spec:
replicas: 1
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend-container
image: vectornguyen76/backend_image:latest
livenessProbe:
httpGet:
path: /healthz
port: 5000
initialDelaySeconds: 3
periodSeconds: 3
12 changes: 12 additions & 0 deletions kubernetes/backend-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
selector:
app: backend
type: LoadBalancer
ports:
- protocol: TCP
port: 5000
targetPort: 5000
10 changes: 10 additions & 0 deletions kubernetes/database-persistent-volume-claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-persistent-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
6 changes: 6 additions & 0 deletions kubernetes/image-search-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ spec:
containers:
- name: image-search-container
image: vectornguyen76/image-search-engine:latest
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
env:
- name: QDRANT_HOST
value: "qdrant-vector-database.default"
17 changes: 17 additions & 0 deletions kubernetes/ingress-nginx-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx-service
namespace: ingress-nginx
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /backend
pathType: Prefix
backend:
service:
name: backend-service
port:
number: 3000
11 changes: 11 additions & 0 deletions kubernetes/postgres-cluster-ip-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: postgres-cluster-ip-service
spec:
type: ClusterIP
selector:
component: postgres
ports:
- port: 5432
targetPort: 5432
33 changes: 33 additions & 0 deletions kubernetes/postgres-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres-deployment
spec:
replicas: 1
selector:
matchLabels:
component: postgres
template:
metadata:
labels:
component: postgres
spec:
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: database-persistent-volume-claim
containers:
- name: postgres
image: postgres
ports:
- containerPort: 5432
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
subPath: postgres
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: pgpassword
key: PGPASSWORD
2 changes: 1 addition & 1 deletion text-search-engine/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
searcher = ElasticSearcher()


@app.get("/")
@app.get("/healthz")
async def healthcheck() -> bool:
"""Check the server's status."""
return await searcher.elasticsearch.cluster.health()
Expand Down

0 comments on commit cda37b7

Please sign in to comment.