diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..8d5c756df643ee05c62fb2b06afd53b9dcdf2855 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +dist/ \ No newline at end of file diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000000000000000000000000000000000000..a5a01069f5d9e9e577218be5325e1bc6d67b02bd --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,101 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "AppCtx.chartName" -}} +{{- default .Chart.Name | trunc 24 | trimSuffix "-" }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "AppCtx.chartNameVersion" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 30 chars in order to leave room for suffixes (because some Kubernetes name fields are limited to 63 chars by the DNS naming spec). +*/}} +{{- define "AppCtx.name" }} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s" $name | trunc 30 | trimSuffix "-"}} +{{- end }} + +{{/* +Create the API name +*/}} +{{- define "AppCtx.apiName" }} +{{- printf "%s-api" (include "AppCtx.name" .) | trunc 63 }} +{{- end }} + +{{/* +Create the Front name +*/}} +{{- define "AppCtx.frontName" }} +{{- printf "%s-front" (include "AppCtx.name" .) | trunc 63 }} +{{- end }} + +{{/* +Create the DB name +*/}} +{{- define "AppCtx.dbName" }} +{{- printf "%s-db" (include "AppCtx.name" .) | trunc 63 }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "AppCtx.selectorLabels" -}} +app.kubernetes.io/name: {{ include "AppCtx.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "AppCtx.labels" -}} +helm.sh/chart: {{ include "AppCtx.chartName" . }} +{{ include "AppCtx.selectorLabels" . }} +app.kubernetes.io/part-of: {{ include "AppCtx.chartName" . }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{- define "AppCtx.apiSelectorLabels" -}} +{{ include "AppCtx.selectorLabels" . }} +app.kubernetes.io/component: api +{{- end }} + +{{- define "AppCtx.apiLabels" -}} +{{ include "AppCtx.apiSelectorLabels" . }} +app.kubernetes.io/part-of: {{ include "AppCtx.chartName" . }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +app/language: java +app/version: {{ .Values.api.image.tag }} +{{- end }} + + +{{- define "AppCtx.frontSelectorLabels" -}} +{{ include "AppCtx.selectorLabels" . }} +app.kubernetes.io/component: front +{{- end }} + +{{- define "AppCtx.frontLabels" -}} +{{ include "AppCtx.frontSelectorLabels" . }} +app.kubernetes.io/part-of: {{ include "AppCtx.chartName" . }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +app/language: javascript +app/version: {{ .Values.front.image.tag }} +{{- end }} + +{{- define "AppCtx.dbSelectorLabels" -}} +{{ include "AppCtx.selectorLabels" . }} +app.kubernetes.io/component: db +{{- end }} + +{{- define "AppCtx.dbLabels" -}} +{{ include "AppCtx.dbSelectorLabels" . }} +app.kubernetes.io/part-of: {{ include "AppCtx.chartName" . }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +app/language: postgresql +app/version: {{ .Values.db.image.tag }} +{{- end }} diff --git a/templates/api-config.yaml b/templates/api-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..39d56d6d86ddfc54a312f671e71af6d04ffd5b19 --- /dev/null +++ b/templates/api-config.yaml @@ -0,0 +1,10 @@ +{{- if .Values.api.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "AppCtx.apiName" . }} + labels: {{ include "AppCtx.apiLabels" . | nindent 4 }} +data: + DB_ENDPOINT: "{{ template "AppCtx.dbName" . }}:5432" + DB_NAME: {{ .Values.db.name }} +{{- end }} \ No newline at end of file diff --git a/templates/api-deployment.yaml b/templates/api-deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..baf0af5ccff3e862142c1531b06a89f7b0741936 --- /dev/null +++ b/templates/api-deployment.yaml @@ -0,0 +1,79 @@ +{{- if .Values.api.enabled }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "AppCtx.apiName" . }} + labels: {{ include "AppCtx.apiLabels" . | nindent 4 }} +spec: + replicas: {{ .Values.api.replicaCount }} + selector: + matchLabels: {{ include "AppCtx.apiSelectorLabels" . | nindent 8 }} + template: + metadata: + labels: {{ include "AppCtx.apiLabels" . | nindent 10 }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/api-config.yaml") . | sha256sum }} + spec: + securityContext: + runAsUser: 1001 + runAsGroup: 1001 + imagePullSecrets: + - name: takima-school-registry + containers: + - name: api + image: {{ .Values.api.image.repository }}:{{ .Values.api.image.tag }} + resources: + requests: + memory: {{ .Values.api.requests.memory }} + cpu: {{ .Values.api.requests.cpu }} + limits: + memory: {{ .Values.api.limits.memory }} + cpu: {{ .Values.api.limits.cpu }} + startupProbe: + httpGet: + path: /actuator/health + port: 8080 + initialDelaySeconds: {{ .Values.api.startupProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.api.startupProbe.periodSeconds }} + successThreshold: 1 + failureThreshold: {{ .Values.api.startupProbe.failureThreshold }} + livenessProbe: + httpGet: + path: /actuator/health/liveness + port: 8080 + periodSeconds: 3 + successThreshold: 1 + failureThreshold: 3 + readinessProbe: + httpGet: + path: /actuator/health/readiness + port: 8080 + periodSeconds: 1 + successThreshold: 1 + failureThreshold: 3 + securityContext: + allowPrivilegeEscalation: false + ports: + - containerPort: 8080 + env: + - name: DB_ENDPOINT + valueFrom: + configMapKeyRef: + name: {{ template "AppCtx.apiName" . }} + key: DB_ENDPOINT + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: {{ template "AppCtx.apiName" . }} + key: DB_NAME + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: {{ template "AppCtx.dbName" . }}-credentials # Nom du secret + key: pg_username # nom de la clef dans le config map + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "AppCtx.dbName" . }}-credentials # Nom du secret + key: pg_password +{{- end }} \ No newline at end of file diff --git a/templates/api-ingress.yaml b/templates/api-ingress.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c8bb6b2f5ef3270c5e96ee719f139a7eaf46c110 --- /dev/null +++ b/templates/api-ingress.yaml @@ -0,0 +1,24 @@ +{{- if .Values.api.enabled }} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ template "AppCtx.apiName" . }} + labels: {{ include "AppCtx.apiLabels" . | nindent 4 }} +spec: + ingressClassName: nginx + rules: + - host: {{ .Values.api.ingress.host }} + http: + paths: + - backend: + service: + name: {{ template "AppCtx.apiName" . }} + port: + number: 80 + path: / + pathType: Prefix + tls: + - hosts: + - {{ .Values.api.ingress.host }} + secretName: app-wildcard +{{- end }} diff --git a/templates/api-service.yaml b/templates/api-service.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0f55be54a9ab93f72cb838eaf45ffe1766c4f38b --- /dev/null +++ b/templates/api-service.yaml @@ -0,0 +1,13 @@ +{{- if .Values.api.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "AppCtx.apiName" . }} + labels: {{ include "AppCtx.apiLabels" . | nindent 8 }} +spec: + selector: {{ include "AppCtx.apiSelectorLabels" . | nindent 4 }} + ports: + - protocol: TCP + port: 80 + targetPort: 8080 +{{- end }} \ No newline at end of file diff --git a/templates/front-config.yaml b/templates/front-config.yaml index da89df77a97e1c3bee1c975c1c7dbb9db99547b5..5d5fd459758f9349305b0c94701eed2bdc4d6d31 100644 --- a/templates/front-config.yaml +++ b/templates/front-config.yaml @@ -8,7 +8,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ .Values.name }}-front + name: {{ template "AppCtx.frontName" . }} data: API_URL: {{ $apiUrl }} {{- end }} \ No newline at end of file diff --git a/templates/front-deployment.yaml b/templates/front-deployment.yaml index fa7c697c84c6b69bc07da8282ea9a3952024706f..6e98e4b7e2cc3f858c71b60252542f733d10eea1 100644 --- a/templates/front-deployment.yaml +++ b/templates/front-deployment.yaml @@ -2,18 +2,17 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ .Values.name }}-front - labels: - app: front + name: {{ template "AppCtx.frontName" . }} + labels: {{ include "AppCtx.frontLabels" . | nindent 4 }} spec: replicas: {{ .Values.front.replicaCount }} selector: - matchLabels: - app: front + matchLabels: {{ include "AppCtx.frontSelectorLabels" . | nindent 8 }} template: metadata: - labels: - app: front + labels: {{ include "AppCtx.frontLabels" . | nindent 10 }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/front-config.yaml") . | sha256sum }} spec: imagePullSecrets: - name: takima-school-registry @@ -63,6 +62,6 @@ spec: - name: API_URL valueFrom: configMapKeyRef: - name: {{ .Values.name }}-front + name: {{ template "AppCtx.frontName" . }} key: API_URL {{- end }} \ No newline at end of file diff --git a/templates/front-ingress.yaml b/templates/front-ingress.yaml index 297d8009a95c0a9e763a5d13ff971c8bd00a678c..9d8648d701433f547ba39108e6ab108ac3344744 100644 --- a/templates/front-ingress.yaml +++ b/templates/front-ingress.yaml @@ -2,7 +2,8 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: {{ .Values.name }}-front + name: {{ template "AppCtx.frontName" . }} + labels: {{ include "AppCtx.frontLabels" . | nindent 4 }} spec: ingressClassName: nginx rules: @@ -11,7 +12,7 @@ spec: paths: - backend: service: - name: {{ .Values.name }}-front + name: {{ template "AppCtx.frontName" . }} port: number: 80 path: / diff --git a/templates/front-service.yaml b/templates/front-service.yaml index 8031d1a9e190946393c8359877c954bfb10ec2d5..29c82005e3fc7d556ec263b5c025f9ad8d7aeafb 100644 --- a/templates/front-service.yaml +++ b/templates/front-service.yaml @@ -2,10 +2,10 @@ apiVersion: v1 kind: Service metadata: - name: {{ .Values.name }}-front + name: {{ template "AppCtx.frontName" . }} + labels: {{ include "AppCtx.frontLabels" . | nindent 8 }} spec: - selector: - app: front + selector: {{ include "AppCtx.frontSelectorLabels" . | nindent 4 }} ports: - protocol: TCP port: 80 diff --git a/templates/pg-config.yaml b/templates/pg-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9704903ae231c8d0f29831a83f8dc63ad05b9015 --- /dev/null +++ b/templates/pg-config.yaml @@ -0,0 +1,10 @@ +{{- if .Values.db.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "AppCtx.dbName" . }} + labels: {{ include "AppCtx.dbLabels" . | nindent 4 }} +data: + db_name: {{ .Values.db.name }} + db_path: "/var/lib/postgresql/data/pgdata" +{{- end }} \ No newline at end of file diff --git a/templates/pg-credentials.yaml b/templates/pg-credentials.yaml new file mode 100644 index 0000000000000000000000000000000000000000..69b2d6efde5454707816e500c3ba84607df82db3 --- /dev/null +++ b/templates/pg-credentials.yaml @@ -0,0 +1,11 @@ +{{- if .Values.db.enabled }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ template "AppCtx.dbName" . }}-credentials + labels: {{ include "AppCtx.dbLabels" . | nindent 4 }} +type: Opaque +data: + pg_username: YWRtaW4= # user: admin + pg_password: dGVzdDEyMyo= # pwd: test123* +{{- end }} \ No newline at end of file diff --git a/templates/pg-deployment.yaml b/templates/pg-deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c4fd65ae807cc832e2a552bd9bd7e563930a75a4 --- /dev/null +++ b/templates/pg-deployment.yaml @@ -0,0 +1,52 @@ +{{- if .Values.db.enabled }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "AppCtx.dbName" . }} + labels: {{ include "AppCtx.dbLabels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: {{ include "AppCtx.dbSelectorLabels" . | nindent 8 }} + template: + metadata: + labels: {{ include "AppCtx.dbLabels" . | nindent 10 }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/front-config.yaml") . | sha256sum }} + spec: + containers: + - name: postgres + image: {{ .Values.db.image.repository }}:{{ .Values.db.image.tag }} + ports: + - containerPort: 80 + env: + - name: POSTGRES_DB + valueFrom: + configMapKeyRef: + name: {{ template "AppCtx.dbName" . }} # Nom du configmap + key: db_name # nom de la clef dans le config map contenant le nom de la DB + - name: PGDATA + valueFrom: + configMapKeyRef: + name: {{ template "AppCtx.dbName" . }} # Nom du configmap + key: db_path # nom de la clef dans le configMap contenant path ou installer la db dans le volume persistant + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: {{ template "AppCtx.dbName" . }}-credentials # Nom du secret + key: pg_username # nom de la clef dans le secret + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "AppCtx.dbName" . }}-credentials # Nom du secret + key: pg_password # nom de la clef dans le secret contenant le password + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: pg-data + imagePullSecrets: + - name: takima-school-registry + volumes: + - name: pg-data + persistentVolumeClaim: + claimName: {{ template "AppCtx.dbName" . }} +{{- end }} diff --git a/templates/pg-pvc.yaml b/templates/pg-pvc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1ba729475407bdff493a12e2492e54c3930c4fa1 --- /dev/null +++ b/templates/pg-pvc.yaml @@ -0,0 +1,15 @@ +{{- if .Values.db.enabled }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ template "AppCtx.dbName" . }} + labels: {{ include "AppCtx.dbLabels" . | nindent 4 }} +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: {{ .Values.db.pvc.size }} + storageClassName: {{ .Values.db.pvc.storageClass }} +{{- end }} diff --git a/templates/pg-service.yaml b/templates/pg-service.yaml new file mode 100644 index 0000000000000000000000000000000000000000..547fd0c01f9db942d9b287c0ae7c279c616c5194 --- /dev/null +++ b/templates/pg-service.yaml @@ -0,0 +1,12 @@ +{{- if .Values.db.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "AppCtx.dbName" . }} + labels: {{ include "AppCtx.dbLabels" . | nindent 4 }} +spec: + selector: {{ include "AppCtx.dbSelectorLabels" . | nindent 4 }} + type: ClusterIP + ports: + - port: 5432 +{{- end}} diff --git a/values.prod.yaml b/values.prod.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fa7675fa763933958f0e624b5d791f5046d3c0a6 --- /dev/null +++ b/values.prod.yaml @@ -0,0 +1,40 @@ +# Default values for CDB app. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +nameOverride: mycdb-prod + +api: + image: + tag: latest + replicaCount: 2 + requests: + memory: "192M" + cpu: "0.2" + limits: + memory: "256M" + cpu: "1" + startupProbe: + initialDelaySeconds: 20 + periodSeconds: 3 + failureThreshold: 5 + ingress: + tlsEnabled: true + host: api.nnowakowski.takima.school + +front: + image: + tag: latest + replicaCount: 1 + ingress: + tlsEnabled: true + host: www.nnowakowski.takima.school + +db: + image: + tag: latest + pvc: + storageClass: gp2 + size: 512Mi + credentials: + user: cdb + pwd: cdb123 \ No newline at end of file diff --git a/values.staging.yaml b/values.staging.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a9c57c1df3318ce122700f27ff28e6858b746d00 --- /dev/null +++ b/values.staging.yaml @@ -0,0 +1,40 @@ +# Default values for CDB app. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +nameOverride: mycdb-staging + +api: + image: + tag: latest + replicaCount: 1 + requests: + memory: "128M" + cpu: "0.1" + limits: + memory: "256M" + cpu: "1" + startupProbe: + initialDelaySeconds: 20 + periodSeconds: 3 + failureThreshold: 5 + ingress: + tlsEnabled: true + host: api-staging.nnowakowski.takima.school + +front: + image: + tag: latest + replicaCount: 1 + ingress: + tlsEnabled: true + host: www-staging.nnowakowski.takima.school + +db: + image: + tag: latest + pvc: + storageClass: gp2 + size: 512Mi + credentials: + user: cdb + pwd: cdb123 diff --git a/values.yaml b/values.yaml index 78a62389ce04b5faa867e601e5f2c8c3b2871141..9383700c7af9637ca60ad22427254d6180792e2e 100644 --- a/values.yaml +++ b/values.yaml @@ -1,12 +1,26 @@ # Default values for CDB app. # This is a YAML-formatted file. # Declare variables to be passed into your templates. -# We have only done front for now -name: cdb +nameOverride: mycdb api: + enabled: true + image: + repository: registry.gitlab.com/takima-school/images/cdb/api + tag: latest + replicaCount: 1 + requests: + memory: "192M" + cpu: "0.2" + limits: + memory: "256M" + cpu: "1" + startupProbe: + initialDelaySeconds: 30 + periodSeconds: 3 + failureThreshold: 5 ingress: - tlsEnabled: false + tlsEnabled: true host: api.nnowakowski.takima.school front: @@ -16,5 +30,19 @@ front: tag: latest replicaCount: 1 ingress: - tlsEnabled: false - host: front.nnowakowski.takima.school \ No newline at end of file + tlsEnabled: true + host: www.nnowakowski.takima.school + +db: + enabled: true + name: cdb-db + image: + repository: registry.takima.io/school/proxy/postgres + tag: latest + pvc: + storageClass: gp2 + size: 512Mi + credentials: + user: cdb + pwd: cdb123 +