| gio | 07eb108 | 2024-10-25 14:35:56 +0400 | [diff] [blame] | 1 | CHART NAME: {{ .Chart.Name }} |
| 2 | CHART VERSION: {{ .Chart.Version }} |
| 3 | APP VERSION: {{ .Chart.AppVersion }} |
| 4 | |
| 5 | {{- if .Values.diagnosticMode.enabled }} |
| 6 | The chart has been deployed in diagnostic mode. All probes have been disabled and the command has been overwritten with: |
| 7 | |
| 8 | command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 4 }} |
| 9 | args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 4 }} |
| 10 | |
| 11 | Get the list of pods by executing: |
| 12 | |
| 13 | kubectl get pods --namespace {{ .Release.Namespace }} -l app.kubernetes.io/instance={{ .Release.Name }} |
| 14 | |
| 15 | Access the pod you want to debug by executing |
| 16 | |
| 17 | kubectl exec --namespace {{ .Release.Namespace }} -ti <NAME OF THE POD> -- bash |
| 18 | |
| 19 | In order to replicate the container startup scripts execute this command: |
| 20 | |
| 21 | /opt/bitnami/scripts/mongodb/entrypoint.sh /opt/bitnami/scripts/mongodb/run.sh |
| 22 | |
| 23 | {{- else }} |
| 24 | |
| 25 | {{- $replicaCount := int .Values.replicaCount }} |
| 26 | {{- $portNumber := int .Values.service.ports.mongodb }} |
| 27 | {{- $fullname := include "mongodb.fullname" . }} |
| 28 | {{- $releaseNamespace := include "mongodb.namespace" . }} |
| 29 | {{- $clusterDomain := .Values.clusterDomain }} |
| 30 | {{- $loadBalancerIPListLength := len .Values.externalAccess.service.loadBalancerIPs }} |
| 31 | {{- $mongoList := list }} |
| 32 | {{- range $e, $i := until $replicaCount }} |
| 33 | {{- $mongoList = append $mongoList (printf "%s-%d.%s-headless.%s.svc.%s:%d" $fullname $i $fullname $releaseNamespace $clusterDomain $portNumber) }} |
| 34 | {{- end }} |
| 35 | |
| 36 | {{- if and (or (and (eq .Values.architecture "standalone") (or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort"))) (and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled)) (not .Values.auth.enabled) }} |
| 37 | ------------------------------------------------------------------------------- |
| 38 | WARNING |
| 39 | |
| 40 | By not enabling "mongodb.auth.enabled" you have most likely exposed the |
| 41 | MongoDB® service externally without any authentication mechanism. |
| 42 | |
| 43 | For security reasons, we strongly suggest that you enable authentication |
| 44 | setting the "mongodb.auth.enabled" parameter to "true". |
| 45 | |
| 46 | ------------------------------------------------------------------------------- |
| 47 | {{- end }} |
| 48 | |
| 49 | ** Please be patient while the chart is being deployed ** |
| 50 | |
| 51 | MongoDB® can be accessed on the following DNS name(s) and ports from within your cluster: |
| 52 | |
| 53 | {{- if eq .Values.architecture "replicaset" }} |
| 54 | {{ join "\n" $mongoList | nindent 4 }} |
| 55 | {{- else }} |
| 56 | |
| 57 | {{ $fullname }}.{{ $releaseNamespace }}.svc.{{ .Values.clusterDomain }} |
| 58 | |
| 59 | {{- end }} |
| 60 | |
| 61 | {{- if .Values.auth.enabled }} |
| 62 | |
| 63 | To get the root password run: |
| 64 | |
| 65 | export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace {{ template "mongodb.namespace" . }} {{ template "mongodb.secretName" . }} -o jsonpath="{.data.mongodb-root-password}" | base64 -d) |
| 66 | |
| 67 | {{- end }} |
| 68 | {{- $customUsers := include "mongodb.customUsers" . -}} |
| 69 | {{- $customDatabases := include "mongodb.customDatabases" . -}} |
| 70 | {{- if and (not (empty $customUsers)) (not (empty $customDatabases)) }} |
| 71 | {{- $customUsersList := splitList "," $customUsers }} |
| 72 | {{- range $index, $user := $customUsersList }} |
| 73 | |
| 74 | To get the password for "{{ $user }}" run: |
| 75 | |
| 76 | export MONGODB_PASSWORD=$(kubectl get secret --namespace {{ include "mongodb.namespace" $ }} {{ include "mongodb.secretName" $ }} -o jsonpath="{.data.mongodb-passwords}" | base64 -d | awk -F',' '{print ${{ add 1 $index }}}') |
| 77 | |
| 78 | {{- end }} |
| 79 | {{- end }} |
| 80 | |
| 81 | To connect to your database, create a MongoDB® client container: |
| 82 | |
| 83 | kubectl run --namespace {{ template "mongodb.namespace" . }} {{ template "mongodb.fullname" . }}-client --rm --tty -i --restart='Never' --env="MONGODB_ROOT_PASSWORD=$MONGODB_ROOT_PASSWORD" --image {{ template "mongodb.image" . }} --command -- bash |
| 84 | |
| 85 | Then, run the following command: |
| 86 | |
| 87 | {{- if eq .Values.architecture "replicaset" }} |
| 88 | mongosh admin --host "{{ join "," $mongoList }}" {{- if .Values.auth.enabled }} --authenticationDatabase admin -u $MONGODB_ROOT_USER -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 89 | {{- else }} |
| 90 | mongosh admin --host "{{ template "mongodb.service.nameOverride" . }}" {{- if .Values.auth.enabled }} --authenticationDatabase admin -u $MONGODB_ROOT_USER -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 91 | {{- end }} |
| 92 | |
| 93 | {{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled }} |
| 94 | |
| 95 | To connect to your database nodes from outside, you need to add both primary and secondary nodes hostnames/IPs to your Mongo client. To obtain them, follow the instructions below: |
| 96 | |
| 97 | {{- if eq "NodePort" .Values.externalAccess.service.type }} |
| 98 | {{- if .Values.externalAccess.service.domain }} |
| 99 | |
| 100 | MongoDB® nodes domain: Use your provided hostname to reach MongoDB® nodes, {{ .Values.externalAccess.service.domain }} |
| 101 | |
| 102 | {{- else }} |
| 103 | |
| 104 | MongoDB® nodes domain: you can reach MongoDB® nodes on any of the K8s nodes external IPs. |
| 105 | |
| 106 | kubectl get nodes -o wide |
| 107 | |
| 108 | {{- end }} |
| 109 | |
| 110 | MongoDB® nodes port: You will have a different node port for each MongoDB® node. You can get the list of configured node ports using the command below: |
| 111 | |
| 112 | echo "$(kubectl get svc --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "mongodb.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=mongodb,pod" -o jsonpath='{.items[*].spec.ports[0].nodePort}' | tr ' ' '\n')" |
| 113 | |
| 114 | {{- else if contains "LoadBalancer" .Values.externalAccess.service.type }} |
| 115 | |
| 116 | NOTE: It may take a few minutes for the LoadBalancer IPs to be available. |
| 117 | Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "mongodb.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=mongodb,pod" -w' |
| 118 | |
| 119 | MongoDB® nodes domain: You will have a different external IP for each MongoDB® node. You can get the list of external IPs using the command below: |
| 120 | |
| 121 | echo "$(kubectl get svc --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "mongodb.name" . }},app.kubernetes.io/instance={{ .Release.Name }},app.kubernetes.io/component=mongodb,pod" -o jsonpath='{.items[*].status.loadBalancer.ingress[0].ip}' | tr ' ' '\n')" |
| 122 | |
| 123 | MongoDB® nodes port: {{ .Values.externalAccess.service.ports.mongodb }} |
| 124 | |
| 125 | {{- end }} |
| 126 | |
| 127 | {{- else if eq .Values.architecture "standalone" }} |
| 128 | |
| 129 | To connect to your database from outside the cluster execute the following commands: |
| 130 | |
| 131 | {{- if contains "NodePort" .Values.service.type }} |
| 132 | |
| 133 | export NODE_IP=$(kubectl get nodes --namespace {{ template "mongodb.namespace" . }} -o jsonpath="{.items[0].status.addresses[0].address}") |
| 134 | export NODE_PORT=$(kubectl get --namespace {{ template "mongodb.namespace" . }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "mongodb.service.nameOverride" . }}) |
| 135 | mongo --host $NODE_IP --port $NODE_PORT {{- if .Values.auth.enabled }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 136 | |
| 137 | {{- else if contains "LoadBalancer" .Values.service.type }} |
| 138 | |
| 139 | NOTE: It may take a few minutes for the LoadBalancer IP to be available. |
| 140 | Watch the status with: 'kubectl get svc --namespace {{ template "mongodb.namespace" . }} -w {{ template "mongodb.service.nameOverride" . }}' |
| 141 | |
| 142 | export SERVICE_IP=$(kubectl get svc --namespace {{ template "mongodb.namespace" . }} {{ template "mongodb.service.nameOverride" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}") |
| 143 | mongosh --host $SERVICE_IP --port {{ $portNumber }} {{- if .Values.auth.enabled }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 144 | |
| 145 | {{- else if contains "ClusterIP" .Values.service.type }} |
| 146 | |
| 147 | kubectl port-forward --namespace {{ template "mongodb.namespace" . }} svc/{{ template "mongodb.service.nameOverride" . }} {{ $portNumber }}:{{ $portNumber }} & |
| 148 | mongosh --host 127.0.0.1 {{- if .Values.auth.enabled }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 149 | |
| 150 | {{- end }} |
| 151 | {{- end }} |
| 152 | |
| 153 | {{- if .Values.metrics.enabled }} |
| 154 | |
| 155 | To access the MongoDB® Prometheus metrics, get the MongoDB® Prometheus URL by running: |
| 156 | |
| 157 | kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ printf "%s-metrics" (include "mongodb.fullname" .) }} {{ .Values.metrics.service.ports.metrics }}:{{ .Values.metrics.service.ports.metrics }} & |
| 158 | echo "Prometheus Metrics URL: http://127.0.0.1:{{ .Values.metrics.service.ports.metrics }}/metrics" |
| 159 | |
| 160 | Then, open the obtained URL in a browser. |
| 161 | |
| 162 | {{- end }} |
| 163 | {{- end }} |
| 164 | {{- include "common.warnings.rollingTag" .Values.image }} |
| 165 | {{- include "common.warnings.rollingTag" .Values.metrics.image }} |
| 166 | {{- include "common.warnings.rollingTag" .Values.externalAccess.autoDiscovery.image }} |
| 167 | {{- include "common.warnings.rollingTag" .Values.volumePermissions.image }} |
| 168 | {{- include "common.warnings.rollingTag" .Values.tls.image }} |
| 169 | {{- include "mongodb.validateValues" . }} |
| 170 | {{- include "common.warnings.resources" (dict "sections" (list "arbiter" "externalAccess.autoDiscovery" "hidden" "metrics" "" "tls" "volumePermissions") "context" $) }} |
| 171 | {{- include "common.warnings.modifiedImages" (dict "images" (list .Values.image .Values.tls.image .Values.externalAccess.autoDiscovery.image .Values.externalAccess.dnsCheck.image .Values.volumePermissions.image .Values.metrics.image) "context" $) }} |