Percona Operator for MySQL, based on Percona XtraDB Cluster (PXC), provides configuration to expose the ProxySQL, HAProxy, and the PXC instances themselves so that you can use Percona Toolkit to connect to MySQL from these endpoints externally. However, you can also create Kubernetes pods to run Percona Toolkit operations there instead if you do not want to expose additional endpoints.

Here’s how to do it.

First, get the PXC pod’s domain name. Here’s a fast way of obtaining it—we can obtain a shell to one of the PXC pods, connect to MySQL, and extract the details from it:

Now that we have the cluster host details, we can create the pod that will run Percona Toolkit. The MySQL administrator credentials are stored in a secret in the PXC operator. We can reuse the credentials by using the same secret in the pod that we will be creating as well. In particular, the pod will connect as the MySQL root user. Percona Toolkit also has a published image in Docker, so we can use that image in the pod’s container.

Notice that the restart policy is set to Never so that if the pod runs into a problem, it won’t restart the pod immediately.

Now, let’s create the pod:

After some time, the pod will complete its operations, and then it will be terminated:

Let’s take a look at the pod’s logs.

You can see from the output above that it was able to run pt-mysql-summary successfully.

Let me provide an additional example. Let’s say you want to use pt-online-schema-change to add a column and add an index to it. Then, my corresponding pod definition would look like this:

Then, let’s create the pod:

Then, we can check from the logs and validate if the DDL operation was successful:

Finally, we can clean up the pod list by deleting the pods:

In summary, we can use Kubernetes pods to run Percona Toolkit operations so that you do not need to expose an endpoint from the outside to run them.


Percona Toolkit is a collection of advanced open source command-line tools developed and used by the Percona technical staff. These tools are engineered to perform a variety of server and system tasks that are too difficult or complex to perform manually.

 

Try Percona Toolkit today!

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments