Skip to content

Kubernetes infra #1088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8d12954
feat(chart): create kube infra
rtrompier Apr 29, 2024
0271926
feat(chart): create kube infra
rtrompier Apr 29, 2024
d7ce041
feat(chart): create kube infra
rtrompier Apr 29, 2024
d6df8b7
feat(chart): create kube infra
rtrompier Apr 29, 2024
26c22fb
feat(chart): create kube infra
rtrompier Apr 29, 2024
bfd6b45
feat(chart): create kube infra
rtrompier Apr 29, 2024
aa78161
feat(chart): create kube infra
rtrompier Apr 29, 2024
a70d558
feat(chart): create kube infra
rtrompier Apr 29, 2024
22f15df
feat(chart): create kube infra
rtrompier Apr 29, 2024
5d71087
feat(chart): create kube infra
rtrompier Apr 29, 2024
e41a312
feat(chart): create kube infra
rtrompier Apr 29, 2024
25b3884
feat(chart): create kube infra
rtrompier Apr 29, 2024
6c4e774
feat(chart): add hpa
rtrompier Apr 30, 2024
6893e26
feat(chart): add service monitor
rtrompier Apr 30, 2024
2871e0b
feat(chart): test
rtrompier Apr 30, 2024
cdbff67
feat(chart): fix lint
rtrompier Apr 30, 2024
26a30ba
feat(chart): remove pm2
rtrompier Apr 30, 2024
d6f948b
feat(chart): fix
rtrompier Apr 30, 2024
8f72697
feat(chart): fix
rtrompier Apr 30, 2024
f1e0e20
feat(chart): fix
rtrompier Apr 30, 2024
62cfed9
feat(chart): fix
rtrompier Apr 30, 2024
f0b5ff8
Merge branch 'main' into feat/infra
rtrompier Apr 30, 2024
24b2e67
feat(chart): fix
rtrompier Apr 30, 2024
5061c54
feat(chart): fix
rtrompier Apr 30, 2024
0a13325
feat(chart): fix
rtrompier Apr 30, 2024
697d0df
feat(chart): fix
rtrompier Apr 30, 2024
2d6ec94
feat(chart): fix
rtrompier Apr 30, 2024
13c8184
feat(chart): fix
rtrompier Apr 30, 2024
9cdf547
Merge branch 'main' into feat/infra
rtrompier Apr 30, 2024
18364da
feat(chart): fix
rtrompier Apr 30, 2024
9b563c1
feat(chart): fix
rtrompier Apr 30, 2024
50ed513
feat(chart): fix
rtrompier Apr 30, 2024
bb38482
feat(chart): fix
rtrompier Apr 30, 2024
f50b508
feat(chart): fix
rtrompier Apr 30, 2024
e4270bb
update replicas count
rtrompier May 3, 2024
21797cd
json logs
rtrompier May 3, 2024
a38cdaf
use internal image for prod env
rtrompier May 3, 2024
f9721e5
Merge branch 'main' into feat/infra
nsarrazin May 3, 2024
10961b5
Add LOG_LEVEL in prod yaml
nsarrazin May 3, 2024
5faef25
Get rid of unused staging env
nsarrazin May 3, 2024
17a7345
add an image build for internal registry
nsarrazin May 3, 2024
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
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
/build
/.svelte-kit
/package
/chart
.env
.env.*
!.env.example
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ RUN --mount=type=secret,id=DOTENV_LOCAL,dst=.env.local \
npm run build

FROM node:20-slim
RUN npm install -g pm2

RUN userdel -r node

Expand All @@ -39,4 +38,4 @@ COPY --link --chown=1000 package.json /app/package.json
COPY --from=builder --chown=1000 /app/build /app/build
COPY --chown=1000 gcp-*.json /app/

CMD pm2 start /app/build/index.js -i $CPU_CORES --no-daemon
CMD node /app/build/index.js
5 changes: 5 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: chat-ui
version: 0.0.0-latest
type: application
icon: https://huggingface.co/front/assets/huggingface_logo-noborder.svg
327 changes: 327 additions & 0 deletions chart/env/prod.yaml

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- define "name" -}}
{{- default $.Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "app.name" -}}
chat-ui
{{- end -}}

{{- define "labels.standard" -}}
release: {{ $.Release.Name | quote }}
heritage: {{ $.Release.Service | quote }}
chart: "{{ include "name" . }}"
app: "{{ include "app.name" . }}"
{{- end -}}

{{- define "labels.resolver" -}}
release: {{ $.Release.Name | quote }}
heritage: {{ $.Release.Service | quote }}
chart: "{{ include "name" . }}"
app: "{{ include "app.name" . }}-resolver"
{{- end -}}

10 changes: 10 additions & 0 deletions chart/templates/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels: {{ include "labels.standard" . | nindent 4 }}
name: {{ include "name" . }}
namespace: {{ .Release.Namespace }}
data:
{{- range $key, $value := $.Values.envVars }}
{{ $key }}: {{ $value | quote }}
{{- end }}
62 changes: 62 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels: {{ include "labels.standard" . | nindent 4 }}
name: {{ include "name" . }}
namespace: {{ .Release.Namespace }}
spec:
progressDeadlineSeconds: 600
{{- if not $.Values.autoscaling.enabled }}
replicas: {{ .Values.replicas }}
{{- end }}
revisionHistoryLimit: 10
selector:
matchLabels: {{ include "labels.standard" . | nindent 6 }}
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels: {{ include "labels.standard" . | nindent 8 }}
spec:
containers:
- name: chat-ui
image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
readinessProbe:
failureThreshold: 30
periodSeconds: 10
httpGet:
path: {{ $.Values.envVars.APP_BASE | default "" }}/healthcheck
port: {{ $.Values.envVars.APP_PORT | default 3000 | int }}
livenessProbe:
failureThreshold: 30
periodSeconds: 10
httpGet:
path: {{ $.Values.envVars.APP_BASE | default "" }}/healthcheck
port: {{ $.Values.envVars.APP_PORT | default 3000 | int }}
ports:
- containerPort: {{ $.Values.envVars.APP_PORT | default 3000 | int }}
name: http
protocol: TCP
{{- if $.Values.monitoring.enabled }}
- containerPort: {{ $.Values.envVars.METRICS_PORT | default 5565 | int }}
name: metrics
protocol: TCP
{{- end }}
resources: {{ toYaml .Values.resources | nindent 12 }}
envFrom:
- configMapRef:
name: {{ include "name" . }}
{{- if $.Values.externalSecrets.enabled }}
- secretRef:
name: {{ $.Values.externalSecrets.secretName }}
{{- end }}
nodeSelector: {{ toYaml .Values.nodeSelector | nindent 8 }}
tolerations: {{ toYaml .Values.tolerations | nindent 8 }}
volumes:
- name: config
configMap:
name: {{ include "name" . }}
45 changes: 45 additions & 0 deletions chart/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{- if $.Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
labels: {{ include "labels.standard" . | nindent 4 }}
name: {{ include "name" . }}
namespace: {{ .Release.Namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "name" . }}
minReplicas: {{ $.Values.autoscaling.minReplicas }}
maxReplicas: {{ $.Values.autoscaling.maxReplicas }}
metrics:
{{- if ne "" $.Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ $.Values.autoscaling.targetMemoryUtilizationPercentage | int }}
{{- end }}
{{- if ne "" $.Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ $.Values.autoscaling.targetCPUUtilizationPercentage | int }}
{{- end }}
behavior:
scaleDown:
stabilizationWindowSeconds: 600
policies:
- type: Percent
value: 10
periodSeconds: 60
scaleUp:
stabilizationWindowSeconds: 0
policies:
- type: Pods
value: 1
periodSeconds: 30
{{- end }}
19 changes: 19 additions & 0 deletions chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations: {{ toYaml .Values.ingress.annotations | nindent 4 }}
labels: {{ include "labels.standard" . | nindent 4 }}
name: {{ include "name" . }}
namespace: {{ .Release.Namespace }}
spec:
rules:
- host: {{ .Values.domain }}
http:
paths:
- backend:
service:
name: {{ include "name" . }}
port:
name: http
path: {{ $.Values.ingress.path | default "/" }}
pathType: Prefix
21 changes: 21 additions & 0 deletions chart/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- if .Values.externalSecrets.enabled }}
apiVersion: "external-secrets.io/v1beta1"
kind: ExternalSecret
metadata:
labels: {{ include "labels.standard" . | nindent 4 }}
name: {{ include "name" $ }}-external-secret
namespace: {{ $.Release.Namespace }}
spec:
refreshInterval: 1h
secretStoreRef:
name: {{ .Values.externalSecrets.secretStoreName }}
kind: SecretStore
target:
name: {{ .Values.externalSecrets.secretName }}
data:
{{- range $key, $value := .Values.externalSecrets.parameters }}
- secretKey: {{ $key | quote }}
remoteRef:
key: {{ $value | quote }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions chart/templates/service-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if $.Values.monitoring.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels: {{ include "labels.standard" . | nindent 4 }}
name: {{ include "name" . }}
namespace: {{ .Release.Namespace }}
spec:
selector:
matchLabels: {{ include "labels.standard" . | nindent 6 }}
endpoints:
- port: metrics
path: /metrics
interval: 15s
{{- end }}
21 changes: 21 additions & 0 deletions chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: Service
metadata:
name: "{{ include "name" . }}"
annotations: {{ toYaml .Values.service.annotations | nindent 4 }}
namespace: {{ .Release.Namespace }}
labels: {{ include "labels.standard" . | nindent 4 }}
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
{{- if $.Values.monitoring.enabled }}
- name: metrics
port: 5565
protocol: TCP
targetPort: http
{{- end }}
selector: {{ include "labels.standard" . | nindent 4 }}
type: {{.Values.service.type}}
44 changes: 44 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
image:
repository: ghcr.io/huggingface
name: chat-ui
tag: 0.0.0-latest
pullPolicy: IfNotPresent

replicas: 3

domain: huggingface.co

service:
type: NodePort
annotations: { }

ingress:
path: "/"
annotations: { }

resources:
requests:
cpu: 1
memory: 8Gi
limits:
cpu: 1
memory: 8Gi
nodeSelector: {}
tolerations: []

envVars: { }
externalSecrets:
enabled: false
secretStoreName: ""
secretName: ""
parameters: { }

autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 2
targetMemoryUtilizationPercentage: ""
targetCPUUtilizationPercentage: ""

monitoring:
enabled: false