|
| 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/drycc/scripts/mongodb/entrypoint.sh /opt/drycc/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 (eq .Values.architecture "replicaset") .Values.externalAccess.enabled (not .Values.externalAccess.autoDiscovery.enabled) (not (eq $replicaCount $loadBalancerIPListLength )) (eq .Values.externalAccess.service.type "LoadBalancer") }} |
| 37 | + |
| 38 | +#################################################################################### |
| 39 | +### ERROR: You enabled external access to MongoDB® nodes without specifying ### |
| 40 | +### the array of load balancer IPs for MongoDB® nodes. ### |
| 41 | +#################################################################################### |
| 42 | + |
| 43 | +This deployment will be incomplete until you configure the array of load balancer |
| 44 | +IPs for MongoDB® nodes. To complete your deployment follow the steps below: |
| 45 | + |
| 46 | +1. Wait for the load balancer IPs (it may take a few minutes for them to be available): |
| 47 | + |
| 48 | + 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" -w |
| 49 | + |
| 50 | +2. Obtain the load balancer IPs and upgrade your chart: |
| 51 | + |
| 52 | + {{- range $e, $i := until $replicaCount }} |
| 53 | + LOAD_BALANCER_IP_{{ add $i 1 }}="$(kubectl get svc --namespace {{ $releaseNamespace }} {{ $fullname }}-{{ $i }}-external -o jsonpath='{.status.loadBalancer.ingress[0].ip}')" |
| 54 | + {{- end }} |
| 55 | + |
| 56 | +3. Upgrade you chart: |
| 57 | + |
| 58 | + helm upgrade --namespace {{ .Release.Namespace }} {{ .Release.Name }} my-repo/{{ .Chart.Name }} \ |
| 59 | + --set mongodb.replicaCount={{ $replicaCount }} \ |
| 60 | + --set mongodb.externalAccess.enabled=true \ |
| 61 | + {{- range $i, $e := until $replicaCount }} |
| 62 | + --set mongodb.externalAccess.service.loadBalancerIPs[{{ $i }}]=$LOAD_BALANCER_IP_{{ add $i 1 }} \ |
| 63 | + {{- end }} |
| 64 | + --set mongodb.externalAccess.service.type=LoadBalancer |
| 65 | + |
| 66 | +{{- else }} |
| 67 | + |
| 68 | +{{- 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) }} |
| 69 | +------------------------------------------------------------------------------- |
| 70 | + WARNING |
| 71 | + |
| 72 | + By not enabling "mongodb.auth.enabled" you have most likely exposed the |
| 73 | + MongoDB® service externally without any authentication mechanism. |
| 74 | + |
| 75 | + For security reasons, we strongly suggest that you enable authentiation |
| 76 | + setting the "mongodb.auth.enabled" parameter to "true". |
| 77 | + |
| 78 | +------------------------------------------------------------------------------- |
| 79 | +{{- end }} |
| 80 | + |
| 81 | +** Please be patient while the chart is being deployed ** |
| 82 | + |
| 83 | +MongoDB® can be accessed on the following DNS name(s) and ports from within your cluster: |
| 84 | + |
| 85 | +{{- if eq .Values.architecture "replicaset" }} |
| 86 | +{{ join "\n" $mongoList | nindent 4 }} |
| 87 | +{{- else }} |
| 88 | + |
| 89 | + {{ $fullname }}.{{ $releaseNamespace }}.svc.{{ .Values.clusterDomain }} |
| 90 | + |
| 91 | +{{- end }} |
| 92 | + |
| 93 | +{{- if .Values.auth.enabled }} |
| 94 | + |
| 95 | +To get the root password run: |
| 96 | + |
| 97 | + export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace {{ template "mongodb.namespace" . }} {{ template "mongodb.secretName" . }} -o jsonpath="{.data.mongodb-root-password}" | base64 -d) |
| 98 | + |
| 99 | +{{- end }} |
| 100 | +{{- $customUsers := include "mongodb.customUsers" . -}} |
| 101 | +{{- $customDatabases := include "mongodb.customDatabases" . -}} |
| 102 | +{{- if and (not (empty $customUsers)) (not (empty $customDatabases)) }} |
| 103 | +{{- $customUsersList := splitList "," $customUsers }} |
| 104 | +{{- range $index, $user := $customUsersList }} |
| 105 | + |
| 106 | +To get the password for "{{ $user }}" run: |
| 107 | + |
| 108 | + 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 }}}') |
| 109 | + |
| 110 | +{{- end }} |
| 111 | +{{- end }} |
| 112 | + |
| 113 | +To connect to your database, create a MongoDB® client container: |
| 114 | + |
| 115 | + 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 |
| 116 | + |
| 117 | +Then, run the following command: |
| 118 | + |
| 119 | + {{- if eq .Values.architecture "replicaset" }} |
| 120 | + mongosh admin --host "{{ join "," $mongoList }}" {{- if .Values.auth.enabled }} --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 121 | + {{- else }} |
| 122 | + mongosh admin --host "{{ template "mongodb.fullname" . }}" {{- if .Values.auth.enabled }} --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 123 | + {{- end }} |
| 124 | + |
| 125 | +{{- if and (eq .Values.architecture "replicaset") .Values.externalAccess.enabled }} |
| 126 | + |
| 127 | +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: |
| 128 | + |
| 129 | +{{- if eq "NodePort" .Values.externalAccess.service.type }} |
| 130 | +{{- if .Values.externalAccess.service.domain }} |
| 131 | + |
| 132 | + MongoDB® nodes domain: Use your provided hostname to reach MongoDB® nodes, {{ .Values.externalAccess.service.domain }} |
| 133 | + |
| 134 | +{{- else }} |
| 135 | + |
| 136 | + MongoDB® nodes domain: you can reach MongoDB® nodes on any of the K8s nodes external IPs. |
| 137 | + |
| 138 | + kubectl get nodes -o wide |
| 139 | + |
| 140 | +{{- end }} |
| 141 | + |
| 142 | + 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: |
| 143 | + |
| 144 | + 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')" |
| 145 | + |
| 146 | +{{- else if contains "LoadBalancer" .Values.externalAccess.service.type }} |
| 147 | + |
| 148 | + NOTE: It may take a few minutes for the LoadBalancer IPs to be available. |
| 149 | + 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' |
| 150 | + |
| 151 | + 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: |
| 152 | + |
| 153 | + 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')" |
| 154 | + |
| 155 | + MongoDB® nodes port: {{ .Values.externalAccess.service.ports.mongodb }} |
| 156 | + |
| 157 | +{{- end }} |
| 158 | + |
| 159 | +{{- else if eq .Values.architecture "standalone" }} |
| 160 | + |
| 161 | +To connect to your database from outside the cluster execute the following commands: |
| 162 | + |
| 163 | +{{- if contains "NodePort" .Values.service.type }} |
| 164 | + |
| 165 | + export NODE_IP=$(kubectl get nodes --namespace {{ template "mongodb.namespace" . }} -o jsonpath="{.items[0].status.addresses[0].address}") |
| 166 | + export NODE_PORT=$(kubectl get --namespace {{ template "mongodb.namespace" . }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "mongodb.fullname" . }}) |
| 167 | + mongo --host $NODE_IP --port $NODE_PORT {{- if .Values.auth.enabled }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 168 | + |
| 169 | +{{- else if contains "LoadBalancer" .Values.service.type }} |
| 170 | + |
| 171 | + NOTE: It may take a few minutes for the LoadBalancer IP to be available. |
| 172 | + Watch the status with: 'kubectl get svc --namespace {{ template "mongodb.namespace" . }} -w {{ template "mongodb.fullname" . }}' |
| 173 | + |
| 174 | + export SERVICE_IP=$(kubectl get svc --namespace {{ template "mongodb.namespace" . }} {{ template "mongodb.fullname" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}") |
| 175 | + mongosh --host $SERVICE_IP --port {{ $portNumber }} {{- if .Values.auth.enabled }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 176 | + |
| 177 | +{{- else if contains "ClusterIP" .Values.service.type }} |
| 178 | + |
| 179 | + kubectl port-forward --namespace {{ template "mongodb.namespace" . }} svc/{{ template "mongodb.fullname" . }} {{ $portNumber }}:{{ $portNumber }} & |
| 180 | + mongosh --host 127.0.0.1 {{- if .Values.auth.enabled }} --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD{{- end }} |
| 181 | + |
| 182 | +{{- end }} |
| 183 | +{{- end }} |
| 184 | +{{- end }} |
| 185 | + |
| 186 | +{{- if .Values.metrics.enabled }} |
| 187 | + |
| 188 | +To access the MongoDB® Prometheus metrics, get the MongoDB® Prometheus URL by running: |
| 189 | + |
| 190 | + kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ include "mongodb.fullname" . }}-metrics {{ .Values.metrics.service.ports.metrics }}:{{ .Values.metrics.service.ports.metrics }} & |
| 191 | + echo "Prometheus Metrics URL: http://127.0.0.1:{{ .Values.metrics.service.ports.metrics }}/metrics" |
| 192 | + |
| 193 | +Then, open the obtained URL in a browser. |
| 194 | + |
| 195 | +{{- end }} |
| 196 | +{{- end }} |
| 197 | +{{- include "common.warnings.rollingTag" .Values.image }} |
| 198 | +{{- include "common.warnings.rollingTag" .Values.metrics.image }} |
| 199 | +{{- include "common.warnings.rollingTag" .Values.externalAccess.autoDiscovery.image }} |
| 200 | +{{- include "common.warnings.rollingTag" .Values.volumePermissions.image }} |
| 201 | +{{- include "common.warnings.rollingTag" .Values.tls.image }} |
| 202 | + |
0 commit comments