# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-service NodePort 10.1.214.59 <none> 3306:30749/TCP 8m55s
通过IP地址、端口、用户名、密码连接即可。
如果pod状态卡在ContainerCreating,并且日志显示 Warning FailedMount 95s (x2 over 3m52s) kubelet Unable to attach or mount volumes: unmounted volumes=[mysql-persistent-storage], unattached volumes=[mysql-persistent-storage kube-api-access-h4tln]: timed out waiting for the condition,则需要在对应节点上手动创建目录。
# helm search repo mysql NAME CHART VERSION APP VERSION DESCRIPTION bitnami/mysql 9.2.0 8.0.29 MySQL is a fast, reliable, scalable, and easy t... bitnami/phpmyadmin 10.1.12 5.2.0 phpMyAdmin is a free software tool written in P... bitnami/mariadb 11.0.14 10.6.8 MariaDB is an open source, community-developed ... bitnami/mariadb-galera 7.3.6 10.6.8 MariaDB Galera is a multi-primary database clus...
echo Username: root MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace mysql mysql -o jsonpath="{.data.mysql-root-password}" | base64 -d)
端口
1 2 3 4 5 6
# kubectl get svc -n mysql NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-primary NodePort 10.1.45.111 <none> 3306:31398/TCP 35s mysql-primary-headless ClusterIP None <none> 3306/TCP 35s mysql-secondary NodePort 10.1.171.237 <none> 3306:30464/TCP 35s mysql-secondary-headless ClusterIP None <none> 3306/TCP 35s
踩坑
集群下安装的mysql版本比较高,是8.x版本,需要手动分配权限。
1 2 3 4 5
# kubectl exec -it mysql-primary-0 -n mysql bash mysql> SELECT host FROM mysql.user WHERE User = 'root'; mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'; mysql> FLUSH PRIVILEGES;