-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Helm chart for MongoDB sharded cluster (#769)
This PR adds a Helm chart for MongoDB, supporting both standalone mode and sharded cluster mode. Shard rules, including shard keys, shard methods, and unique constraints, are defined and managed in the values.yaml. This chart depends on Bitnami's mongodb-sharded chart (https://github.com/bitnami/charts/tree/main/bitnami/mongodb-sharded). There are a few known issues with it: A problem with livenessProbe and readinessProbe - Issues: bitnami/charts#21957 - Solution: use custom livenessProbe and readinessProbe instead Lack of ARM64 support in the Bitnami mongodb-sharded container - Issues: - bitnami/charts#7305 (comment) - bitnami/containers#40947 - Solution: use the official Mongo 6.0 image instead and set up the cluster via a Job. --------- Co-authored-by: Youngteac Hong <susukang98@gmail.com>
- Loading branch information
1 parent
b399a68
commit 699fd63
Showing
15 changed files
with
448 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
dependencies: | ||
- name: mongodb-sharded | ||
version: "7.2.2" | ||
repository: "https://charts.bitnami.com/bitnami" | ||
condition: sharded.enabled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
build/charts/yorkie-mongodb/templates/sharded/_helpers.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
69
build/charts/yorkie-mongodb/templates/sharded/configmap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
2 changes: 1 addition & 1 deletion
2
...ter/charts/mongodb/templates/service.yaml → ...mongodb/templates/standalone/service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.