Skip to content

Commit

Permalink
Deploy FastAPI app to k8
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosribas committed May 10, 2024
1 parent a9475eb commit ecd2a57
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 0 deletions.
23 changes: 23 additions & 0 deletions kubernetes/helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
14 changes: 14 additions & 0 deletions kubernetes/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v2
name: helm
description: A Helm chart for Kubernetes

type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.16.0
73 changes: 73 additions & 0 deletions kubernetes/helm/templates/nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: {{ .Values.nginxPort }}
targetPort: {{ .Values.nginxTargetPort }}
protocol: TCP
selector:
app: rfam-batch-search
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
local.conf: |-
# FastAPI application
upstream rfam-batch-search {
server rfam-batch-search:{{ .Values.port }};
}
server {
listen {{ .Values.nginxTargetPort }};
location / {
# everything is passed to FastAPI
proxy_pass http://rfam-batch-search;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: {{ .Values.nginxReplicas }}
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
annotations:
rollme: {{ randAlphaNum 5 | quote }}
spec:
containers:
- image: nginx:1.26-alpine
name: nginx
resources:
requests:
memory: {{ .Values.nginxRequestsMemory }}
cpu: {{ .Values.nginxRequestsCPU }}
limits:
memory: {{ .Values.nginxLimitsMemory }}
ports:
- containerPort: {{ .Values.nginxTargetPort }}
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/conf.d/local.conf
subPath: local.conf
restartPolicy: Always
volumes:
- name: nginx-config
configMap:
name: nginx-config
48 changes: 48 additions & 0 deletions kubernetes/helm/templates/rfam-batch-search.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: v1
kind: Service
metadata:
name: rfam-batch-search
labels:
app: rfam-batch-search
spec:
type: NodePort
ports:
- port: {{ .Values.port }}
targetPort: {{ .Values.port }}
protocol: TCP
selector:
app: rfam-batch-search
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rfam-batch-search
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: rfam-batch-search
template:
metadata:
labels:
app: rfam-batch-search
annotations:
rollme: {{ randAlphaNum 5 | quote }}
spec:
containers:
- image: ghcr.io/rfam/rfam-batch-search:{{ .Values.branch }}
name: rfam-batch-search
imagePullPolicy: Always
ports:
- containerPort: {{ .Values.port }}
resources:
requests:
memory: {{ .Values.requestsMemory }}
cpu: {{ .Values.requestsCPU }}
limits:
memory: {{ .Values.limitsMemory }}
envFrom:
- secretRef:
name: email
- configMapRef:
name: {{ .Values.proxy }}
18 changes: 18 additions & 0 deletions kubernetes/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Proxy
proxy: proxy-hh

# Nginx
nginxPort: 8000
nginxTargetPort: 80
nginxReplicas: 2
nginxRequestsMemory: "2000Mi"
nginxRequestsCPU: "1000m"
nginxLimitsMemory: "4000Mi"

# Rfam batch search
branch: main
port: 8000
replicas: 4
requestsMemory: "4000Mi"
requestsCPU: "1000m"
limitsMemory: "6000Mi"
10 changes: 10 additions & 0 deletions kubernetes/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "rfam",
"labels": {
"name": "rfam"
}
}
}
10 changes: 10 additions & 0 deletions kubernetes/proxy-hh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: proxy-hh
data:
HTTP_PROXY: http://hh-wwwcache.ebi.ac.uk:3128
HTTPS_PROXY: http://hh-wwwcache.ebi.ac.uk:3128
http_proxy: http://hh-wwwcache.ebi.ac.uk:3128
https_proxy: http://hh-wwwcache.ebi.ac.uk:3128
no_proxy: localhost,.cluster.local
9 changes: 9 additions & 0 deletions kubernetes/quota-mem-cpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ResourceQuota
metadata:
name: rfam
spec:
hard:
requests.cpu: "8"
requests.memory: 20Gi
limits.memory: 32Gi

0 comments on commit ecd2a57

Please sign in to comment.