Перенести актуальную lab2 как базу lab3
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
apiVersion: v2
|
||||
name: messenger
|
||||
description: Учебный мессенджер с PostgreSQL и шардированным Valkey
|
||||
version: 0.1.0
|
||||
appVersion: lab2
|
||||
type: application
|
||||
@@ -0,0 +1,7 @@
|
||||
{{- define "messenger.shards" -}}
|
||||
{{- $nodes := list -}}
|
||||
{{- range $i := until (int .Values.valkey.shards) -}}
|
||||
{{- $nodes = append $nodes (printf "shard%d=valkey-%d.valkey:6379" $i $i) -}}
|
||||
{{- end -}}
|
||||
{{- join "," $nodes -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,88 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: messenger-config
|
||||
namespace: {{ .Release.Namespace }}
|
||||
data:
|
||||
APP_PORT: '8080'
|
||||
VALKEY_COORDINATOR: shard0
|
||||
VALKEY_SHARDS: {{ include "messenger.shards" . | quote }}
|
||||
{{- range $key, $value := .Values.api.env }}
|
||||
{{ $key }}: {{ $value | quote }}
|
||||
{{- end }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: api
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
selector:
|
||||
app: api
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: api
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
replicas: {{ .Values.api.replicas }}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: api
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
checksum/config: {{ printf "%s%s" (include "messenger.shards" .) (toJson .Values.api.env) | sha256sum }}
|
||||
labels:
|
||||
app: api
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: {{ .Values.imagePullSecret }}
|
||||
terminationGracePeriodSeconds: 10
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 65532
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
containers:
|
||||
- name: api
|
||||
image: "{{ .Values.image.repository }}@{{ .Values.image.digest }}"
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: messenger-config
|
||||
env:
|
||||
- name: DATABASE_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.databaseSecret }}
|
||||
key: database-url
|
||||
resources:
|
||||
{{- toYaml .Values.api.resources | nindent 12 }}
|
||||
startupProbe:
|
||||
httpGet:
|
||||
path: /health/ready
|
||||
port: 8080
|
||||
periodSeconds: 2
|
||||
failureThreshold: 30
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health/ready
|
||||
port: 8080
|
||||
periodSeconds: 2
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health/live
|
||||
port: 8080
|
||||
periodSeconds: 5
|
||||
securityContext:
|
||||
readOnlyRootFilesystem: true
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities:
|
||||
drop: [ALL]
|
||||
@@ -0,0 +1,7 @@
|
||||
{{- $live := lookup "v1" "ConfigMap" .Release.Namespace "messenger-config" -}}
|
||||
{{- if and $live (ne (index $live.data "VALKEY_SHARDS") (include "messenger.shards" .)) -}}
|
||||
{{- $api := lookup "apps/v1" "Deployment" .Release.Namespace "api" -}}
|
||||
{{- if or (gt (int .Values.api.replicas) 0) (and $api (gt (int $api.spec.replicas) 0)) -}}
|
||||
{{- fail "Changing shards requires drained API: use make reshard SHARDS=2 or SHARDS=3" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,22 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: private-databases
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
podSelector:
|
||||
matchExpressions:
|
||||
- key: app
|
||||
operator: In
|
||||
values: [postgres, valkey]
|
||||
policyTypes: [Ingress]
|
||||
ingress:
|
||||
- from:
|
||||
- podSelector:
|
||||
matchLabels:
|
||||
app: api
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 5432
|
||||
- protocol: TCP
|
||||
port: 6379
|
||||
@@ -0,0 +1,66 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: postgres
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
selector:
|
||||
app: postgres
|
||||
ports:
|
||||
- port: 5432
|
||||
targetPort: 5432
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: postgres
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
serviceName: postgres
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: postgres
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
terminationGracePeriodSeconds: 30
|
||||
containers:
|
||||
- name: postgres
|
||||
image: {{ .Values.postgres.image | quote }}
|
||||
ports:
|
||||
- containerPort: 5432
|
||||
env:
|
||||
- name: POSTGRES_DB
|
||||
value: messenger
|
||||
- name: POSTGRES_USER
|
||||
value: messenger
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.databaseSecret }}
|
||||
key: postgres-password
|
||||
- name: PGDATA
|
||||
value: /var/lib/postgresql/data/pgdata
|
||||
resources:
|
||||
{{- toYaml .Values.postgres.resources | nindent 12 }}
|
||||
readinessProbe:
|
||||
exec:
|
||||
command: [pg_isready, -U, messenger, -d, messenger]
|
||||
initialDelaySeconds: 3
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
spec:
|
||||
{{- if .Values.storageClass }}
|
||||
storageClassName: {{ .Values.storageClass | quote }}
|
||||
{{- end }}
|
||||
accessModes: [ReadWriteOnce]
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.postgres.storage }}
|
||||
@@ -0,0 +1,57 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: valkey
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
clusterIP: None
|
||||
selector:
|
||||
app: valkey
|
||||
ports:
|
||||
- port: 6379
|
||||
targetPort: 6379
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: valkey
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
serviceName: valkey
|
||||
replicas: {{ .Values.valkey.shards }}
|
||||
podManagementPolicy: Parallel
|
||||
selector:
|
||||
matchLabels:
|
||||
app: valkey
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: valkey
|
||||
spec:
|
||||
terminationGracePeriodSeconds: 30
|
||||
containers:
|
||||
- name: valkey
|
||||
image: {{ .Values.valkey.image | quote }}
|
||||
args: [valkey-server, --appendonly, 'yes', --appendfsync, always, --maxmemory, {{ .Values.valkey.maxmemory | quote }}, --maxmemory-policy, noeviction]
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
resources:
|
||||
{{- toYaml .Values.valkey.resources | nindent 12 }}
|
||||
readinessProbe:
|
||||
exec:
|
||||
command: [valkey-cli, ping]
|
||||
initialDelaySeconds: 2
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: data
|
||||
spec:
|
||||
{{- if .Values.storageClass }}
|
||||
storageClassName: {{ .Values.storageClass | quote }}
|
||||
{{- end }}
|
||||
accessModes: [ReadWriteOnce]
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.valkey.storage }}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"valkey": {"type": "object", "properties": {"shards": {"type": "integer", "minimum": 2, "maximum": 3}}},
|
||||
"api": {"type": "object", "properties": {"replicas": {"type": "integer", "minimum": 0}}},
|
||||
"image": {"type": "object", "properties": {"digest": {"type": "string", "pattern": "^sha256:[a-f0-9]{64}$"}}}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
# Ресурсы lab2 в общем namespace. Секреты создаются через make init.
|
||||
image:
|
||||
repository: asisti.registry.twcstorage.ru/mtusi2026lab2
|
||||
digest: sha256:3f19c9feb306a88044cc46b25d99592d48f04c21eba477d59676486277b2956c
|
||||
imagePullSecret: registry-pull
|
||||
databaseSecret: messenger-secrets
|
||||
api:
|
||||
replicas: 1
|
||||
resources:
|
||||
requests: {cpu: 250m, memory: 128Mi}
|
||||
limits: {cpu: '1', memory: 256Mi}
|
||||
env:
|
||||
SESSION_TTL_SECONDS: '3600'
|
||||
DEPENDENCY_TIMEOUT_MS: '1000'
|
||||
DEPENDENCY_POOL_SIZE: '8'
|
||||
REQUEST_TIMEOUT_SECONDS: '3'
|
||||
SHUTDOWN_TIMEOUT_SECONDS: '5'
|
||||
GOMEMLIMIT: 160MiB
|
||||
postgres:
|
||||
image: postgres:17.6-alpine
|
||||
storage: 2Gi
|
||||
resources:
|
||||
requests: {cpu: 250m, memory: 256Mi}
|
||||
limits: {cpu: '1', memory: 512Mi}
|
||||
valkey:
|
||||
image: valkey/valkey:8.1.3-alpine
|
||||
shards: 3
|
||||
storage: 1Gi
|
||||
maxmemory: 64mb
|
||||
resources:
|
||||
requests: {cpu: 100m, memory: 96Mi}
|
||||
limits: {cpu: 500m, memory: 128Mi}
|
||||
# Пустое значение использует default StorageClass. Задать до первой установки.
|
||||
storageClass: ''
|
||||
Reference in New Issue
Block a user