From ee29cfe6f0ca461999fa651a32cee91ec7826462 Mon Sep 17 00:00:00 2001 From: "georgi.todorov" <georgi.todorov@optimal-industries.com> Date: Thu, 19 Jan 2023 14:55:02 +0200 Subject: [PATCH] Add mongo configs --- .gitlab-ci.yml | 21 +++++++ Chart.yaml | 5 ++ templates/_helpers.tpl | 40 +++++++++++++ templates/mongodb-service.yaml | 23 ++++++++ templates/mongodb-statefulset.yaml | 92 ++++++++++++++++++++++++++++++ values.yaml | 20 +++++++ 6 files changed, 201 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Chart.yaml create mode 100644 templates/_helpers.tpl create mode 100644 templates/mongodb-service.yaml create mode 100644 templates/mongodb-statefulset.yaml create mode 100644 values.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..1afa27d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,21 @@ +image: nexus.tech.vereign.com:6001/helm:3.5.3 + +include: + - project: 'gaiax/tsa/ci-helpers' + file: 'helm-package.yml' + +stages: + - lint + - package + +helm-lint: + extends: .helm-lint + stage: lint + tags: + - amd64-docker + +helm-package: + extends: .helm-package + stage: package + tags: + - amd64-docker diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000..7215f97 --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "v0.0.1" +name: mongodb +version: "0.0.1" + diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000..aa9bae6 --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,40 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "mongodb.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "mongodb.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 -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "mongodb.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{- define "mongodb.metricsSecret" -}} + {{- if .Values.auth.existingMetricsSecret -}} + {{- .Values.auth.existingMetricsSecret -}} + {{- else -}} + {{- template "mongodb.fullname" . -}}-metrics + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/templates/mongodb-service.yaml b/templates/mongodb-service.yaml new file mode 100644 index 0000000..5794ebf --- /dev/null +++ b/templates/mongodb-service.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "mongodb.name" . }} + namespace: {{ template "mongodb.name" . }} + labels: + name: {{ template "mongodb.name" . }} +spec: + ports: + - protocol: TCP + port: {{ .Values.port }} + targetPort: {{ .Values.port }} + selector: + name: {{ template "mongodb.name" . }} + clusterIP: None + clusterIPs: + - None + type: ClusterIP + sessionAffinity: None + ipFamilies: + - IPv4 + ipFamilyPolicy: SingleStack + internalTrafficPolicy: Cluster diff --git a/templates/mongodb-statefulset.yaml b/templates/mongodb-statefulset.yaml new file mode 100644 index 0000000..11b35b0 --- /dev/null +++ b/templates/mongodb-statefulset.yaml @@ -0,0 +1,92 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ template "mongodb.name" . }} + namespace: {{ template "mongodb.name" . }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + name: {{ template "mongodb.name" . }} + template: + metadata: + creationTimestamp: null + labels: + name: {{ template "mongodb.name" . }} + spec: + containers: + - name: {{ template "mongodb.name" . }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + command: + - mongod + - '--port=27017' + - '--dbpath=/data/db' + - '--replSet=rs0' + - '--bind_ip_all' + ports: + - containerPort: {{ .Values.port }} + protocol: TCP + env: + - name: MONGO_INITDB_ROOT_USERNAME + value: {{ .Values.mongo.user }} + - name: MONGO_INITDB_ROOT_PASSWORD + value: {{ .Values.mongo.pass }} + - name: MONGO_REPLICA_SET_NAME + value: {{ .Values.mongo.replicaSetName }} + resources: {} + volumeMounts: + - name: mongo-persistent-storage + mountPath: /data/db + livenessProbe: + exec: + command: + - >- + test $(echo "rs.initiate().ok || rs.status().ok" | mongo -u + root -p root --quiet) -eq 1 + initialDelaySeconds: 10 + timeoutSeconds: 1 + periodSeconds: 30 + successThreshold: 1 + failureThreshold: 3 + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + imagePullPolicy: Always + - name: {{ template "mongodb.name" . }}-sidecar + image: cvallance/mongo-k8s-sidecar + env: + - name: MONGO_SIDECAR_POD_LABELS + value: name=mongo + - name: KUBERNETES_MONGO_SERVICE_NAME + value: {{ template "mongodb.name" . }} + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + imagePullPolicy: Always + restartPolicy: Always + terminationGracePeriodSeconds: 10 + dnsPolicy: ClusterFirst + serviceAccountName: {{ template "mongodb.name" . }} + serviceAccount: {{ template "mongodb.name" . }} + securityContext: {} + schedulerName: default-scheduler + volumeClaimTemplates: + - kind: PersistentVolumeClaim + apiVersion: v1 + metadata: + name: mongo-persistent-storage + creationTimestamp: null + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.persistentVolume.size | quote }} + storageClassName: standard + volumeMode: Filesystem + serviceName: {{ template "mongodb.name" . }} + podManagementPolicy: OrderedReady + updateStrategy: + type: RollingUpdate + rollingUpdate: + partition: 0 + revisionHistoryLimit: 10 \ No newline at end of file diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..2d01548 --- /dev/null +++ b/values.yaml @@ -0,0 +1,20 @@ +# Mongo replica count +replicas: 1 + +# Mongo service port +port: 27017 + +# Mongo replSetName, user and pass +mongo: + replicaSetName: rs0 + user: "" + pass: "" + +# Specs for the MongoDB image +image: + repository: mongo + tag: 3.6 + +# Select desired volume size +persistentVolume: + size: 10Gi \ No newline at end of file -- GitLab