From 2be53934ea4558c25b73e7152ac58ef5c55bf026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 14 Feb 2022 00:08:25 +0100 Subject: [PATCH] finish helm --- helmchart/Chart.yaml | 4 +- helmchart/templates/configmap.yaml | 6 +++ helmchart/templates/deployment.yaml | 11 +++-- helmchart/templates/postgresql.yaml | 62 +++++++++++++++++++++++++ helmchart/templates/serviceaccount.yaml | 12 ----- helmchart/values.yaml | 21 +++++---- 6 files changed, 89 insertions(+), 27 deletions(-) create mode 100644 helmchart/templates/configmap.yaml create mode 100644 helmchart/templates/postgresql.yaml delete mode 100644 helmchart/templates/serviceaccount.yaml diff --git a/helmchart/Chart.yaml b/helmchart/Chart.yaml index 9b8f7ed..cc8f02e 100644 --- a/helmchart/Chart.yaml +++ b/helmchart/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 -name: helmchart -description: A Helm chart for Kubernetes +name: mealapi +description: A fun meal api # A chart can be either an 'application' or a 'library' chart. # diff --git a/helmchart/templates/configmap.yaml b/helmchart/templates/configmap.yaml new file mode 100644 index 0000000..511fa20 --- /dev/null +++ b/helmchart/templates/configmap.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: meal-api-config +data: + DATABASE_URI: {{ .Values.configmap.dburi }} diff --git a/helmchart/templates/deployment.yaml b/helmchart/templates/deployment.yaml index 0c260cc..3d8f393 100644 --- a/helmchart/templates/deployment.yaml +++ b/helmchart/templates/deployment.yaml @@ -1,3 +1,4 @@ +--- apiVersion: apps/v1 kind: Deployment metadata: @@ -24,7 +25,6 @@ spec: imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} - serviceAccountName: {{ include "helmchart.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: @@ -33,17 +33,20 @@ spec: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + envFrom: + - configMapRef: + name: meal-api-config ports: - name: http - containerPort: 80 + containerPort: 8080 protocol: TCP livenessProbe: httpGet: - path: / + path: /healthz port: http readinessProbe: httpGet: - path: / + path: /healthz port: http resources: {{- toYaml .Values.resources | nindent 12 }} diff --git a/helmchart/templates/postgresql.yaml b/helmchart/templates/postgresql.yaml new file mode 100644 index 0000000..d7db432 --- /dev/null +++ b/helmchart/templates/postgresql.yaml @@ -0,0 +1,62 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: meal-api-postgres-pvc +spec: + storageClassName: {{ .Values.postgres.storage.provider }} + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.postgres.storage.size }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: meal-api-postgres +spec: + replicas: 1 + selector: + matchLabels: + app: meal-api-postgres + template: + metadata: + labels: + app: meal-api-postgres + spec: + volumes: + - name: data + persistentVolumeClaim: + claimName: meal-api-postgres-pvc + containers: + - name: meal-api-postgres + image: "postgres:14" + envFrom: + - configMapRef: + name: meal-api-postgres-config + volumeMounts: + - mountPath: /var/lib/postgresql + name: data +--- +apiVersion: v1 +kind: Service +metadata: + name: meal-api-postgres +spec: + selector: + app: meal-api-postgres + ports: + - name: {{ .Values.postgres.name }} + protocol: TCP + port: 5432 + targetPort: 5432 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: meal-api-postgres-config +data: + POSTGRES_PASSWORD: {{ .Values.postgres.password }} + POSTGRES_USER: {{ .Values.postgres.user }} + POSTGRES_DB: {{ .Values.postgres.database }} \ No newline at end of file diff --git a/helmchart/templates/serviceaccount.yaml b/helmchart/templates/serviceaccount.yaml deleted file mode 100644 index 0ff9959..0000000 --- a/helmchart/templates/serviceaccount.yaml +++ /dev/null @@ -1,12 +0,0 @@ -{{- if .Values.serviceAccount.create -}} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ include "helmchart.serviceAccountName" . }} - labels: - {{- include "helmchart.labels" . | nindent 4 }} - {{- with .Values.serviceAccount.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -{{- end }} diff --git a/helmchart/values.yaml b/helmchart/values.yaml index 063e9f0..f870b6c 100644 --- a/helmchart/values.yaml +++ b/helmchart/values.yaml @@ -14,15 +14,6 @@ imagePullSecrets: [] nameOverride: "" fullnameOverride: "" -serviceAccount: - # Specifies whether a service account should be created - create: true - # Annotations to add to the service account - annotations: {} - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: "" - podAnnotations: {} podSecurityContext: {} @@ -80,3 +71,15 @@ nodeSelector: {} tolerations: [] affinity: {} + +postgres: + name: postgres-meapi + user: meapi-postgres + password: mealapi-postgres + database: mealapi + storage: + size: 1Gi + privder: longhorn + +configmap: + dburi: "postgresql://meapi-postgres:mealapi-postgres@postgres-meapi:5432/mealapi" \ No newline at end of file