简体   繁体   English

我如何访问在Docker容器(由Rancher管理)中运行的MySQL,而不在主机上发布端口?

[英]How do I access MySQL running in a docker container (managed by Rancher) without publishing the port on the host?

I am using Rancher to manage Kubernetes which orchestrates my Docker containers. 我正在使用Rancher来管理Kubernetes,该Kubernetes编排了我的Docker容器。

Each of our microservices (running in a container) that requires persistence has a corresponding MySQL container. 我们每个需要持久性的微服务(在容器中运行)都有一个对应的MySQL容器。 Eg MyApp is running in a container called MyApp and persists to a MySQL container called MySQL-MyApp. 例如,MyApp在名为MyApp的容器中运行,并持久存在于名为MySQL-MyApp的MySQL容器中。

We have many of these. 我们有很多。 We don't want to define which nodes the MySQL containers runs on, and therefore can't publish/expose the port on the host in case it clashes with any other ports on that host. 我们不想定义MySQL容器在哪个节点上运行,因此,如果该端口与该主机上的任何其他端口冲突,则无法在该主机上发布/公开该端口。

However, if something goes wrong with some data for one of our microservices, we need to be able to access the MySQL instance in the relevant container using MySQL Workbench to view/edit the data in the database from an external machine on our physical network. 但是,如果其中一项微服务的某些数据出了问题,我们需要能够使用MySQL Workbench访问相关容器中的MySQL实例,以便从物理网络上的外部计算机查看/编辑数据库中的数据。

Any ideas how we would go about doing this? 有什么想法我们将如何去做吗? Are we able to somehow temporarily expose/publish a port on the fly for a MySQL container that is running so that we can connect to it via MySQL Workbench, or are there other ways to get this done? 我们是否能够以某种方式临时公开/发布正在运行的MySQL容器的端口,以便我们可以通过MySQL Workbench连接到它,或者是否有其他方法可以完成此操作?

If the users have access to kubectl command-line for the cluster, they can set-up a temporary port-forward between a local development machine and the pod that contains your MySQL container. 如果用户可以访问集群的kubectl命令行,则可以在本地开发计算机和包含MySQL容器的pod之间设置临时端口转发

For example, where mypod-765d459796-258hz is a pod and you want to connect to port 3306 of that pod: 例如,如果mypod-765d459796-258hz是一个Pod,而您想连接到该Pod的端口3306:

kubectl port-forward mypod-765d459796-258hz 12345:3306

Then you could connect MySQL Workbench to localhost:12345 and it would forward to your MySQL container in Kubernetes. 然后,您可以将MySQL Workbench连接到localhost:12345 ,它将转发到Kubernetes中的MySQL容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM