diff --git a/manifest.yaml b/manifest.yaml index 998bbd9e..6255403c 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -60,22 +60,89 @@ apiVersion: apps/v1 kind: Deployment metadata: name: ${CI_PROJECT_PATH_SLUG}-deployment + labels: + app: ${CI_PROJECT_PATH_SLUG}-app spec: - replicas: 1 selector: matchLabels: app: ${CI_PROJECT_PATH_SLUG}-app + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + maxSurge: 1 template: metadata: labels: app: ${CI_PROJECT_PATH_SLUG}-app spec: + securityContext: + runAsUser: 82 + runAsGroup: 82 + fsGroup: 82 + fsGroupChangePolicy: OnRootMismatch + terminationGracePeriodSeconds: 30 + imagePullSecrets: + - name: docker-registry-credentials + affinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - ${CI_PROJECT_PATH_SLUG}-app + topologyKey: kubernetes.io/hostname + namespaces: + - ${KUBE_NAMESPACE} + volumes: + - name: laravel-cache + emptyDir: {} + - name: laravel-views + emptyDir: {} containers: - name: ${CI_PROJECT_PATH_SLUG}-container image: $IMAGE_TAG + imagePullPolicy: IfNotPresent + env: + - name: XDG_CONFIG_HOME # For tinker + value: /tmp envFrom: - configMapRef: name: ${CI_PROJECT_PATH_SLUG}-config-map + ports: + - name: http + containerPort: 80 + protocol: TCP + volumeMounts: + - name: laravel-cache + mountPath: /app/srcs/bootstrap/cache + - name: laravel-views + mountPath: /app/srcs/storage/framework/views + readinessProbe: + httpGet: + path: /up + port: http + initialDelaySeconds: 10 + periodSeconds: 10 + timeoutSeconds: 3 + failureThreshold: 3 + livenessProbe: + httpGet: + path: /up + port: http + initialDelaySeconds: 30 + periodSeconds: 20 + timeoutSeconds: 3 + failureThreshold: 3 + startupProbe: + httpGet: + path: /up + port: http + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 24 resources: limits: cpu: "${APP_CI_CPU_LIMIT}" @@ -83,6 +150,11 @@ spec: requests: cpu: "${APP_CI_CPU_REQUEST}" memory: "${APP_CI_MEMORY_REQUEST}" + securityContext: + # TODO : valider le POC + # readOnlyRootFilesystem: true + # TODO : a priori incompatible avec PVC + # allowPrivilegeEscalation: false - name: ${CI_PROJECT_PATH_SLUG}-queue-worker image: $IMAGE_TAG lifecycle: @@ -103,13 +175,11 @@ spec: envFrom: - configMapRef: name: ${CI_PROJECT_PATH_SLUG}-config-map - imagePullSecrets: - - name: docker-registry-credentials - securityContext: - runAsUser: 82 - runAsGroup: 82 - fsGroup: 82 - fsGroupChangePolicy: "OnRootMismatch" + securityContext: + # TODO : valider le POC + # readOnlyRootFilesystem: true + # TODO : a priori incompatible avec PVC + # allowPrivilegeEscalation: false --- apiVersion: v1 kind: Service @@ -119,8 +189,10 @@ spec: selector: app: ${CI_PROJECT_PATH_SLUG}-app ports: - - port: 80 - targetPort: 80 + - name: http + port: 80 + targetPort: http + protocol: TCP --- apiVersion: traefik.io/v1alpha1 kind: IngressRoute @@ -131,7 +203,7 @@ spec: - web - websecure routes: - - match: Host(`${APP_DOMAIN}`) + - match: Host(`${APP_DOMAIN}`) || Host(`www.${APP_DOMAIN}`) kind: Rule services: - name: ${CI_PROJECT_PATH_SLUG}-service @@ -141,3 +213,118 @@ spec: tls: secretName: ${CRT_TLS_NAME} +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: ${CI_PROJECT_PATH_SLUG}-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: ${CI_PROJECT_PATH_SLUG}-deployment + minReplicas: 1 + maxReplicas: 2 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 60 + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: 75 + behavior: + scaleUp: + stabilizationWindowSeconds: 0 + selectPolicy: Max + policies: + - type: Percent + value: 100 + periodSeconds: 60 + - type: Pods + value: 2 + periodSeconds: 60 + scaleDown: + stabilizationWindowSeconds: 300 + selectPolicy: Min + policies: + - type: Percent + value: 25 + periodSeconds: 60 + - type: Pods + value: 1 + periodSeconds: 60 +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: ${CI_PROJECT_PATH_SLUG}-cronjob +spec: + schedule: "* * * * *" + successfulJobsHistoryLimit: 1 + failedJobsHistoryLimit: 1 + concurrencyPolicy: Forbid + jobTemplate: + spec: + template: + spec: + restartPolicy: OnFailure + securityContext: + runAsUser: 82 + runAsGroup: 82 + fsGroup: 82 + fsGroupChangePolicy: OnRootMismatch + affinity: + podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - ${CI_PROJECT_PATH_SLUG}-app + topologyKey: kubernetes.io/hostname + namespaces: + - ${KUBE_NAMESPACE} + imagePullSecrets: + - name: docker-registry-credentials + volumes: + - name: laravel-cache + emptyDir: {} + - name: laravel-views + emptyDir: {} + containers: + - name: ${CI_PROJECT_PATH_SLUG}-scheduled + image: $IMAGE_TAG + imagePullPolicy: IfNotPresent + workingDir: /app/srcs + command: + - php + args: + - artisan + - schedule:run + envFrom: + - configMapRef: + name: ${CI_PROJECT_PATH_SLUG}-config-map + volumeMounts: + - name: laravel-cache + mountPath: /app/srcs/bootstrap/cache + - name: laravel-views + mountPath: /app/srcs/storage/framework/views + resources: + requests: + cpu: "${APP_CI_CPU_REQUEST}" + memory: "${APP_CI_MEMORY_REQUEST}" + limits: + cpu: "${APP_CI_CPU_LIMIT}" + memory: "${APP_CI_MEMORY_LIMIT}" + securityContext: + # TODO : valider le POC + # readOnlyRootFilesystem: true + # TODO : a priori incompatible avec PVC + # allowPrivilegeEscalation: false