<p>I am using Rancher to manage Kubernetes which orchestrates my Docker containers.</p>

<p>Each of our microservices (running in a container) that requires persistence has a corresponding MySQL container. E.g. MyApp is running in a container called MyApp and persists to a MySQL container called MySQL-MyApp.</p>

<p>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.</p>

<p>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.</p>

<p>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?</p>

dleerob
<p>If the users have access to <code>kubectl</code> command-line for the cluster, they can set-up a temporary <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="noreferrer">port-forward</a> between a local development machine and the pod that contains your MySQL container.</p>

<p>For example, where <code>mypod-765d459796-258hz</code> is a pod and you want to connect to port 3306 of that pod:</p>

<p><code>kubectl port-forward mypod-765d459796-258hz 12345:3306</code></p>

<p>Then you could connect MySQL Workbench to <code>localhost:12345</code> and it would forward to your MySQL container in Kubernetes.</p>
