Skip to content

Instantly share code, notes, and snippets.

@aisensiy
Created July 30, 2020 08:11
Show Gist options
  • Save aisensiy/260cc1eaf3c0c60d64cdce0faf0e9868 to your computer and use it in GitHub Desktop.
Save aisensiy/260cc1eaf3c0c60d64cdce0faf0e9868 to your computer and use it in GitHub Desktop.
访问集群内的 mysql
#!/bin/bash
# kubectx -> dev env
kubectx
# kubens -> infra
kubens
# list service use openbayes-mysql-master
kubectl get svc
# NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
# clickhouse ClusterIP 10.97.15.238 <none> 8123/TCP 34d
# grafana ClusterIP 10.97.15.166 <none> 80/TCP 16h
# mysql ClusterIP None <none> 3306/TCP,9125/TCP 7d21h
# mysql-mysql-operator ClusterIP 10.97.4.144 <none> 80/TCP 7d21h
# mysql-mysql-operator-0-svc ClusterIP 10.97.11.186 <none> 80/TCP,10008/TCP 7d21h
# openbayes-mysql ClusterIP 10.97.4.26 <none> 3306/TCP 7d
# openbayes-mysql-master ClusterIP 10.97.1.157 <none> 3306/TCP,8080/TCP 7d
# openbayes-mysql-replicas ClusterIP 10.97.13.10 <none> 3306/TCP,8080/TCP 7d
# openbayes-prometheus-alertmanager ClusterIP 10.97.9.89 <none> 80/TCP 3d18h
# openbayes-prometheus-node-exporter ClusterIP None <none> 9100/TCP 3d18h
# openbayes-prometheus-pushgateway ClusterIP 10.97.15.103 <none> 9091/TCP 3d18h
# openbayes-prometheus-server ClusterIP 10.97.13.83 <none> 80/TCP 3d18h
# port forward
kubectl port-forward svc/openbayes-mysql-master 3306
# Forwarding from 127.0.0.1:3306 -> 3306
# Forwarding from [::1]:3306 -> 3306
# login
mysql -hlocalhost -u<username> -p<password>
@aisensiy
Copy link
Author

如果本地 3306 被占用,还可以 kubectl port-forward svc/openbayes-mysql-master 3307:3306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment