This blog post continues the series of comparisons of solutions to run databases on Kubernetes. Previous blog posts:
The initial release of MySQL was in 1995 and Kubernetes was released 19 years later in 2014. According to DB-engines, MySQL today is the most popular open source relational database, whereas Kubernetes is the de-facto standard for running containerized workloads. The popularity of these two technologies among engineers drove companies to create solutions to run them together. In this blog post, we will review various Kubernetes Operators for MySQL, see how different they are, and what capabilities they provide for developers and operations teams.
The summary and comparison table can be found in our documentation.
Before reviewing the operators, I need to mention numerous interesting solutions to run MySQL in k8s.
KubeDB is a swiss-army knife operator, which can deploy and manage multiple databases, including MySQL. The thing is that it is working in an open core model, where the most interesting features are not available in the free version, so I cannot easily try them out. Rest assured it is a viable solution, but in this blog post, I want to focus on open source offerings.
The desire to run MySQL on Kubernetes was there before the Operator SDK appeared. To address this, the community was very creative and developed numerous ways how to do it, ranging from regular manual deployments to more sophisticated helm charts (ex Bitnami Helm Chart).
They do the job – you can deploy a MySQL server. With some digging and tuning it is even possible to have a cluster. But what these solutions have in common is that they lack the ability to perform different day-2 operations: backups, scaling, upgrades, etc. For databases, it might be crucial, because data consistency and safety are at stake. Applying methods that worked on legacy environments, might not be safe on Kubernetes.
This is where Operators come into play.
Bitpoke is a company that provides tools for WordPress self-hosting on Kubernetes, including MySQL and WordPress operators. Their team developed one of the first MySQL operators and shared it with the community. Developed initially within Presslabs, since 2021 the team and operator have moved to Bitpoke. The operator is used in production by numerous companies.
It is Apache 2.0 licensed. Interestingly enough, it uses Percona Server for MySQL under the hood “because of backup improvements (eg. backup locks), monitoring improvements, and some serviceability improvements (eg. utility user)“.
I followed the documentation:
|
1 |
helm repo add bitpoke https://helm-charts.bitpoke.io<br>helm install mysql-operator bitpoke/mysql-operator |
The operator is up and running. Deploying the cluster:
|
1 |
kubectl apply -f https://raw.githubusercontent.com/bitpoke/mysql-operator/master/examples/example-cluster-secret.yaml<br>kubectl apply -f https://raw.githubusercontent.com/bitpoke/mysql-operator/master/examples/example-cluster.yaml |
This deploys MySQL 5.7 cluster with asynchronous replication – one main and one replica node.
Bitpoke operator allows you to back up, restore, scale, and upgrade MySQL on Kubernetes. So regular day-2 operations are available.
Let’s start with the pros:
As for cons, it seems that the operator is not actively developed with 15 commits for the last year.
This is not the first time Oracle created the Operator for MySQL, but the difference now is that this Operator made it to the General Availability stage. Operator is distributed under the unusual “Universal Permissive License (UPL)”, but it is really permissive and close to the MIT license.
Standard deployment for the operator with helm, no surprises:
|
1 |
helm repo add mysql-operator https://mysql.github.io/mysql-operator/<br>helm repo update<br>helm install mysql-operator mysql-operator/mysql-operator --namespace mysql-operator --create-namespace |
Now the cluster:
|
1 |
export NAMESPACE=default<br>helm install my-mysql-innodbcluster mysql-operator/mysql-innodbcluster -n $NAMESPACE <br> --version 2.0.7 <br> --set credentials.root.password=">-0URS4F3P4SS" <br> --set tls.useSelfSigned=true |
This deploys a MySQL cluster with three nodes with Group Replication and a single MySQL router Pod in front of it for query routing.
Even though the operator was promoted to GA, some basic capabilities are not there or should be implemented by the user. For example, upgrades, monitoring, and topology flexibility.
Similar to the Bitpoke operator, Moco was created by Cybozu for its internal needs and later open-sourced. It goes under Apache 2.0 license, is written in Golang, and has a good release cadence.
As usual, let’s try a quick start guide. Note that a cert-manager is required (curiosity peaked from the start!).
Install cert-manager and deploy the operator:
|
1 |
curl -fsLO https://github.com/jetstack/cert-manager/releases/latest/download/cert-manager.yaml<br>kubectl apply -f cert-manager.yaml<br><br>helm repo add moco https://cybozu-go.github.io/moco/<br>helm repo update<br>helm install --create-namespace --namespace moco-system moco moco/moco |
Create the cluster from an example folder:
|
1 |
kubectl apply -f https://raw.githubusercontent.com/cybozu-go/moco/main/examples/loadbalancer.yaml |
This deploys a cluster with three nodes and semi-sync replication exposed with a load balancer.
Moco is quite feature-rich and enables users to execute various management tasks. Refreshing solutions and ideas:
There are some concerns that I have regarding this operator:
Vitess is a database clustering system for horizontal scaling of MySQL and was initially developed in YouTube (and it was widely used there). Now it is a CNCF project and is actively developed by PlanetScale and the community. It is open source, but there are some features in Vitess itself that are only available for PlanetScale customers. Interesting fact: Vitess Operator serves as a core component of the PlanetScale DBaaS. So it is a production-grade and battle-tested operator.
Going with a quickstart:
|
1 |
git clone https://github.com/vitessio/vitess<br>cd vitess/examples/operator<br><br>kubectl apply -f operator.yaml |
Operator is ready. Let’s deploy an intro cluster:
|
1 |
kubectl apply -f 101_initial_cluster.yaml |
This deploys the following:
Sharding is one of the biggest pros of this operator. The only competitor I can think of is TiDB (which should be MySQL protocol compatible, but not MySQL). There are no other solutions for MySQL sharding in the open source space. But at the same time, it all comes with a price – complexity, which Kubernetes for sure helps to masquerade. Getting familiar with all vt-* components can be overwhelming, especially for users who never used Vitess before.
Operator provides users with all the regular management operations. The only downside is that these operations are not well documented and you have to discover them through various blog posts, reference docs, and other artifacts. For example, this blog post covers some basics for backups and restores, whereas this document covers basic Vitess operations.
At Percona we have two operators for MySQL:
In Percona Operator for MySQL – Alpha Release, we explain why we decided to create the new operator. Both operators are fully open source as the components they are based on. The one based on PXC is production-ready, whereas PS is getting there.
For Percona Kubernetes Operators we maintain helm charts for ease of onboarding. Deployment is a two-step process.
Deploy the operator:
|
1 |
helm repo add percona https://percona.github.io/percona-helm-charts/<br>helm install my-op percona/pxc-operator |
And the database:
|
1 |
helm install my-db percona/pxc-db |
For features, I will focus on PXC as it is production-ready, and we are aiming for PS Operator to reach parity in the nearest future.
Percona is committed to providing open source products to the community, but we also provide exceptional services for our customers: managed and professional services and support. We have an ecosystem of products — Percona Platform — that brings together our software and services offerings.