1 MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
2 {{ template "mysql.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
4 {{- if .Values.existingSecret }}
5 If you have not already created the mysql password secret:
7 kubectl create secret generic {{ .Values.existingSecret }} --namespace {{ .Release.Namespace }} --from-file=./mysql-root-password --from-file=./mysql-password
10 To get your root password run:
12 MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "mysql.fullname" . }} -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)
15 To connect to your database:
17 1. Run an Ubuntu pod that you can use as a client:
19 kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il
21 2. Install the mysql client:
23 $ apt-get update && apt-get install mysql-client -y
25 3. Connect using the mysql cli, then provide your password:
26 $ mysql -h {{ template "mysql.fullname" . }} -p
28 To connect to your database directly from outside the K8s cluster:
29 {{- if contains "NodePort" .Values.service.type }}
30 MYSQL_HOST=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath='{.items[0].status.addresses[0].address}')
31 MYSQL_PORT=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "mysql.fullname" . }} -o jsonpath='{.spec.ports[0].nodePort}')
33 {{- else if contains "ClusterIP" .Values.service.type }}
35 MYSQL_PORT={{ .Values.service.port }}
37 # Execute the following command to route the connection:
38 kubectl port-forward svc/{{ template "mysql.fullname" . }} {{ .Values.service.port }}
42 mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}