Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongo helm charts added for performance benchmarking #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions mongo-helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: mongo
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
2 changes: 2 additions & 0 deletions mongo-helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# mongo-helm
helm charts for mongo
62 changes: 62 additions & 0 deletions mongo-helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "mongo.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 "mongo.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 "mongo.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "mongo.labels" -}}
helm.sh/chart: {{ include "mongo.chart" . }}
{{ include "mongo.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "mongo.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mongo.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "mongo.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "mongo.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
27 changes: 27 additions & 0 deletions mongo-helm/templates/mongodb-client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: {{ .Values.mongoclient.name }}
role: client
name: {{ .Values.mongoclient.name }}
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Values.mongoclient.name }}
role: client
template:
metadata:
labels:
app: {{ .Values.mongoclient.name }}
role: client
spec:
containers:
- image: "{{ .Values.mongoclient.image.repository }}:{{ .Values.mongoclient.image.tag | default .Chart.AppVersion }}"
name: {{ .Values.mongoclient.name }}
env:
- name: mongo-client_INITDB_ROOT_USERNAME
value: 'dummy'
- name: mongo-client_INITDB_ROOT_PASSWORD
value: 'dummy'
77 changes: 77 additions & 0 deletions mongo-helm/templates/standalone/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{{- if .Values.standalone.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mongo.fullname" . }}
labels:
role: mongo
{{- include "mongo.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
role: mongo
{{- include "mongo.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
role: mongo
{{- include "mongo.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "mongo.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: {{ .Values.secrets.name }}
key: username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.secrets.name }}
key: password
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: "mongo-data-dir"
mountPath: "/data/db"
nodeSelector:
kubernetes.io/arch: amd64
openebs.io/engine: mayastor
volumes:
- name: "mongo-data-dir"
persistentVolumeClaim:
claimName: {{ .Values.storage.pvcname }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
17 changes: 17 additions & 0 deletions mongo-helm/templates/standalone/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.standalone.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Values.storage.pvcname }}
spec:
accessModes:
- {{ .Values.storage.accessmode }}
resources:
requests:
storage: {{ .Values.storage.size }}
{{ if .Values.statefulset.multireplica.enabled }}
storageClassName: {{ .Values.statefulset.multireplica.scname }}
{{ else }}
storageClassName: {{ .Values.statefulset.singlereplica.scname }}
{{ end }}
{{- end }}
10 changes: 10 additions & 0 deletions mongo-helm/templates/standalone/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.standalone.enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.secrets.name }}
type: "Opaque"
data:
username: {{ .Values.secrets.username | b64enc | quote }}
password: {{ .Values.secrets.password | b64enc | quote }}
{{- end }}
17 changes: 17 additions & 0 deletions mongo-helm/templates/standalone/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.standalone.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "mongo.fullname" . }}
labels:
{{- include "mongo.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "mongo.selectorLabels" . | nindent 4 }}
{{- end }}
40 changes: 40 additions & 0 deletions mongo-helm/templates/statefulsets/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if .Values.ha.enabled }}
apiVersion: v1
data:
script.sh: |+
#!/bin/bash
set -ex
#Initiating the server

hostname=`hostname -f`
stsname=`hostname | cut -d "-" -f1`
db_hostname="$hostname:27017"
serviceproxy="mongodb-service.default.svc.cluster.local:27017"
echo "Hostname of Server is $hostname"
stsidentity=`hostname -f | cut -d "." -f1 | cut -d "-" -f2`

if [ $stsidentity -eq 0 ];then
mongosh <<EOF
rs.initiate()
EOF
mongosh <<EOF
var cfg = rs.conf();cfg.members[0].host="$stsname-0.$serviceproxy";
rs.reconfig(cfg);
EOF
mongosh <<EOF
db.getSiblingDB("admin").createUser({
user : "{{ .Values.statefulset.secrets.username }}",
pwd : "{{ .Values.statefulset.secrets.password }}",
roles: [ { role: "root", db: "admin" } ]});
EOF
elif [ $stsidentity -ne 0 ];then
mongosh mongodb://$stsname-0.$serviceproxy <<EOF
rs.add("$db_hostname")
rs.status()
EOF
fi

kind: ConfigMap
metadata:
name: mongo-replica
{{- end }}
26 changes: 26 additions & 0 deletions mongo-helm/templates/statefulsets/mongodb-service-headless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- if .Values.ha.enabled }}
apiVersion: v1
kind: Service
metadata:
labels:
name: {{ .Values.statefulset.service.name }}
name: {{ .Values.statefulset.service.name }}
spec:
clusterIP: None
clusterIPs:
- None
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- port: {{ .Values.service.port }}
protocol: TCP
targetPort: {{ .Values.statefulset.service.port }}
selector:
role: mongo
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
{{- end }}
10 changes: 10 additions & 0 deletions mongo-helm/templates/statefulsets/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.ha.enabled }}
apiVersion: v1
data:
password: {{ .Values.statefulset.secrets.password | b64enc | quote }}
username: {{ .Values.statefulset.secrets.username | b64enc | quote }}
kind: Secret
metadata:
name: {{ .Values.statefulset.secrets.name }}
type: Opaque
{{- end }}
Loading