diff --git a/mongo-helm/Chart.yaml b/mongo-helm/Chart.yaml new file mode 100644 index 0000000..638bb45 --- /dev/null +++ b/mongo-helm/Chart.yaml @@ -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" diff --git a/mongo-helm/README.md b/mongo-helm/README.md new file mode 100644 index 0000000..1b23339 --- /dev/null +++ b/mongo-helm/README.md @@ -0,0 +1,2 @@ +# mongo-helm +helm charts for mongo diff --git a/mongo-helm/templates/_helpers.tpl b/mongo-helm/templates/_helpers.tpl new file mode 100644 index 0000000..cce4e1b --- /dev/null +++ b/mongo-helm/templates/_helpers.tpl @@ -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 }} diff --git a/mongo-helm/templates/mongodb-client.yaml b/mongo-helm/templates/mongodb-client.yaml new file mode 100644 index 0000000..733794d --- /dev/null +++ b/mongo-helm/templates/mongodb-client.yaml @@ -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' diff --git a/mongo-helm/templates/standalone/deployment.yaml b/mongo-helm/templates/standalone/deployment.yaml new file mode 100644 index 0000000..f792375 --- /dev/null +++ b/mongo-helm/templates/standalone/deployment.yaml @@ -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 }} diff --git a/mongo-helm/templates/standalone/pvc.yaml b/mongo-helm/templates/standalone/pvc.yaml new file mode 100644 index 0000000..38003f2 --- /dev/null +++ b/mongo-helm/templates/standalone/pvc.yaml @@ -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 }} diff --git a/mongo-helm/templates/standalone/secret.yaml b/mongo-helm/templates/standalone/secret.yaml new file mode 100644 index 0000000..2f48036 --- /dev/null +++ b/mongo-helm/templates/standalone/secret.yaml @@ -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 }} diff --git a/mongo-helm/templates/standalone/service.yaml b/mongo-helm/templates/standalone/service.yaml new file mode 100644 index 0000000..ec438e4 --- /dev/null +++ b/mongo-helm/templates/standalone/service.yaml @@ -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 }} diff --git a/mongo-helm/templates/statefulsets/configmap.yaml b/mongo-helm/templates/statefulsets/configmap.yaml new file mode 100644 index 0000000..069e56e --- /dev/null +++ b/mongo-helm/templates/statefulsets/configmap.yaml @@ -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 < /tmp/script-log"] + name: mongod-container + ports: + - containerPort: 27017 + protocol: TCP + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /data/db + name: mongodb-persistent-storage-claim + - mountPath: /tmp/scripts + name: mongo-scripts + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 10 + volumes: + - configMap: + defaultMode: 511 + name: mongo-replica + name: mongo-scripts + updateStrategy: + type: RollingUpdate + volumeClaimTemplates: + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + annotations: + {{ if .Values.statefulset.multireplica.enabled }} + volume.beta.kubernetes.io/storage-class: {{ .Values.statefulset.multireplica.scname }} + {{ else }} + volume.beta.kubernetes.io/storage-class: {{ .Values.statefulset.singlereplica.scname }} + {{ end }} + creationTimestamp: null + name: mongodb-persistent-storage-claim + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.statefulset.volume }} + volumeMode: Filesystem +{{- end }} diff --git a/mongo-helm/templates/tests/test-connection.yaml b/mongo-helm/templates/tests/test-connection.yaml new file mode 100644 index 0000000..9b9cee4 --- /dev/null +++ b/mongo-helm/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "mongo.fullname" . }}-test-connection" + labels: + {{- include "mongo.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "mongo.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/mongo-helm/templates/ycsb.yaml b/mongo-helm/templates/ycsb.yaml new file mode 100644 index 0000000..d43d64b --- /dev/null +++ b/mongo-helm/templates/ycsb.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Values.ycsb.name }} + labels: + app: {{ .Values.ycsb.name }} + role: client +spec: + replicas: 1 + selector: + matchLabels: + app: {{ .Values.ycsb.name }} + role: client + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + app: {{ .Values.ycsb.name }} + role: client + 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.ycsb.image.repository }}/{{ .Values.ycsb.image.name }}:{{ .Values.ycsb.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: ["sleep", "3650d"] diff --git a/mongo-helm/values.yaml b/mongo-helm/values.yaml new file mode 100644 index 0000000..e229fa6 --- /dev/null +++ b/mongo-helm/values.yaml @@ -0,0 +1,143 @@ +# Default values for mongo. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +#replicaCount: 1 #default replica count for standalone=1 & ha=3 + +standalone: #Creates standalone deployment + enabled: false +ha: #Creates HA statefulset + enabled: false + +#############################IMAGE SECTION######################################### + +image: + repository: mongo + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "latest" + +############################HA STATEFULSET SECTION################################ + +statefulset: + name: mongod #Statefulset name + volume: 20Gi #PVC Volume size + secrets: + name: secrets #Secret Name + username: admin #DB User Name + password: admin #DB Password + service: + name: mongodb-service #headless Service Name + port: 27017 #headles service Port + type: ClusterIP #headless service type + +###########################MAYASTOR VOLUME REPLICA SECTION############################################ + + singlereplica: # Single replica mayastor Volume + scname: # Single replica sc name + multireplica: # Multi replicas mayastor Volume + enabled: false + scname: #Three replica sc name + +#############################################MONGO CLIENT SECTION#################################### + +mongoclient: + name: mongo-client #Mongo Client deployment name + image: + repository: mongo + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "latest" +#############################################YCSB SECTION######################################## + +ycsb: + name: ycsb + image: + repository: thulaseebyt + name: ycsb + pullPolicy: IfNotPresent + tag: "latest" + +###########################################STANDALONE STORAGE SECTION###################################### + +storage: #Storage section for standalone + pvcname: mongo-data # PVC name + size: 20Gi #pvc size + accessmode: ReadWriteOnce +########################################STANDALONE SECRETS SECTION############################################ + +secrets: + name: mongo-creds + username: admin + password: admin123 + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: false + # 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: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 27017 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {}