forked from mtusi2026/mtusi2026lab3
Реализовать lab3 в общем Helm-релизе с Traefik, TLS и HPA
This commit is contained in:
@@ -2,5 +2,5 @@ apiVersion: v2
|
||||
name: messenger
|
||||
description: Учебный мессенджер с PostgreSQL и шардированным Valkey
|
||||
version: 0.1.0
|
||||
appVersion: lab2
|
||||
appVersion: lab3
|
||||
type: application
|
||||
|
||||
@@ -14,13 +14,16 @@ data:
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: api
|
||||
name: api
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
selector:
|
||||
app: api
|
||||
ports:
|
||||
- port: 8080
|
||||
- name: http
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
@@ -29,7 +32,13 @@ metadata:
|
||||
name: api
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
{{- if not .Values.autoscaling.enabled }}
|
||||
replicas: {{ .Values.api.replicas }}
|
||||
{{- end }}
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxUnavailable: 0
|
||||
maxSurge: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: api
|
||||
@@ -42,7 +51,14 @@ spec:
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: {{ .Values.imagePullSecret }}
|
||||
terminationGracePeriodSeconds: 10
|
||||
terminationGracePeriodSeconds: 20
|
||||
topologySpreadConstraints:
|
||||
- maxSkew: 1
|
||||
topologyKey: kubernetes.io/hostname
|
||||
whenUnsatisfiable: ScheduleAnyway
|
||||
labelSelector:
|
||||
matchLabels:
|
||||
app: api
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 65532
|
||||
@@ -58,6 +74,15 @@ spec:
|
||||
- configMapRef:
|
||||
name: messenger-config
|
||||
env:
|
||||
- name: INSTANCE_ID
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: CURSOR_SIGNING_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.databaseSecret }}
|
||||
key: cursor-key
|
||||
- name: DATABASE_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
@@ -65,6 +90,10 @@ spec:
|
||||
key: database-url
|
||||
resources:
|
||||
{{- toYaml .Values.api.resources | nindent 12 }}
|
||||
lifecycle:
|
||||
preStop:
|
||||
sleep:
|
||||
seconds: 3
|
||||
startupProbe:
|
||||
httpGet:
|
||||
path: /health/ready
|
||||
@@ -72,6 +101,8 @@ spec:
|
||||
periodSeconds: 2
|
||||
failureThreshold: 30
|
||||
readinessProbe:
|
||||
timeoutSeconds: 2
|
||||
failureThreshold: 2
|
||||
httpGet:
|
||||
path: /health/ready
|
||||
port: 8080
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
{{- if .Values.autoscaling.enabled }}
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: api
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: api
|
||||
minReplicas: {{ .Values.autoscaling.minReplicas }}
|
||||
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: {{ .Values.autoscaling.cpuPercent }}
|
||||
behavior:
|
||||
scaleUp:
|
||||
stabilizationWindowSeconds: 15
|
||||
policies:
|
||||
- type: Pods
|
||||
value: 1
|
||||
periodSeconds: 30
|
||||
scaleDown:
|
||||
stabilizationWindowSeconds: 120
|
||||
policies:
|
||||
- type: Pods
|
||||
value: 1
|
||||
periodSeconds: 60
|
||||
{{- end }}
|
||||
@@ -0,0 +1,23 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: messenger
|
||||
annotations:
|
||||
cert-manager.io/cluster-issuer: {{ .Values.ingress.clusterIssuer | quote }}
|
||||
spec:
|
||||
ingressClassName: {{ .Values.ingress.className }}
|
||||
tls:
|
||||
- hosts:
|
||||
- {{ .Values.ingress.host | quote }}
|
||||
secretName: messenger-tls
|
||||
rules:
|
||||
- host: {{ .Values.ingress.host | quote }}
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: api
|
||||
port:
|
||||
number: 8080
|
||||
@@ -0,0 +1,37 @@
|
||||
{{- if .Values.load.enabled }}
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: load-{{ .Values.load.run }}
|
||||
spec:
|
||||
backoffLimit: 0
|
||||
activeDeadlineSeconds: 300
|
||||
ttlSecondsAfterFinished: 86400
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: load
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- name: k6
|
||||
image: grafana/k6:1.3.0
|
||||
args: [run, --quiet, /scripts/{{ .Values.load.script }}]
|
||||
env:
|
||||
- name: BASE_URL
|
||||
value: "https://{{ .Values.ingress.host }}"
|
||||
- name: DURATION
|
||||
value: {{ .Values.load.duration | quote }}
|
||||
- name: VUS
|
||||
value: {{ .Values.load.vus | quote }}
|
||||
resources:
|
||||
requests: {cpu: 250m, memory: 128Mi}
|
||||
limits: {cpu: '2', memory: 256Mi}
|
||||
volumeMounts:
|
||||
- name: scripts
|
||||
mountPath: /scripts
|
||||
volumes:
|
||||
- name: scripts
|
||||
configMap:
|
||||
name: load-scripts
|
||||
{{- end }}
|
||||
@@ -0,0 +1,32 @@
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: migrate-{{ .Release.Revision }}
|
||||
spec:
|
||||
activeDeadlineSeconds: 180
|
||||
backoffLimit: 3
|
||||
ttlSecondsAfterFinished: 86400
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: migrate
|
||||
spec:
|
||||
restartPolicy: OnFailure
|
||||
imagePullSecrets:
|
||||
- name: {{ .Values.imagePullSecret }}
|
||||
containers:
|
||||
- name: migrate
|
||||
image: "{{ .Values.image.repository }}@{{ .Values.image.digest }}"
|
||||
args: [migrate]
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: messenger-config
|
||||
env:
|
||||
- name: DATABASE_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.databaseSecret }}
|
||||
key: database-url
|
||||
resources:
|
||||
requests: {cpu: 50m, memory: 32Mi}
|
||||
limits: {cpu: 500m, memory: 128Mi}
|
||||
@@ -0,0 +1,19 @@
|
||||
{{- if .Values.monitoring.serviceMonitor }}
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: ServiceMonitor
|
||||
metadata:
|
||||
name: api
|
||||
labels:
|
||||
app: api
|
||||
spec:
|
||||
namespaceSelector:
|
||||
matchNames: [{{ .Release.Namespace }}]
|
||||
selector:
|
||||
matchLabels:
|
||||
app: api
|
||||
endpoints:
|
||||
- port: http
|
||||
path: /metrics
|
||||
interval: 15s
|
||||
scrapeTimeout: 3s
|
||||
{{- end }}
|
||||
@@ -20,3 +20,35 @@ spec:
|
||||
port: 5432
|
||||
- protocol: TCP
|
||||
port: 6379
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: migrate
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 5432
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: private-api
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
app: api
|
||||
policyTypes: [Ingress]
|
||||
ingress:
|
||||
- from:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: traefik
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 8080
|
||||
- from:
|
||||
- namespaceSelector:
|
||||
matchLabels:
|
||||
kubernetes.io/metadata.name: monitoring
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 8080
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
# Ресурсы lab2 в общем namespace. Секреты создаются через make init.
|
||||
# Existing lab2 release; shared persistent stores and credentials.
|
||||
image:
|
||||
repository: asisti.registry.twcstorage.ru/mtusi2026lab2
|
||||
digest: sha256:3f19c9feb306a88044cc46b25d99592d48f04c21eba477d59676486277b2956c
|
||||
repository: asisti.registry.twcstorage.ru/mtusi2026lab3
|
||||
digest: sha256:a73799010550ab2008b984ed9d0bfa8dfdd9bb963cb948bc91713748b24c3889
|
||||
imagePullSecret: registry-pull
|
||||
databaseSecret: messenger-secrets
|
||||
api:
|
||||
replicas: 1
|
||||
replicas: 2
|
||||
resources:
|
||||
requests: {cpu: 250m, memory: 128Mi}
|
||||
limits: {cpu: '1', memory: 256Mi}
|
||||
env:
|
||||
SESSION_TTL_SECONDS: '3600'
|
||||
DEPENDENCY_TIMEOUT_MS: '1000'
|
||||
DEPENDENCY_TIMEOUT_MS: '2000'
|
||||
DEPENDENCY_POOL_SIZE: '8'
|
||||
REQUEST_TIMEOUT_SECONDS: '3'
|
||||
REQUEST_TIMEOUT_SECONDS: '4'
|
||||
SHUTDOWN_TIMEOUT_SECONDS: '5'
|
||||
GOMEMLIMIT: 160MiB
|
||||
postgres:
|
||||
@@ -32,3 +32,22 @@ valkey:
|
||||
limits: {cpu: 500m, memory: 128Mi}
|
||||
# Пустое значение использует default StorageClass. Задать до первой установки.
|
||||
storageClass: ''
|
||||
|
||||
autoscaling:
|
||||
enabled: true
|
||||
minReplicas: 2
|
||||
maxReplicas: 4
|
||||
cpuPercent: 60
|
||||
monitoring:
|
||||
serviceMonitor: false
|
||||
load:
|
||||
enabled: false
|
||||
run: manual
|
||||
script: scaling.js
|
||||
duration: 30
|
||||
vus: 32
|
||||
|
||||
ingress:
|
||||
host: hl.agapov.space
|
||||
className: traefik
|
||||
clusterIssuer: letsencrypt-prod
|
||||
|
||||
Reference in New Issue
Block a user