Skip to content
Snippets Groups Projects
Commit 34066c4e authored by Georgi Todorov's avatar Georgi Todorov
Browse files

Merge branch 'mongo-custom-helm' into 'main'

mongo-custom-helm

See merge request !1
parents eb4ed44f 62d5acf5
No related branches found
No related tags found
1 merge request!1mongo-custom-helm
Pipeline #58433 passed
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
apiVersion: v1
appVersion: "v0.0.1"
name: mongodb
version: "0.0.1"
# mongodb-helm # mongodb-helm
1. This helm chart deploys mongodb replicaSet with specific mongo version - 3.6
- Also it creates automatically service account, cluster account and clusterRole binding
2. After the first deployment we need to create root user:
- open terminal in mongo pod
- execute "mongo" command
- after that it will enter in the primary replicaSet then execute "use admin"
- then "db.createUser({ user: "root" , pwd: "root", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})"
When the root user is created we dont need to do that after every deployment because the data is persisted in the volume and wont be lost until volume deletion.
3. We need to create the databases and insert the collections manualy. (This has to be automated from the devs)
- open terminal in mongo pod
- execute "mongo" command again
- then execute all the scripts that are creating the collections and the databases (The sctipts are located in the Workspace repository in init.db folder)
\ No newline at end of file
{{/* 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 -}}
\ No newline at end of file
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ template "mongodb.name" . }}
rules:
- verbs:
- '*'
apiGroups:
- '*'
resources:
- '*'
\ No newline at end of file
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ template "mongodb.name" . }}
subjects:
- kind: ServiceAccount
name: {{ template "mongodb.name" . }}
namespace: {{ .Release.Namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "mongodb.name" . }}
apiVersion: v1
kind: Service
metadata:
name: {{ template "mongodb.name" . }}
namespace: {{ .Release.Namespace }}
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
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "mongodb.name" . }}
namespace: {{ .Release.Namespace }}
automountServiceAccountToken: true
\ No newline at end of file
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ template "mongodb.name" . }}
namespace: {{ .Release.Namespace }}
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
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=mongodb
- 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
# Mongo replica count
replicas: 1
# Mongo service port
port: 27017
# Mongo replSetName, user and pass
mongo:
replicaSetName: rs0
user: "root"
pass: "root"
# Specs for the MongoDB image
image:
repository: mongo
tag: 3.6
# Select desired volume size
persistentVolume:
size: 10Gi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment