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

Add Helm chart for MongoDB sharded cluster #769

Merged
merged 5 commits into from
Jan 25, 2024
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ output.txt
.vscode

# Chart dependencies
/build/charts/yorkie-cluster/charts/*.tgz
**/charts/*.tgz
/build/charts/yorkie-argocd/charts/
/build/charts/yorkie-monitoring/charts/
/build/charts/yorkie-mongodb/charts/
24 changes: 0 additions & 24 deletions build/charts/yorkie-cluster/charts/mongodb/Chart.yaml

This file was deleted.

21 changes: 5 additions & 16 deletions build/charts/yorkie-cluster/values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Configuration for Yorkie cluster
yorkie:
name: yorkie
namespace: &namespace yorkie
namespace: yorkie

autoscaling:
enabled: false
Expand All @@ -13,26 +13,15 @@ yorkie:
tag: ""

args:
dbUrl: &mongoUrl mongodb
dbPort: &mongoPort 27017
dbUrl: mongodb.mongodb.svc.cluster.local
dbPort: 27017

ports:
rpcPort: 8080
profilingPort: 8081

resources: {}

# Configuration for internal mongoDB
mongodb:
enabled: true

namespace: *namespace
name: *mongoUrl
port: *mongoPort

storageClassName: standard
storageSize: 1Gi

# Configuration for istio ingress gateway
ingressGateway:
consistentHash:
Expand All @@ -43,7 +32,7 @@ ingressGateway:
maglev:
enabled: true
tableSize: 65537

ringHash:
enabled: false
minimumRingSize: 1024
Expand All @@ -63,7 +52,7 @@ ingress:
hosts:
enabled: false
apiHost: api.yorkie.dev

alb:
enabled: false
certArn: arn:aws:acm:ap-northeast-2:123412341234:certificate/1234-1234-1234-1234-1234
Expand Down
6 changes: 6 additions & 0 deletions build/charts/yorkie-mongodb/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: mongodb-sharded
repository: https://charts.bitnami.com/bitnami
version: 7.2.2
digest: sha256:ae306fa705473ca5e99f02fcca27ebb5900cf4bdf4357472f8b5006c9c4fca24
generated: "2024-01-23T20:44:36.400805+09:00"
20 changes: 20 additions & 0 deletions build/charts/yorkie-mongodb/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v2
name: yorkie-mongodb
description: yorkie-mongodb provides the deployment of MongoDB for the yorkie server, supporting both standalone mode and sharded cluster mode.
type: application
icon: https://raw.githubusercontent.com/yorkie-team/yorkie-team.github.io/main/public/favicon-512x512.png
maintainers:
- name: hackerwins
email: susukang98@gmail.com
- name: krapie
email: krapi0314@gmail.com

version: 0.4.13
appVersion: "0.4.13"
kubeVersion: ">=1.23.0-0"

hackerwins marked this conversation as resolved.
Show resolved Hide resolved
dependencies:
- name: mongodb-sharded
version: "7.2.2"
repository: "https://charts.bitnami.com/bitnami"
condition: sharded.enabled
70 changes: 70 additions & 0 deletions build/charts/yorkie-mongodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# yorkie-mongodb

Installs MongoDB for the yorkie server, supporting both standalone mode and sharded cluster mode for storing yorkie data.

## Prerequisites

- Kubernetes 1.24+
- Helm 3+

## Get Helm Repository Info

```bash
helm repo add yorkie-team https://yorkie-team.github.io/yorkie/helm-charts
helm repo update
```

_See [`helm repo`](https://helm.sh/docs/helm/helm_repo/) for command documentation._

## Install Helm Chart

```bash
# Create mongodb namespace
kubectl create namespace mongodb

# Install yorkie monitoring helm chart
helm install [RELEASE_NAME] yorkie-team/yorkie-mongodb --namespace mongodb --set=sharded.enabled=true
```

_See [configuration](#configuration) below for custom installation_

_See [`helm install`](https://helm.sh/docs/helm/helm_install/) for command documentation._

## Dependencies

By default this chart installs additional, dependent charts:

- [mongodb-sharded](https://github.com/bitnami/charts/tree/main/bitnami/mongodb-sharded)

_See [`helm dependency`](https://helm.sh/docs/helm/helm_dependency/) for command documentation._

## Uninstall Helm Chart

```bash
helm uninstall [RELEASE_NAME] -n mongodb
```

This removes all the Kubernetes components associated with the chart and deletes the release.

_See [`helm uninstall`](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._

## Upgrading Chart

```bash
helm upgrade [RELEASE_NAME] yorkie-team/yorkie-mongodb -n mongodb
```

With Helm v3, CRDs created by this chart are not updated by default and should be manually updated.
Consult also the [Helm Documentation on CRDs](https://helm.sh/docs/chart_best_practices/custom_resource_definitions).

_See [`helm upgrade`](https://helm.sh/docs/helm/helm_upgrade/) for command documentation._

## Configuration

See [Customizing the Chart Before Installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with detailed comments:

```console
helm show values yorkie-team/yorkie-mongodb
```

You may also `helm show values` on this chart's [dependencies](#dependencies) for additional options.
9 changes: 9 additions & 0 deletions build/charts/yorkie-mongodb/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- Install Complete ---
{{ .Release.Name }} successfully installed!

For next steps, follow:
$ curl https://github.com/yorkie-team/yorkie/tree/main/charts/yorkie-mongodb

To learn more about the release, try:
$ helm status {{ .Release.Name }}
$ helm get all {{ .Release.Name }}
31 changes: 31 additions & 0 deletions build/charts/yorkie-mongodb/templates/sharded/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{- define "configReplName" -}}
{{- $name := index . 0 -}}
{{- printf "%s-configsvr" $name -}}
{{- end -}}

{{- define "configReplAddr" -}}
{{- $name := index . 0 -}}
{{- $replIndex := index . 1 -}}
{{- $domainSuffix := index . 2 -}}
{{- printf "%s-configsvr-%d.%s-headless.%s" $name $replIndex $name $domainSuffix -}}
{{- end -}}

{{- define "shardReplName" -}}
{{- $name := index . 0 -}}
{{- $index := index . 1 -}}
{{- printf "%s-shard-%d" $name $index -}}
{{- end -}}

{{- define "shardReplAddr" -}}
{{- $name := index . 0 -}}
{{- $shardIndex := index . 1 -}}
{{- $replIndex := index . 2 -}}
{{- $domainSuffix := index . 3 -}}
{{- printf "%s-shard%d-data-%d.%s-headless.%s" $name $shardIndex $replIndex $name $domainSuffix -}}
{{- end -}}

{{- define "mongosAddr" -}}
{{- $name := index . 0 -}}
{{- $domainSuffix := index . 1 -}}
{{- printf "%s-mongos-0.%s.%s" $name $name $domainSuffix -}}
{{- end -}}
69 changes: 69 additions & 0 deletions build/charts/yorkie-mongodb/templates/sharded/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{- if and .Values.sharded.enabled .Values.sharded.setup.enabled }}
{{- $domainSuffix := printf "%s.svc.%s:%d" $.Values.namespace $.Values.clusterDomain ($.Values.port | int ) }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.name }}-setup-script
namespace: {{ .Values.namespace }}
labels:
app.kubernetes.io/component: mongodb
app.kubernetes.io/part-of: yorkie
data:
setup.sh: |
#!/bin/bash

function waitUntilReady {
while true; do
mongosh $1 --quiet --eval "db.runCommand('ping').ok"
if [ $? -eq 0 ]; then
break
fi
sleep 5
done
}

{{ $configsvrAddr := include "configReplAddr" (list $.Values.name 0 $domainSuffix) }}
echo "Wait until config server is ready..."
configsvrAddr="{{ $configsvrAddr }}"
echo "Config server address: ${configsvrAddr}"
waitUntilReady $configsvrAddr
echo "Configure config server"
mongosh $configsvrAddr --eval 'rs.initiate({"_id":"{{ include "configReplName" (list $.Values.name) }}", "members":[{"_id":0,"host":"{{ $configsvrAddr }}","priority":5}]})'

{{ range $i, $e := until ($.Values.sharded.shards | int) }}
{{ $shardsvrAddr := include "shardReplAddr" (list $.Values.name $i 0 $domainSuffix) }}
echo "{{ printf "Wait until shard%d is ready..." $i }}"
shardsvrAddr="{{ $shardsvrAddr }}"
echo "{{ printf "Shard%d address: %s" $i $shardsvrAddr }}"
waitUntilReady $shardsvrAddr
echo "{{ printf "Configure shard%d" $i }}"
mongosh $shardsvrAddr --eval 'rs.initiate({"_id":"{{ include "shardReplName" (list $.Values.name $i) }}", "members":[{"_id":0,"host":"{{ $shardsvrAddr }}","priority":5}]})'
{{ end }}

{{ $mongosAddr := include "mongosAddr" (list $.Values.name $domainSuffix) }}
echo "Wait until mongos is ready..."
mongosAddr="{{ $mongosAddr }}"
echo "Mongos address: ${mongosAddr}"
waitUntilReady $mongosAddr
echo "Configure mongos"
mongosh $mongosAddr --eval <<EOF
{{- range $i, $e := until ($.Values.sharded.shards | int) }}
{{- range $j, $e := until ($.Values.sharded.replicaCount.shardsvr | int) }}
sh.addShard("{{ printf "%s/%s" (include "shardReplName" (list $.Values.name $i)) (include "shardReplAddr" (list $.Values.name $i $j $domainSuffix)) }}");
{{- end }}
{{- end }}
sh.enableSharding("{{ .Values.sharded.setup.database }}");
{{- range .Values.sharded.setup.rules }}
sh.shardCollection(
"{{ printf "%s.%s" $.Values.sharded.setup.database .collectionName }}",
{
{{- range .shardKeys }}
{{ printf "%s: %s," .name .method }}
{{- end }}
},
{{ .unique }}
);
{{- end }}
EOF

{{ end -}}
29 changes: 29 additions & 0 deletions build/charts/yorkie-mongodb/templates/sharded/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if and .Values.sharded.enabled .Values.sharded.setup.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Values.name }}-setup-job
namespace: {{ .Values.namespace }}
labels:
app.kubernetes.io/component: mongodb
app.kubernetes.io/part-of: yorkie
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation
spec:
template:
spec:
restartPolicy: {{ .Values.sharded.setup.restartPolicy }}
containers:
- name: setup
image: {{ printf "%s/%s:%s" $.Values.image.registry $.Values.image.repository $.Values.image.tag }}
command: [ "/bin/bash", "/etc/config/setup.sh" ]
volumeMounts:
- name: setup-script
mountPath: /etc/config
volumes:
- name: setup-script
configMap:
name: {{ .Values.name }}-setup-script
backoffLimit: {{ .Values.sharded.setup.backoffLimit }}
{{ end }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ if .Values.enabled -}}
{{ if not .Values.sharded.enabled -}}
apiVersion: v1
kind: Service
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ if .Values.enabled -}}
{{ if not .Values.sharded.enabled -}}
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand All @@ -25,7 +25,7 @@ spec:
terminationGracePeriodSeconds: 60
containers:
- name: mongodb
image: mongo:4.4.1
image: {{ printf "%s/%s:%s" $.Values.image.registry $.Values.image.repository $.Values.image.tag }}
ports:
- containerPort: {{ .Values.port }}
volumeMounts:
Expand All @@ -39,8 +39,8 @@ spec:
name: {{ .Values.name }}-storage
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: {{ .Values.storageClassName }}
storageClassName: {{ .Values.persistence.storageClass }}
resources:
requests:
storage: {{ .Values.storageSize }}
storage: {{ .Values.persistence.dataSize }}
{{ end }}
Loading
Loading