-
-
Notifications
You must be signed in to change notification settings - Fork 170
Add Helm chart for MongoDB sharded cluster #769
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
027b044
Add helm chart for MongoDB sharded cluster
sejongk 5e79a55
Support standalone deployment
sejongk 57026bc
Restore yorkie-cluster value
sejongk 038c815
Update build/charts/yorkie-mongodb/templates/sharded/configmap.yaml
hackerwins 6522060
Reflect reviews
hackerwins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.