Skip to content

Instantly share code, notes, and snippets.

@hongmengwang
Last active Sep 2, 2022
Embed
What would you like to do?
Install Mysql by operator in Kubernetes
#install kind and create local K8S cluster
#kind create cluster --name local
helm repo add mysql-operator https://mysql.github.io/mysql-operator/
helm repo update
MYSQL_OPERATOR_NS=mysql-operator
helm install mysql-operator mysql-operator/mysql-operator --namespace ${MYSQL_OPERATOR_NS} --create-namespace
MYSQL_NAME=mysql
MYSQL_NS=mysql
MYSQL_USER=root
MYSQL_PWD=root
MYSQL_SERVER_INSTANCE=1
MYSQL_ROUTER_INSTANCE=1
helm install ${MYSQL_NAME} mysql-operator/mysql-innodbcluster \
--namespace ${MYSQL_NS} \
--create-namespace \
--version 2.0.5 \
--set credentials.root.user=${MYSQL_USER} \
--set credentials.root.password=${MYSQL_PWD} \
--set credentials.root.host='%' \
--set serverInstances=${MYSQL_SERVER_INSTANCE} \
--set routerInstances=${MYSQL_ROUTER_INSTANCE} \
--set tls.useSelfSigned=true
kubectl get service -n ${MYSQL_NS}
kubectl port-forward service/${MYSQL_NAME} 3306:3306 -n ${MYSQL_NS}
#run mysql client
#kubectl run mysql-client --image=mysql:5.7 -it --rm --restart=Never \
#-- mysql -h${MYSQL_NAME}.${MYSQL_NS}.svc.cluster.local -P3306 -u${MYSQL_USER} -p${MYSQL_PWD}
kubectl run mysql-client --image=mysql:5.7 -it --rm --restart=Never /bin/bash
mysql -hmysql.mysql.svc.cluster.local -P3306 -uroot -proot
#mysql -h127.0.0.1 -P3306 -uroot -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment