diff --git a/charts/backend/.helmignore b/charts/backend/.helmignore new file mode 100644 index 0000000..9b340f8 --- /dev/null +++ b/charts/backend/.helmignore @@ -0,0 +1,13 @@ +# Patterns to ignore when building packages. +.DS_Store +.git/ +.gitignore +*.swp +*.bak +*.tmp +*.orig +*~ +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/backend/Chart.yaml b/charts/backend/Chart.yaml new file mode 100644 index 0000000..5b7594d --- /dev/null +++ b/charts/backend/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: platform-backend +description: Go API backend (Gin) — storefront platform +type: application +version: 0.1.0 +appVersion: "1.0.0" diff --git a/charts/backend/templates/NOTES.txt b/charts/backend/templates/NOTES.txt new file mode 100644 index 0000000..5f4fd05 --- /dev/null +++ b/charts/backend/templates/NOTES.txt @@ -0,0 +1,30 @@ +Backend deployed as {{ include "backend.fullname" . }} ({{ .Values.replicaCount }} replica{{ if ne (int .Values.replicaCount) 1 }}s{{ end }}). + +{{- if .Values.migrationJob.enabled }} +Migrations (backend/migrations) ran as a pre-install/pre-upgrade hook. +{{- else }} +migrationJob.enabled is false -- you must run backend/migrations against +DATABASE_URL yourself before the API will work against an empty database. +{{- end }} + +{{- if .Values.seedJob.enabled }} +The initial admin account was created by the post-install seed Job. Check +its logs for the username (`kubectl logs job/{{ include "backend.fullname" . }}-seed -n {{ .Release.Namespace }}`) +-- it will NOT run again on upgrade, and re-enabling it once the admin +already exists will fail the Job. +{{- end }} + +This chart creates no ingress: routing is done by the ingressroute chart +(charts/ingressroute), which claims "/api/" and "/uploads/" for this Service +on the same host as the frontend. +In-cluster, the API is reachable at: + http://{{ include "backend.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }} + +{{- if eq .Values.env.MEDIA_STORAGE_DRIVER "local" }} + +MEDIA_STORAGE_DRIVER=local: uploaded files live on PersistentVolumeClaims +(uploads: {{ if .Values.persistence.uploads.enabled }}{{ .Values.persistence.uploads.size }}{{ else }}DISABLED -- uploads will be lost on pod restart{{ end }}, +verification: {{ if .Values.persistence.verification.enabled }}{{ .Values.persistence.verification.size }}{{ else }}DISABLED -- files will be lost on pod restart{{ end }}). +This only works correctly with replicaCount=1 / autoscaling disabled. +Switch to MEDIA_STORAGE_DRIVER=s3 before scaling beyond one replica. +{{- end }} diff --git a/charts/backend/templates/_helpers.tpl b/charts/backend/templates/_helpers.tpl new file mode 100644 index 0000000..9347867 --- /dev/null +++ b/charts/backend/templates/_helpers.tpl @@ -0,0 +1,25 @@ +{{- define "backend.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "backend.fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "backend.labels" -}} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} +app.kubernetes.io/name: {{ include "backend.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "backend.selectorLabels" -}} +app.kubernetes.io/name: {{ include "backend.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{- define "backend.secretName" -}} +{{ include "backend.fullname" . }}-secrets +{{- end }} diff --git a/charts/backend/templates/configmap.yaml b/charts/backend/templates/configmap.yaml new file mode 100644 index 0000000..243d68e --- /dev/null +++ b/charts/backend/templates/configmap.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "backend.fullname" . }} + labels: + {{- include "backend.labels" . | nindent 4 }} +data: + {{- range $k, $v := .Values.env }} + {{ $k }}: {{ $v | quote }} + {{- end }} diff --git a/charts/backend/templates/deployment.yaml b/charts/backend/templates/deployment.yaml new file mode 100644 index 0000000..e65cb15 --- /dev/null +++ b/charts/backend/templates/deployment.yaml @@ -0,0 +1,90 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "backend.fullname" . }} + labels: + {{- include "backend.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + {{- if or .Values.persistence.uploads.enabled .Values.persistence.verification.enabled }} + # Volumes ReadWriteOnce : un rolling update bloquerait (l'ancien Pod garde le + # volume, le nouveau ne peut pas le monter). + strategy: + type: Recreate + {{- end }} + selector: + matchLabels: + {{- include "backend.selectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "backend.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: ["/app/api"] + ports: + - name: http + containerPort: {{ .Values.env.PORT | int }} + protocol: TCP + envFrom: + - configMapRef: + name: {{ include "backend.fullname" . }} + - secretRef: + name: {{ include "backend.secretName" . }} + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + {{- if .Values.persistence.uploads.enabled }} + - name: uploads + mountPath: {{ .Values.env.MEDIA_LOCAL_DIR }} + {{- end }} + {{- if .Values.persistence.verification.enabled }} + - name: verification + mountPath: {{ .Values.env.VERIFICATION_UPLOAD_DIR }} + {{- end }} + volumes: + {{- if .Values.persistence.uploads.enabled }} + - name: uploads + persistentVolumeClaim: + claimName: {{ include "backend.fullname" . }}-uploads + {{- end }} + {{- if .Values.persistence.verification.enabled }} + - name: verification + persistentVolumeClaim: + claimName: {{ include "backend.fullname" . }}-verification + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/backend/templates/hpa.yaml b/charts/backend/templates/hpa.yaml new file mode 100644 index 0000000..35dca0b --- /dev/null +++ b/charts/backend/templates/hpa.yaml @@ -0,0 +1,22 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "backend.fullname" . }} + labels: + {{- include "backend.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "backend.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} +{{- end }} diff --git a/charts/backend/templates/migration-job.yaml b/charts/backend/templates/migration-job.yaml new file mode 100644 index 0000000..efbaae5 --- /dev/null +++ b/charts/backend/templates/migration-job.yaml @@ -0,0 +1,58 @@ +{{- if .Values.migrationJob.enabled }} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "backend.fullname" . }}-migrate-{{ .Release.Revision }} + labels: + {{- include "backend.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-5" + "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded +spec: + backoffLimit: {{ .Values.migrationJob.backoffLimit }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "backend.name" . }}-migrate + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/component: migrate + spec: + restartPolicy: Never + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + # Migrations are baked into the backend image (see backend/Dockerfile) + # so they always match the version being deployed; this initContainer + # just hands them to the golang-migrate image below via a shared + # emptyDir, since that image has the `migrate` binary but not our SQL. + initContainers: + - name: copy-migrations + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + command: ["sh", "-c", "cp -r /app/migrations/. /migrations/"] + volumeMounts: + - name: migrations + mountPath: /migrations + containers: + - name: migrate + image: "{{ .Values.migrationJob.image.repository }}:{{ .Values.migrationJob.image.tag }}" + imagePullPolicy: {{ .Values.migrationJob.image.pullPolicy }} + args: + - "-path=/migrations" + - "-database=$(DATABASE_URL)" + - "up" + env: + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: {{ include "backend.secretName" . }} + key: DATABASE_URL + volumeMounts: + - name: migrations + mountPath: /migrations + readOnly: true + volumes: + - name: migrations + emptyDir: {} +{{- end }} diff --git a/charts/backend/templates/pvc.yaml b/charts/backend/templates/pvc.yaml new file mode 100644 index 0000000..d1c9702 --- /dev/null +++ b/charts/backend/templates/pvc.yaml @@ -0,0 +1,20 @@ +{{- range $name, $pvc := .Values.persistence }} +{{- if $pvc.enabled }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "backend.fullname" $ }}-{{ $name }} + labels: + {{- include "backend.labels" $ | nindent 4 }} +spec: + accessModes: + - {{ $pvc.accessMode }} + {{- if $pvc.storageClass }} + storageClassName: {{ $pvc.storageClass }} + {{- end }} + resources: + requests: + storage: {{ $pvc.size }} +{{- end }} +{{- end }} diff --git a/charts/backend/templates/secret.yaml b/charts/backend/templates/secret.yaml new file mode 100644 index 0000000..ed11092 --- /dev/null +++ b/charts/backend/templates/secret.yaml @@ -0,0 +1,32 @@ +{{- if or (not .Values.secrets.JWT_SECRET) (eq .Values.secrets.JWT_SECRET "change-me-to-a-long-random-secret") }} +{{- fail "secrets.JWT_SECRET must be overridden to a strong, unique value (e.g. `openssl rand -base64 48`)" }} +{{- end }} +{{- if and .Values.seedJob.enabled (not .Values.secrets.SEED_ADMIN_PASSWORD) }} +{{- fail "secrets.SEED_ADMIN_PASSWORD is required when seedJob.enabled=true" }} +{{- end }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "backend.secretName" . }} + labels: + {{- include "backend.labels" . | nindent 4 }} + annotations: + # Hook pre-install/pre-upgrade : le Job de migration (hook lui aussi) tourne + # AVANT la création des ressources normales du chart et lit DATABASE_URL + # depuis ce Secret. Sans ce hook, le Job démarrerait sans Secret. + # Conséquence : `helm uninstall` ne supprime pas ce Secret. + "helm.sh/hook": pre-install,pre-upgrade + "helm.sh/hook-weight": "-10" + "helm.sh/hook-delete-policy": before-hook-creation +type: Opaque +stringData: + {{- range $k, $v := .Values.secrets }} + {{ $k }}: {{ $v | quote }} + {{- end }} + # Assemblées ici (plutôt que passées telles quelles) pour que + # database.*/redis.* restent des champs structurés côté values.yaml, à + # l'image de postgresql.auth/redis.auth des charts ../postgresql, ../redis + # -- alors que backend/internal/platform/config ne sait lire qu'une seule + # chaîne de connexion. + DATABASE_URL: {{ printf "postgres://%s:%s@%s:%v/%s?sslmode=%s" (.Values.database.user | urlquery) (.Values.secrets.DB_PASSWORD | urlquery) .Values.database.host .Values.database.port .Values.database.name .Values.database.sslmode | quote }} + REDIS_URL: {{ printf "redis://:%s@%s:%v/%v" (.Values.secrets.REDIS_PASSWORD | urlquery) .Values.redis.host .Values.redis.port .Values.redis.db | quote }} diff --git a/charts/backend/templates/seed-job.yaml b/charts/backend/templates/seed-job.yaml new file mode 100644 index 0000000..f99ff35 --- /dev/null +++ b/charts/backend/templates/seed-job.yaml @@ -0,0 +1,40 @@ +{{- if .Values.seedJob.enabled }} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "backend.fullname" . }}-seed + labels: + {{- include "backend.labels" . | nindent 4 }} + annotations: + # post-install only, never post-upgrade: cmd/seed hard-fails if + # SEED_ADMIN_USERNAME already exists (see backend/cmd/seed/main.go), so + # it is not safe to re-run on every upgrade. Turn seedJob.enabled back + # off after the first successful install. + "helm.sh/hook": post-install + "helm.sh/hook-weight": "5" + "helm.sh/hook-delete-policy": before-hook-creation +spec: + backoffLimit: {{ .Values.seedJob.backoffLimit }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "backend.name" . }}-seed + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/component: seed + spec: + restartPolicy: Never + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: seed + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: ["/app/seed"] + envFrom: + - configMapRef: + name: {{ include "backend.fullname" . }} + - secretRef: + name: {{ include "backend.secretName" . }} +{{- end }} diff --git a/charts/backend/templates/service.yaml b/charts/backend/templates/service.yaml new file mode 100644 index 0000000..4fb4186 --- /dev/null +++ b/charts/backend/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "backend.fullname" . }} + labels: + {{- include "backend.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "backend.selectorLabels" . | nindent 4 }} diff --git a/charts/backend/values.yaml b/charts/backend/values.yaml new file mode 100644 index 0000000..8055edb --- /dev/null +++ b/charts/backend/values.yaml @@ -0,0 +1,158 @@ +# 1 seul replica tant que les médias sont sur des volumes ReadWriteOnce +# (persistence.* ci-dessous) ; passer à S3 avant d'en mettre plus. +replicaCount: 1 + +image: + repository: platform-backend + tag: latest + pullPolicy: IfNotPresent + +# Injecté par qui déploie (voir deploy/chart-gestion/registry-credentials +# dans omnex/deploy pour le modèle) si un compte registry authentifié est +# configuré — évite le rate-limit de pull anonyme partagé par IP de nœud. +# Vide = pull anonyme (défaut). +imagePullSecrets: [] + +service: + type: ClusterIP + port: 8080 + +resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 500m + memory: 256Mi + +autoscaling: + enabled: false + minReplicas: 2 + maxReplicas: 5 + targetCPUUtilizationPercentage: 70 + +# Deux volumes distincts : uploads (médias publics, servis via /uploads) et +# verification (pièces d'identité clients, jamais servies publiquement -- +# voir backend/internal/modules/customerverification). Seulement pertinent +# pour media.storageDriver=local ci-dessous ; avec S3 les deux sont désactivables. +persistence: + uploads: + enabled: true + size: 5Gi + storageClass: "longhorn-replicated" + accessMode: ReadWriteOnce + verification: + enabled: true + size: 2Gi + storageClass: "longhorn-replicated" + accessMode: ReadWriteOnce + +# Postgres/Redis de CE namespace (voir ../postgresql, ../redis) -- host par +# défaut = le nom de Service que ces charts produisent avec leur +# fullnameOverride par défaut ("postgres"/"redis"). name/user = auth.database / +# auth.username par défaut de ../postgresql. +# Le mot de passe vit dans secrets.DB_PASSWORD / secrets.REDIS_PASSWORD +# ci-dessous (jamais ici), et DATABASE_URL/REDIS_URL sont assemblés par +# templates/secret.yaml à partir des deux. +database: + host: postgres + port: 5432 + name: vitrine_db + user: postgres + sslmode: disable + +redis: + host: redis + port: 6379 + db: 0 + +# Variables non sensibles (backend/internal/platform/config). PORT doit +# rester égal à service.port ci-dessus / containerPort (templates/deployment.yaml). +env: + PORT: "8080" + GIN_MODE: release + # Laisser vide si frontend et backend sont routés sur le même host par + # l'IngressRoute partagée (voir ../ingressroute) -- l'origine est alors la + # même pour le navigateur et CORS n'entre pas en jeu. + CORS_ORIGIN: "" + ACCESS_TOKEN_TTL_MINUTES: "15" + REFRESH_TOKEN_TTL_HOURS: "168" + COOKIE_SECURE: "true" + ADMIN_NUMBER: "1" + SEED_ADMIN_USERNAME: admin + MEDIA_STORAGE_DRIVER: local + MEDIA_MAX_UPLOAD_MB: "10" + MEDIA_LOCAL_DIR: /app/uploads + # URL publique sous laquelle /uploads est servi -- à fixer explicitement + # une fois le host de l'IngressRoute connu (ex: https://shop.example.com/uploads). + MEDIA_LOCAL_BASE_URL: "" + VERIFICATION_UPLOAD_DIR: /app/verification-uploads + S3_BUCKET: "" + S3_REGION: "" + S3_ENDPOINT: "" + S3_USE_PATH_STYLE: "false" + S3_PUBLIC_BASE_URL: "" + + +# Valeurs sensibles -- à surcharger via --set-string ou un Secret Manager +# externe, jamais commitées avec une vraie valeur. DATABASE_URL et REDIS_URL +# ne sont PAS ici : templates/secret.yaml les construit à partir de +# database.* / redis.* ci-dessus + DB_PASSWORD / REDIS_PASSWORD. +secrets: + JWT_SECRET: "change-me-to-a-long-random-secret" + DB_PASSWORD: "" + REDIS_PASSWORD: "" + SEED_ADMIN_PASSWORD: "" + S3_ACCESS_KEY_ID: "" + S3_SECRET_ACCESS_KEY: "" + +# Bootstrap du compte admin initial (cmd/seed). PAS idempotent -- échoue si +# SEED_ADMIN_USERNAME existe déjà (voir backend/cmd/seed/main.go), donc ce +# Job ne tourne qu'en post-install (jamais post-upgrade). À repasser à false +# après la première installation réussie. +seedJob: + enabled: false + backoffLimit: 0 + +# Applique backend/migrations (embarquées dans l'image) sur DATABASE_URL en +# hook pre-install/pre-upgrade, via l'image officielle golang-migrate. +# `migrate up` est idempotent -- rien n'empêche de le laisser actif à chaque +# upgrade, contrairement au seed Job ci-dessus. +migrationJob: + enabled: true + backoffLimit: 2 + image: + repository: migrate/migrate + tag: v4.18.1 + pullPolicy: IfNotPresent + +livenessProbe: + httpGet: + path: /health + port: http + initialDelaySeconds: 10 + periodSeconds: 20 + +readinessProbe: + httpGet: + path: /health + port: http + initialDelaySeconds: 5 + periodSeconds: 10 + +podSecurityContext: + runAsNonRoot: true + runAsUser: 101 + runAsGroup: 101 + fsGroup: 101 + seccompProfile: + type: RuntimeDefault + +securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: false + capabilities: + drop: + - ALL + +podAnnotations: {} diff --git a/charts/cert-manager/cluster-issuer.yml b/charts/cert-manager/cluster-issuer.yml new file mode 100644 index 0000000..49ab0e0 --- /dev/null +++ b/charts/cert-manager/cluster-issuer.yml @@ -0,0 +1,59 @@ +# Cluster déjà équipé pour omnex.sbs (cert-manager + ClusterIssuers +# `letsencrypt-dns` / `letsencrypt-dns-staging` limités à la zone omnex.sbs). +# Ce fichier AJOUTE des issuers dédiés à vitrine-omnex.club, avec des noms +# distincts : rien d'existant n'est modifié ni écrasé. +# +# Ne PAS réinstaller cert-manager : il est déjà là. Vérifier : +# kubectl get pods -n cert-manager +# +# Un certificat wildcard (*.vitrine-omnex.club) ne peut être émis que via un +# challenge DNS-01 : cert-manager crée des TXT chez Cloudflare. +# +# Le Secret n'est volontairement PAS dans ce fichier (ne jamais committer un +# token). Token Cloudflare avec "Zone - DNS - Edit" ET "Zone - Zone - Read" sur la +# zone vitrine-omnex.club (Zone Read : cert-manager retrouve la zone avec) +# (https://dash.cloudflare.com/profile/api-tokens), à créer une seule fois : +# kubectl create secret generic cloudflare-api-token-vitrine -n cert-manager \ +# --from-literal=api-token='' +apiVersion: cert-manager.io/v1 +kind: ClusterIssuer +metadata: + name: letsencrypt-dns-vitrine +spec: + acme: + server: https://acme-v02.api.letsencrypt.org/directory + email: admin@omnex.sbs # À adapter + privateKeySecretRef: + name: letsencrypt-dns-vitrine-account-key + solvers: + - dns01: + cloudflare: + apiTokenSecretRef: + name: cloudflare-api-token-vitrine + key: api-token + selector: + dnsZones: + - "vitrine-omnex.club" + +--- +# Issuer de test (hors rate-limit Let's Encrypt prod) : à utiliser dans +# le chart ingressroute (templates/certificate.yaml) pour valider la chaîne DNS-01 avant de basculer. +apiVersion: cert-manager.io/v1 +kind: ClusterIssuer +metadata: + name: letsencrypt-dns-vitrine-staging +spec: + acme: + server: https://acme-staging-v02.api.letsencrypt.org/directory + email: admin@omnex.sbs # À adapter + privateKeySecretRef: + name: letsencrypt-dns-vitrine-staging-account-key + solvers: + - dns01: + cloudflare: + apiTokenSecretRef: + name: cloudflare-api-token-vitrine + key: api-token + selector: + dnsZones: + - "vitrine-omnex.club" diff --git a/charts/cert-manager/networkpolicy.yml b/charts/cert-manager/networkpolicy.yml new file mode 100644 index 0000000..7338939 --- /dev/null +++ b/charts/cert-manager/networkpolicy.yml @@ -0,0 +1,134 @@ +# ⚠️ NE PAS APPLIQUER si cert-manager est déjà installé sur le cluster (cas +# actuel : omnex.sbs y est déjà géré). Les flux nécessaires à vitrine-omnex.club +# (API server, DNS, HTTPS sortant vers Let's Encrypt/Cloudflare) sont +# identiques à ceux d'omnex.sbs : les politiques existantes suffisent, et +# celles-ci les écraseraient avec une IP d'API server potentiellement fausse. +# Fichier conservé uniquement comme référence pour une installation neuve. +# +# Isolation réseau du namespace cert-manager — même logique que +# deploy/chart-gestion/network-policy (deny-by-default + allowlist), adaptée +# aux flux réels de cert-manager : +# - Ingress : l'API server appelle le webhook d'admission de cert-manager +# (validation des CRD Certificate/Issuer/ClusterIssuer) sur le port 10250. +# - Egress : API server (lecture/écriture des CRD + Secrets), DNS, et +# Internet en HTTPS (Let's Encrypt ACME + API Cloudflare pour le +# challenge DNS-01 — IPs non fixes, pas de CIDR précis possible). +# +# ⚠️ AVANT D'APPLIQUER : remplacer CHANGE_ME_apiserver_ip par l'IP réelle de +# l'API server de votre cluster (trouvable via : +# kubectl get endpoints kubernetes -n default -o wide +# ). Une mauvaise valeur bloque l'accès de cert-manager à l'API Kubernetes — +# le renouvellement automatique des certificats s'arrête silencieusement +# (pas d'impact immédiat, le cert en cours reste valide jusqu'à expiration). +# Testez avec `kubectl apply --dry-run=server` puis surveillez +# `kubectl get certificate -A` après application. + +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: default-deny-all + namespace: cert-manager +spec: + podSelector: {} + policyTypes: + - Ingress + - Egress + +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-intra-namespace + namespace: cert-manager +spec: + podSelector: {} + policyTypes: + - Ingress + - Egress + ingress: + - from: + - podSelector: {} + egress: + - to: + - podSelector: {} + +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-ingress-apiserver-webhook + namespace: cert-manager +spec: + podSelector: {} + policyTypes: + - Ingress + ingress: + - from: + - ipBlock: + cidr: 176.116.0.189/32 + ports: + - protocol: TCP + port: 10250 + +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-egress-dns + namespace: cert-manager +spec: + podSelector: {} + policyTypes: + - Egress + egress: + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + ports: + - protocol: UDP + port: 53 + - protocol: TCP + port: 53 + +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-egress-apiserver + namespace: cert-manager +spec: + podSelector: {} + policyTypes: + - Egress + egress: + - to: + - ipBlock: + cidr: 176.116.0.189/32 + ports: + - protocol: TCP + port: 6443 + +--- +# Let's Encrypt (ACME) + API Cloudflare (challenge DNS-01) : IPs publiques +# non fixes, seul HTTPS sortant est nécessaire. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-egress-internet-https + namespace: cert-manager +spec: + podSelector: {} + policyTypes: + - Egress + egress: + - to: + - ipBlock: + cidr: 0.0.0.0/0 + except: + - 10.0.0.0/8 + - 172.16.0.0/12 + - 192.168.0.0/16 + ports: + - protocol: TCP + port: 443 diff --git a/charts/frontend/.helmignore b/charts/frontend/.helmignore new file mode 100644 index 0000000..9b340f8 --- /dev/null +++ b/charts/frontend/.helmignore @@ -0,0 +1,13 @@ +# Patterns to ignore when building packages. +.DS_Store +.git/ +.gitignore +*.swp +*.bak +*.tmp +*.orig +*~ +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/frontend/Chart.yaml b/charts/frontend/Chart.yaml new file mode 100644 index 0000000..b469940 --- /dev/null +++ b/charts/frontend/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: frontend +description: Helm chart for the storefront/admin SPA (Vite/React), served as a static build behind nginx. +type: application +version: 0.1.0 +appVersion: "1.0.0" diff --git a/charts/frontend/templates/NOTES.txt b/charts/frontend/templates/NOTES.txt new file mode 100644 index 0000000..ad45650 --- /dev/null +++ b/charts/frontend/templates/NOTES.txt @@ -0,0 +1,15 @@ +Frontend deployed as {{ include "frontend.fullname" . }} ({{ .Values.replicaCount }} replica{{ if ne (int .Values.replicaCount) 1 }}s{{ end }}). + +{{- if .Values.ingress.enabled }} + +Reachable at: + {{ if .Values.ingress.tls.enabled }}https{{ else }}http{{ end }}://{{ .Values.ingress.host }}{{ .Values.ingress.path }} + +For the API calls made from this SPA (relative /api, /uploads paths) to +work, deploy the backend chart's ingress on the SAME host so the more +specific "/api" and "/uploads" paths take precedence over this chart's "/". +{{- else }} + +ingress.enabled is false. Reach it in-cluster at: + http://{{ include "frontend.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }} +{{- end }} diff --git a/charts/frontend/templates/_helpers.tpl b/charts/frontend/templates/_helpers.tpl new file mode 100644 index 0000000..4365f33 --- /dev/null +++ b/charts/frontend/templates/_helpers.tpl @@ -0,0 +1,48 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "frontend.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +*/}} +{{- define "frontend.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{- define "frontend.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "frontend.labels" -}} +helm.sh/chart: {{ include "frontend.chart" . }} +{{ include "frontend.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "frontend.selectorLabels" -}} +app.kubernetes.io/name: {{ include "frontend.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{- define "frontend.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "frontend.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/frontend/templates/deployment.yaml b/charts/frontend/templates/deployment.yaml new file mode 100644 index 0000000..478938c --- /dev/null +++ b/charts/frontend/templates/deployment.yaml @@ -0,0 +1,57 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "frontend.fullname" . }} + labels: + {{- include "frontend.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "frontend.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "frontend.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "frontend.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.targetPort }} + protocol: TCP + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/frontend/templates/hpa.yaml b/charts/frontend/templates/hpa.yaml new file mode 100644 index 0000000..5108d65 --- /dev/null +++ b/charts/frontend/templates/hpa.yaml @@ -0,0 +1,22 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "frontend.fullname" . }} + labels: + {{- include "frontend.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "frontend.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} +{{- end }} diff --git a/charts/frontend/templates/service.yaml b/charts/frontend/templates/service.yaml new file mode 100644 index 0000000..708b0ed --- /dev/null +++ b/charts/frontend/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "frontend.fullname" . }} + labels: + {{- include "frontend.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "frontend.selectorLabels" . | nindent 4 }} diff --git a/charts/frontend/values.yaml b/charts/frontend/values.yaml new file mode 100644 index 0000000..3581e08 --- /dev/null +++ b/charts/frontend/values.yaml @@ -0,0 +1,79 @@ +replicaCount: 2 + +image: + repository: ghcr.io/your-org/platform-frontend + tag: "" # defaults to .Chart.AppVersion + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + annotations: {} + name: "" + +podAnnotations: {} + +podSecurityContext: + runAsNonRoot: true + runAsUser: 101 + fsGroup: 101 + +securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: false + capabilities: + drop: ["ALL"] + +service: + type: ClusterIP + port: 80 + targetPort: 8080 + +# Ce chart ne crée pas d'Ingress : le routage est fait par charts/ingressroute +# (Traefik), qui envoie "/" ici et "/api/", "/uploads/" au backend sur le MÊME +# host -- le navigateur ne voit qu'une origine (cf. proxy dev de +# vite.config.ts). Ce bloc ne sert qu'à l'affichage de NOTES.txt : laisser +# enabled=false. +ingress: + enabled: false + host: "" + path: / + pathType: Prefix + annotations: {} + tls: + enabled: false + secretName: "" + +resources: + requests: + cpu: 50m + memory: 64Mi + limits: + cpu: 200m + memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 2 + maxReplicas: 6 + targetCPUUtilizationPercentage: 75 + +nodeSelector: {} +tolerations: [] +affinity: {} + +livenessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 3 + periodSeconds: 10 +readinessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 3 + periodSeconds: 10 diff --git a/charts/ingressroute/Chart.yaml b/charts/ingressroute/Chart.yaml new file mode 100644 index 0000000..02d755b --- /dev/null +++ b/charts/ingressroute/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: gestion-ingressroute +description: Routage Traefik + certificat TLS d'un host (Services de son propre namespace) — pointe vers le Traefik partagé (namespace traefik) +type: application +version: 0.1.0 +appVersion: "1.0.0" diff --git a/charts/ingressroute/templates/_helpers.tpl b/charts/ingressroute/templates/_helpers.tpl new file mode 100644 index 0000000..eeb9ec3 --- /dev/null +++ b/charts/ingressroute/templates/_helpers.tpl @@ -0,0 +1,14 @@ +{{- define "ingressroute.labels" -}} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} +app.kubernetes.io/name: {{ .Chart.Name }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "ingressroute.backendService" -}} +{{- .Values.backend.serviceName | default ("backend-platform-backend") }} +{{- end }} + +{{- define "ingressroute.frontendService" -}} +{{- .Values.frontend.serviceName | default ("frontend") }} +{{- end }} diff --git a/charts/ingressroute/templates/certificate.yaml b/charts/ingressroute/templates/certificate.yaml new file mode 100644 index 0000000..4f8560b --- /dev/null +++ b/charts/ingressroute/templates/certificate.yaml @@ -0,0 +1,19 @@ +{{- if and .Values.tls.secretName .Values.tls.certificate.enabled }} +# Certificat émis par cert-manager (DNS-01) dans le namespace de la release : +# Traefik ne lit `tls.secretName` que dans le namespace de l'IngressRoute. +# Les ClusterIssuers sont définis dans ../cert-manager. +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: {{ .Values.tls.secretName }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "ingressroute.labels" . | nindent 4 }} +spec: + secretName: {{ .Values.tls.secretName }} + issuerRef: + name: {{ .Values.tls.certificate.issuerName }} + kind: {{ .Values.tls.certificate.issuerKind }} + dnsNames: + {{- toYaml .Values.tls.certificate.dnsNames | nindent 4 }} +{{- end }} diff --git a/charts/ingressroute/templates/ingressroute.yaml b/charts/ingressroute/templates/ingressroute.yaml new file mode 100644 index 0000000..87d91d9 --- /dev/null +++ b/charts/ingressroute/templates/ingressroute.yaml @@ -0,0 +1,58 @@ +{{- if not .Values.host }} +{{- fail "ingressroute: .Values.host est requis (ex: vitrine-abc12.vitrine-omnex.club)" }} +{{- end }} +# Routage HTTPS. Le certificat est celui de `tls.secretName` (SNI) ; sans +# secretName, Traefik retombe sur le certificat par défaut du TLSStore +# partagé. Le redirect HTTP -> HTTPS est géré au niveau de l'entrypoint +# Traefik (pas dupliqué ici). +apiVersion: traefik.io/v1alpha1 +kind: IngressRoute +metadata: + name: {{ .Release.Namespace }}-routes + namespace: {{ .Release.Namespace }} + labels: + {{- include "ingressroute.labels" . | nindent 4 }} +spec: + entryPoints: + - websecure + routes: + # API backend — WAF + headers + rate limit (middlewares partagés, définis + # dans le namespace du Traefik commun, référencés cross-namespace). + - match: Host(`{{ .Values.host }}`) && (PathPrefix(`/api/`)) + kind: Rule + priority: 20 + middlewares: + - name: waf-chain + namespace: {{ .Values.traefikNamespace }} + services: + - name: {{ include "ingressroute.backendService" . }} + port: {{ .Values.backend.servicePort }} + + # Fichiers uploadés — WAF désactivé dans les règles Coraza pour ce path + - match: Host(`{{ .Values.host }}`) && PathPrefix(`/uploads/`) + kind: Rule + priority: 15 + middlewares: + - name: security-headers + namespace: {{ .Values.traefikNamespace }} + services: + - name: {{ include "ingressroute.backendService" . }} + port: {{ .Values.backend.servicePort }} + + # Frontend SPA — WAF + headers + rate limit + - match: Host(`{{ .Values.host }}`) + kind: Rule + priority: 1 + middlewares: + - name: waf-chain + namespace: {{ .Values.traefikNamespace }} + services: + - name: {{ include "ingressroute.frontendService" . }} + port: {{ .Values.frontend.servicePort }} + + {{- if .Values.tls.secretName }} + tls: + secretName: {{ .Values.tls.secretName }} + {{- else }} + tls: {} + {{- end }} diff --git a/charts/ingressroute/values.yaml b/charts/ingressroute/values.yaml new file mode 100644 index 0000000..b5afba9 --- /dev/null +++ b/charts/ingressroute/values.yaml @@ -0,0 +1,36 @@ +# Host complet servi par cette IngressRoute, ex: vitrine-omnex.club +# (doit être couvert par le certificat de `tls` ci-dessous). +host: "" + +# Namespace où tourne le Traefik partagé et ses Middlewares (waf-chain, +# rate-limit, coraza-waf, security-headers) — voir deploy/chart-gestion/traefik. +traefikNamespace: traefik + +# TLS. Le TLSStore par défaut de Traefik est déjà pris par le wildcard +# *.omnex.sbs : ce host doit donc désigner explicitement son propre secret. +# Le secret doit être dans le namespace de cette release (là où vit +# l'IngressRoute) : d'où le Certificate rendu par ce chart. +# Laisser `secretName` vide pour retomber sur le certificat par défaut. +tls: + secretName: wildcard-vitrine-tls + certificate: + enabled: true + # Utiliser letsencrypt-dns-vitrine-staging pour un premier essai. + issuerName: letsencrypt-dns-vitrine + issuerKind: ClusterIssuer + dnsNames: + - vitrine-omnex.club + - "*.vitrine-omnex.club" + +# Services de CE namespace. Par défaut : ceux générés par les charts +# backend/frontend installés avec les releases `backend` et `frontend` +# (README.md) -- `backend-platform-backend` et `frontend`. À surcharger si +# les releases portent d'autres noms. +# servicePort doit égaler `service.port` du chart correspondant. +backend: + serviceName: "" + servicePort: 8080 + +frontend: + serviceName: "" + servicePort: 80 diff --git a/charts/postgresql/Chart.yaml b/charts/postgresql/Chart.yaml new file mode 100644 index 0000000..e830eb1 --- /dev/null +++ b/charts/postgresql/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: gestion-postgresql +description: PostgreSQL 16 — gestion-commande +type: application +version: 0.1.0 +appVersion: "16" diff --git a/charts/postgresql/templates/_helpers.tpl b/charts/postgresql/templates/_helpers.tpl new file mode 100644 index 0000000..21e376a --- /dev/null +++ b/charts/postgresql/templates/_helpers.tpl @@ -0,0 +1,20 @@ +{{- define "postgresql.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-postgresql" .Release.Name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} + +{{- define "postgresql.labels" -}} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} +app.kubernetes.io/name: postgresql +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "postgresql.selectorLabels" -}} +app.kubernetes.io/name: postgresql +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/charts/postgresql/templates/configmap.yaml b/charts/postgresql/templates/configmap.yaml new file mode 100644 index 0000000..7fdb2c6 --- /dev/null +++ b/charts/postgresql/templates/configmap.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "postgresql.fullname" . }}-config + labels: + {{- include "postgresql.labels" . | nindent 4 }} +data: + postgresql.conf: | + max_connections = {{ .Values.config.maxConnections }} + shared_buffers = {{ .Values.config.sharedBuffers }} + effective_cache_size = {{ .Values.config.effectiveCacheSize }} + maintenance_work_mem = {{ .Values.config.maintenanceWorkMem }} + wal_buffers = {{ .Values.config.walBuffers }} + default_statistics_target = {{ .Values.config.defaultStatisticsTarget }} + random_page_cost = {{ .Values.config.randomPageCost }} + log_min_duration_statement = {{ .Values.config.logMinDurationStatement }} + log_timezone = 'UTC' + timezone = 'UTC' + # Connexions sécurisées uniquement depuis le réseau interne cluster + listen_addresses = '*' diff --git a/charts/postgresql/templates/pvc.yaml b/charts/postgresql/templates/pvc.yaml new file mode 100644 index 0000000..e776ca6 --- /dev/null +++ b/charts/postgresql/templates/pvc.yaml @@ -0,0 +1,17 @@ +{{- if .Values.persistence.enabled }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "postgresql.fullname" . }}-data + labels: + {{- include "postgresql.labels" . | nindent 4 }} +spec: + accessModes: + - {{ .Values.persistence.accessMode }} + resources: + requests: + storage: {{ .Values.persistence.size }} + {{- if .Values.persistence.storageClass }} + storageClassName: {{ .Values.persistence.storageClass }} + {{- end }} +{{- end }} diff --git a/charts/postgresql/templates/secret.yaml b/charts/postgresql/templates/secret.yaml new file mode 100644 index 0000000..b704ac2 --- /dev/null +++ b/charts/postgresql/templates/secret.yaml @@ -0,0 +1,14 @@ +{{- if not .Values.auth.password }} +{{- fail "auth.password is required (--set-string auth.password=...)" }} +{{- end }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "postgresql.fullname" . }} + labels: + {{- include "postgresql.labels" . | nindent 4 }} +type: Opaque +stringData: + POSTGRES_PASSWORD: {{ .Values.auth.password | quote }} + POSTGRES_USER: {{ .Values.auth.username | quote }} + POSTGRES_DB: {{ .Values.auth.database | quote }} diff --git a/charts/postgresql/templates/service.yaml b/charts/postgresql/templates/service.yaml new file mode 100644 index 0000000..919644f --- /dev/null +++ b/charts/postgresql/templates/service.yaml @@ -0,0 +1,32 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql.fullname" . }} + labels: + {{- include "postgresql.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + {{- include "postgresql.selectorLabels" . | nindent 4 }} + ports: + - name: postgresql + port: {{ .Values.service.port }} + targetPort: postgresql + protocol: TCP +--- +# Service headless pour le StatefulSet +apiVersion: v1 +kind: Service +metadata: + name: {{ include "postgresql.fullname" . }}-headless + labels: + {{- include "postgresql.labels" . | nindent 4 }} +spec: + type: ClusterIP + clusterIP: None + selector: + {{- include "postgresql.selectorLabels" . | nindent 4 }} + ports: + - name: postgresql + port: {{ .Values.service.port }} + targetPort: postgresql diff --git a/charts/postgresql/templates/statefulset.yaml b/charts/postgresql/templates/statefulset.yaml new file mode 100644 index 0000000..98bcd1e --- /dev/null +++ b/charts/postgresql/templates/statefulset.yaml @@ -0,0 +1,78 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "postgresql.fullname" . }} + labels: + {{- include "postgresql.labels" . | nindent 4 }} +spec: + serviceName: {{ include "postgresql.fullname" . }}-headless + replicas: 1 + selector: + matchLabels: + {{- include "postgresql.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "postgresql.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: postgresql + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + ports: + - name: postgresql + containerPort: 5432 + protocol: TCP + envFrom: + - secretRef: + name: {{ include "postgresql.fullname" . }} + env: + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + volumeMounts: + - name: data + mountPath: /var/lib/postgresql/data + - name: config + mountPath: /etc/postgresql/postgresql.conf + subPath: postgresql.conf + args: + - "-c" + - "config_file=/etc/postgresql/postgresql.conf" + livenessProbe: + exec: + command: + - sh + - -c + - pg_isready -U $POSTGRES_USER -d $POSTGRES_DB + initialDelaySeconds: 30 + periodSeconds: 10 + failureThreshold: 6 + readinessProbe: + exec: + command: + - sh + - -c + - pg_isready -U $POSTGRES_USER -d $POSTGRES_DB + initialDelaySeconds: 5 + periodSeconds: 5 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: data + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ include "postgresql.fullname" . }}-data + {{- else }} + emptyDir: {} + {{- end }} + - name: config + configMap: + name: {{ include "postgresql.fullname" . }}-config diff --git a/charts/postgresql/values.yaml b/charts/postgresql/values.yaml new file mode 100644 index 0000000..6481623 --- /dev/null +++ b/charts/postgresql/values.yaml @@ -0,0 +1,65 @@ +# Nom des ressources (dont le Service ClusterIP joint par le backend). +# "postgres" = valeur attendue par backend/values.yaml (database.host / redis.host). +fullnameOverride: "postgres" + +image: + repository: postgres + tag: "16-alpine" + pullPolicy: IfNotPresent + +# Injecté par le provisioner (voir deploy/chart-gestion/registry-credentials) +# si un compte Docker Hub authentifié est configuré — évite le rate-limit de +# pull anonyme partagé par IP de nœud. Vide = pull anonyme (défaut). +imagePullSecrets: [] + +auth: + username: postgres + database: vitrine_db + # À surcharger via --set auth.password=xxx + password: "" + +persistence: + enabled: true + size: 10Gi + # Répliqué sur 2 nœuds (Longhorn) : survit à la perte d'un nœud. Voir + # deploy/longhorn/storageclass.yml pour le prérequis d'installation. + storageClass: "longhorn-replicated" + accessMode: ReadWriteOnce + +resources: + requests: + cpu: 250m + memory: 256Mi + limits: + cpu: 1000m + memory: 1Gi + +service: + type: ClusterIP + port: 5432 + +# Paramètres PostgreSQL (postgresql.conf) +config: + maxConnections: "200" + sharedBuffers: "256MB" + effectiveCacheSize: "768MB" + maintenanceWorkMem: "64MB" + walBuffers: "16MB" + defaultStatisticsTarget: "100" + randomPageCost: "1.1" + logMinDurationStatement: "1000" + +podSecurityContext: + runAsNonRoot: true + runAsUser: 999 + runAsGroup: 999 + fsGroup: 999 + seccompProfile: + type: RuntimeDefault + +securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: false + capabilities: + drop: + - ALL diff --git a/charts/redis/Chart.yaml b/charts/redis/Chart.yaml new file mode 100644 index 0000000..05336dc --- /dev/null +++ b/charts/redis/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: gestion-redis +description: Redis 7 — gestion-commande +type: application +version: 0.1.0 +appVersion: "7" diff --git a/charts/redis/templates/_helpers.tpl b/charts/redis/templates/_helpers.tpl new file mode 100644 index 0000000..b001d21 --- /dev/null +++ b/charts/redis/templates/_helpers.tpl @@ -0,0 +1,20 @@ +{{- define "redis.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-redis" .Release.Name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} + +{{- define "redis.labels" -}} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} +app.kubernetes.io/name: redis +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "redis.selectorLabels" -}} +app.kubernetes.io/name: redis +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/charts/redis/templates/configmap.yaml b/charts/redis/templates/configmap.yaml new file mode 100644 index 0000000..631b48c --- /dev/null +++ b/charts/redis/templates/configmap.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "redis.fullname" . }}-config + labels: + {{- include "redis.labels" . | nindent 4 }} +data: + redis.conf: | + maxmemory {{ .Values.config.maxmemory }} + maxmemory-policy {{ .Values.config.maxmemoryPolicy }} + appendonly {{ .Values.config.appendonly }} + appendfsync {{ .Values.config.appendfsync }} + {{- if .Values.config.save }} + save {{ .Values.config.save }} + {{- else }} + save "" + {{- end }} + protected-mode no + loglevel notice + # Le mot de passe est injecté au démarrage via --requirepass diff --git a/charts/redis/templates/pvc.yaml b/charts/redis/templates/pvc.yaml new file mode 100644 index 0000000..4b403f5 --- /dev/null +++ b/charts/redis/templates/pvc.yaml @@ -0,0 +1,17 @@ +{{- if .Values.persistence.enabled }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "redis.fullname" . }}-data + labels: + {{- include "redis.labels" . | nindent 4 }} +spec: + accessModes: + - {{ .Values.persistence.accessMode }} + resources: + requests: + storage: {{ .Values.persistence.size }} + {{- if .Values.persistence.storageClass }} + storageClassName: {{ .Values.persistence.storageClass }} + {{- end }} +{{- end }} diff --git a/charts/redis/templates/secret.yaml b/charts/redis/templates/secret.yaml new file mode 100644 index 0000000..c28af41 --- /dev/null +++ b/charts/redis/templates/secret.yaml @@ -0,0 +1,12 @@ +{{- if not .Values.auth.password }} +{{- fail "auth.password is required (--set-string auth.password=...)" }} +{{- end }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "redis.fullname" . }} + labels: + {{- include "redis.labels" . | nindent 4 }} +type: Opaque +stringData: + REDIS_PASSWORD: {{ .Values.auth.password | quote }} diff --git a/charts/redis/templates/service.yaml b/charts/redis/templates/service.yaml new file mode 100644 index 0000000..8c12c0f --- /dev/null +++ b/charts/redis/templates/service.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "redis.fullname" . }} + labels: + {{- include "redis.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + {{- include "redis.selectorLabels" . | nindent 4 }} + ports: + - name: redis + port: {{ .Values.service.port }} + targetPort: redis + protocol: TCP +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ include "redis.fullname" . }}-headless + labels: + {{- include "redis.labels" . | nindent 4 }} +spec: + type: ClusterIP + clusterIP: None + selector: + {{- include "redis.selectorLabels" . | nindent 4 }} + ports: + - name: redis + port: {{ .Values.service.port }} + targetPort: redis diff --git a/charts/redis/templates/statefulset.yaml b/charts/redis/templates/statefulset.yaml new file mode 100644 index 0000000..7f8fc1d --- /dev/null +++ b/charts/redis/templates/statefulset.yaml @@ -0,0 +1,84 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "redis.fullname" . }} + labels: + {{- include "redis.labels" . | nindent 4 }} +spec: + serviceName: {{ include "redis.fullname" . }}-headless + replicas: 1 + selector: + matchLabels: + {{- include "redis.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "redis.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: redis + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + ports: + - name: redis + containerPort: 6379 + protocol: TCP + command: + - redis-server + - /etc/redis/redis.conf + - "--requirepass" + - "$(REDIS_PASSWORD)" + env: + - name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "redis.fullname" . }} + key: REDIS_PASSWORD + volumeMounts: + - name: data + mountPath: /data + - name: config + mountPath: /etc/redis/redis.conf + subPath: redis.conf + - name: tmp + mountPath: /tmp + livenessProbe: + exec: + command: + - sh + - -c + - redis-cli --no-auth-warning -a $REDIS_PASSWORD ping | grep PONG + initialDelaySeconds: 15 + periodSeconds: 10 + failureThreshold: 6 + readinessProbe: + exec: + command: + - sh + - -c + - redis-cli --no-auth-warning -a $REDIS_PASSWORD ping | grep PONG + initialDelaySeconds: 5 + periodSeconds: 5 + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: data + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ include "redis.fullname" . }}-data + {{- else }} + emptyDir: {} + {{- end }} + - name: config + configMap: + name: {{ include "redis.fullname" . }}-config + - name: tmp + emptyDir: {} diff --git a/charts/redis/values.yaml b/charts/redis/values.yaml new file mode 100644 index 0000000..45d4c2f --- /dev/null +++ b/charts/redis/values.yaml @@ -0,0 +1,61 @@ +# Nom des ressources (dont le Service ClusterIP joint par le backend). +# "redis" = valeur attendue par backend/values.yaml (database.host / redis.host). +fullnameOverride: "redis" + +image: + repository: redis + tag: "7-alpine" + pullPolicy: IfNotPresent + +# Injecté par le provisioner (voir deploy/chart-gestion/registry-credentials) +# si un compte Docker Hub authentifié est configuré — évite le rate-limit de +# pull anonyme partagé par IP de nœud. Vide = pull anonyme (défaut). +imagePullSecrets: [] + +auth: + # À surcharger via --set auth.password=xxx + password: "" + +persistence: + enabled: true + size: 2Gi + # Répliqué sur 2 nœuds (Longhorn) : survit à la perte d'un nœud. Voir + # deploy/longhorn/storageclass.yml pour le prérequis d'installation. + storageClass: "longhorn-replicated" + accessMode: ReadWriteOnce + +resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 500m + memory: 512Mi + +service: + type: ClusterIP + port: 6379 + +config: + maxmemory: "256mb" + # allkeys-lru : expulse les clés les moins récemment utilisées quand la mémoire est pleine + maxmemoryPolicy: "allkeys-lru" + appendonly: "yes" + appendfsync: "everysec" + # Désactiver les snapshots RDB (AOF suffit) + save: "" + +podSecurityContext: + runAsNonRoot: true + runAsUser: 999 + runAsGroup: 999 + fsGroup: 999 + seccompProfile: + type: RuntimeDefault + +securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL