| # ***************************************************************************** |
| # |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| # |
| # ****************************************************************************** |
| |
| MySQL can be accessed via port 3306 on the following DNS name from within your cluster: |
| {{ template "mysql.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local |
| |
| {{- if .Values.mysqlx.port.enabled }} |
| Connection to the X protocol of MySQL can be done via 33060 on the following DNS name from within your cluster: |
| {{ template "mysql.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local |
| {{- end }} |
| |
| {{- if .Values.existingSecret }} |
| If you have not already created the mysql password secret: |
| |
| kubectl create secret generic {{ .Values.existingSecret }} --namespace {{ .Release.Namespace }} --from-file=./mysql-root-password --from-file=./mysql-password |
| {{ else }} |
| |
| To get your root password run: |
| |
| MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "mysql.fullname" . }} -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo) |
| {{- end }} |
| |
| To connect to your database: |
| |
| 1. Run an Ubuntu pod that you can use as a client: |
| |
| kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il |
| |
| 2. Install the mysql client: |
| |
| $ apt-get update && apt-get install mysql-client -y |
| |
| 3. Connect using the mysql cli, then provide your password: |
| $ mysql -h {{ template "mysql.fullname" . }} -p |
| |
| To connect to your database directly from outside the K8s cluster: |
| {{- if contains "NodePort" .Values.service.type }} |
| MYSQL_HOST=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath='{.items[0].status.addresses[0].address}') |
| MYSQL_PORT=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "mysql.fullname" . }} -o jsonpath='{.spec.ports[0].nodePort}') |
| |
| {{- else if contains "ClusterIP" .Values.service.type }} |
| MYSQL_HOST=127.0.0.1 |
| MYSQL_PORT={{ .Values.service.port }} |
| |
| # Execute the following command to route the connection: |
| kubectl port-forward svc/{{ template "mysql.fullname" . }} {{ .Values.service.port }} |
| |
| {{- end }} |
| |
| mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD} |
| |