Deploy MySQL Server in Kubernetes using Helm

To install MySQL server in Kubernetes, run

helm install stable/mysql

Once install is completed, you will get something like

NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
incendiary-monkey-mysql.default.svc.cluster.local

To get your root password run:

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default incendiary-monkey-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)

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 incendiary-monkey-mysql -p

To connect to your database directly from outside the K8s cluster:
    MYSQL_HOST=127.0.0.1
    MYSQL_PORT=3306

    # Execute the following command to route the connection:
    kubectl port-forward svc/incendiary-monkey-mysql 3306

    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}

To connect to this MySQL, you need to create a temporary Ubuntu server in Kubernetes as MySQL is only available inside the cluster.

Advertisement

To create a server, run

kubectl run -i --tty ubuntu --image=ubuntu:18.04 --restart=Never -- bash -il

Install MySQL client inside this server with

apt update
apt install mariadb-client -y

To connect to MySQL, use the command provided after install, in my case

mysql -h incendiary-monkey-mysql -u root -p

You can get password by running

kubectl get secret --namespace default incendiary-monkey-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo

You can list packages installed using helm with

boby@sok-01:~$ helm list
NAME             	REVISION	UPDATED                 	STATUS  	CHART       	APP VERSION	NAMESPACE
incendiary-monkey	1       	Tue Feb 26 22:24:13 2019	DEPLOYED	mysql-0.15.0	5.7.14     	default
boby@sok-01:~$

To delete, run

boby@sok-01:~$ helm delete incendiary-monkey
release "incendiary-monkey" deleted
boby@sok-01:~$

In Google Kubernetes Engine, Nodes are Google Complete Engine (Virtual Machiens). Pods run inside Nodes. A Kubernetes cluster can contain multiple node pools. A node pool contain multiple nodes of same instance type.

To create a Node Pool in Google Kubernetes Engine, run

gcloud container node-pools create POOL_NAME \
  --cluster=CLUSER_NAME \
  --machine-type=e2-standard-2 \
  --num-nodes=1 \
  --zone=ZONE_NAME

To delete a node pool, run

gcloud container node-pools delete POOL_NAME --cluster CLUSER_NAME --zone ZONE_NAME

To resize a node pool, run

gcloud container clusters resize CLUSER_NAME --node-pool POOL_NAME \
    --num-nodes 3 --zone ZONE_NAME
Add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement