Home›Learn›MySQL on Kubernetes: the Percona operators
MySQL · High availability · Kubernetes

MySQL on Kubernetes: the Percona operators

Two operators, two ways to replicate. Which one do you run, and who fails over?

Percona ships two Kubernetes operators for MySQL. One runs XtraDB Cluster. The other runs Percona Server with Group Replication or, in tech preview, asynchronous replication managed by Orchestrator.

Why this tool exists

Why run MySQL with an operator on Kubernetes

A MySQL pod that dies is easy to restart. The hard part is everything around it: which pod is the writer now, how a new pod joins the group without losing data, how the proxy finds the writer, and how you take a backup that you can restore. An operator is a controller that knows those rules for one database and keeps them true while pods and nodes come and go.

Percona ships two operators for MySQL. They are different products with different replication, so pick before you deploy.

Percona Operator for MySQL based on Percona XtraDB Cluster (PXC)Percona Operator for MySQL based on Percona Server (PS)
ReplicationGalera-based synchronous replication in Percona XtraDB Cluster.Group Replication (GA) or asynchronous replication (tech preview in the 1.3.0 docs).
Who handles failoverThe cluster itself: the group keeps a majority and drops the failed node.Group Replication: the group protocol. Async: Orchestrator, which the operator deploys.
ProxyHAProxy or ProxySQL.HAProxy for both modes. MySQL Router for Group Replication only.
Status per PerconaPercona called it "production-ready and widely adopted" in a July 2022 post.1.0.0 with Group Replication went GA in November 2025. The 1.3.0 docs say async is tech preview and not recommended for production.
Versions used on this pageOperator 1.20.0Operator 1.3.0
What we are protecting

Write availability and the data, on a platform that reschedules pods without asking you.

What we achieve

Declarative clusters, automatic recovery of failed pods, rolling updates, scheduled backups with XtraBackup, and a proxy in front.

Why Orchestrator shows up here

In the PS operator's async mode, Orchestrator decides the new primary. Percona says its Operator for MySQL uses Orchestrator to manage asynchronous topologies, so the ProxySQL takeover matters to it. See Orchestrator.

What it is not

Not a replacement for knowing MySQL. You still read GTIDs, lag and the error log, and you still test restores.

Running on bare servers instead? See InnoDB Cluster for Group Replication with Router, or Orchestrator for classic replicas.

How it was done before

MySQL on a StatefulSet by hand

The plain approach is a StatefulSet of three MySQL pods, one writer and two replicas, with a Service in front. The first pod is the writer because it is named mysql-0. Kubernetes restarts it if it dies, and that is where its help ends.

  1. Node failure leaves mysql-0 pending while its volume is attached to the lost node. Writes are down.
  2. You decide whether to wait or to promote mysql-1. If you promote, you check GTIDs first and then point mysql-2 at it.
  3. You change which pod the Service selects.
  4. When mysql-0 returns it believes it is the writer. If nothing stopped it, you have two writers.

Every one of those is a script somebody has to write, test and keep current. The operator is those scripts, written once, with tests.

Step through it:

Explained clearly

What the two operators build

1

The problem

You want one custom resource that says "three MySQL nodes, this proxy, these backups", and a controller that creates and repairs everything underneath.

2

What it is

Install the operator once. Create a PerconaXtraDBCluster (PXC operator) or a PerconaServerMySQL (PS operator) resource. The PS operator deploys, in StatefulSets: Percona Server for MySQL, XtraBackup, Orchestrator (only with async replication), HAProxy (both modes) or MySQL Router (Group Replication only), and optional sidecars such as PMM Client. The PXC operator's default cr.yaml deploys three PXC pods and three HAProxy pods and schedules a daily backup to a PVC.

3

Follow one request

  1. The app connects to the proxy Service, for example cluster1-haproxy or ps-cluster1-router.
  2. The proxy sends writes to the current primary and, with Router, reads to the others.
  3. When a pod fails, Kubernetes reschedules it and the replication layer (Galera, Group Replication or Orchestrator) handles who is primary.
  4. The app reconnects to the same Service name.
4

What to watch

  • Node count. Percona recommends 3 to 5 PXC nodes, odd numbers, and 3 to 9 for Group Replication. Even or other counts need an unsafeFlags setting.
  • A full-cluster crash. In Group Replication the cluster goes to error with reason FullClusterCrashDetected and needs the operator to reboot it.
  • 3.0 and causes downtime.

Step through it:

Step by step

Set it up

Percona Operator for MySQL based on Percona XtraDB Cluster, 1.20.0

kubectl create namespace mysql
kubectl apply --server-side -f https://raw.githubusercontent.com/percona/percona-xtradb-cluster-operator/v1.20.0/deploy/bundle.yaml -n mysql
kubectl apply -f https://raw.githubusercontent.com/percona/percona-xtradb-cluster-operator/v1.20.0/deploy/cr.yaml -n mysql
kubectl get pxc -n mysql

The default cr.yaml deploys three PXC pods and three HAProxy pods spread across nodes, so you need at least three schedulable nodes. On one node (a lab) use deploy/cr-minimal.yaml instead. When the cluster is ready the output looks like cluster1 cluster1-haproxy.mysql ready 3 3. The default also schedules a daily backup to a PVC and keeps the last five.

Key fields to set in your own copy of cr.yaml (apiVersion: pxc.percona.com/v1, kind: PerconaXtraDBCluster): crVersion: 1.20.0, pxc.size: 3, haproxy.enabled: true and haproxy.size: 3 (or ProxySQL, one proxy at a time), and backup.storages pointing at S3-compatible storage.

Percona Operator for MySQL based on Percona Server, 1.3.0

git clone -b v1.3.0 https://github.com/percona/percona-server-mysql-operator
cd percona-server-mysql-operator
kubectl apply --server-side -f deploy/crd.yaml
kubectl create namespace mysql
kubectl config set-context $(kubectl config current-context) --namespace=mysql
kubectl apply -f deploy/rbac.yaml
kubectl apply -f deploy/operator.yaml
# edit deploy/secrets.yaml with your users and passwords, then:
kubectl create -f deploy/secrets.yaml
kubectl apply -f deploy/cr.yaml

You should see ps-cluster1-mysql-0, -1, -2 and ps-cluster1-haproxy-0, -1, -2 plus the operator pod. The default file uses Group Replication with HAProxy, so there is no Orchestrator pod; ps-cluster1-orc-0 appears only with mysql.clusterType: async and orchestrator.enabled: true. In cr.yaml (kind: PerconaServerMySQL) set crVersion: 1.3.0 and mysql.clusterType to group-replication for production or async for the tech-preview Orchestrator mode.

Read the root credentials from the connection secret ps-cluster1-psuser-root and connect through the proxy from a client pod:

kubectl get secret ps-cluster1-psuser-root -n mysql -o jsonpath='{.data.password}' | base64 --decode && echo
kubectl run -i --rm --tty percona-client --image=percona/percona-server:8.4 --restart=Never -- bash -il
mysql -h ps-cluster1-haproxy -uroot -p            # HAProxy, the default
mysql -h ps-cluster1-router  -uroot -p            # MySQL Router, Group Replication clusters

With Group Replication the default proxy is HAProxy. To use MySQL Router instead, set proxy.router.enabled: true and turn HAProxy off. The Percona 2022 post lists its ports: 6446 read/write to the primary, 6447 read-only across replicas, and 6448 and 6449 for the same split over the X protocol. Confirm the ports on your version.

When it breaks

A writer failure, per operator

PXC: Galera keeps a majority

Three PXC pods and three HAProxy pods. The pod that holds the writer role dies.

Step through it:

PS with async replication: Orchestrator decides

Step through it:

Because Percona calls async mode tech preview, treat this as a lab and test setup for now. Check the current docs before you rely on it.

PS with Group Replication

Group Replication elects a new primary on its own and the proxy follows it (MySQL Router reads the group metadata, HAProxy uses health checks), as on the InnoDB Cluster page. The operator reschedules the failed pod, which rejoins after a RECOVERING phase. If every member crashes, the cluster status is error with reason FullClusterCrashDetected, and the operator reboots the cluster.

Day to day

The commands you will actually run

NS is the namespace and NAME the cluster name (cluster1 for PXC and ps-cluster1 for PS in the default files).

Status

kubectl get pxc -n NS                                      # PXC operator: state, PXC and HAProxy counts
kubectl get ps -n NS                                       # PS operator
kubectl get pxc NAME -n NS -o jsonpath='{.status.state}'   # ready, initializing or error
kubectl get pxc NAME -n NS -o jsonpath='{.status.message}' # why, when state is error
kubectl get pods -n NS

Scale

kubectl scale --replicas=5 pxc/NAME -n NS
kubectl patch ps NAME -n NS --type='json' -p='[{"op":"replace","path":"/spec/mysql/size","value":5}]'

PXC: odd numbers, 3 to 5 recommended. PS: async accepts 2 or more, Group Replication wants an odd number from 3 to 9. Anything else needs unsafeFlags. Do not scale the StatefulSets directly, the operator will not reconcile them back. Proxies are scaled through haproxy.size or proxysql.size in the custom resource, with at least 2 pods by default.

Pause and resume

kubectl patch pxc NAME -n NS --type=merge -p '{"spec":{"pause":true}}'
kubectl patch pxc NAME -n NS --type=merge -p '{"spec":{"pause":false}}'
kubectl patch ps NAME -n NS --type=merge -p '{"spec":{"pause":true}}'
kubectl patch ps NAME -n NS --type=merge -p '{"spec":{"pause":false}}'

The docs set spec.pause by editing cr.yaml: true gracefully stops the cluster, false starts it again. The patch above makes the same change. A paused cluster has no writes, so tell your users first.

Backups

Backups use Percona XtraBackup and go to the storages you list in the custom resource. On demand, you create a backup resource (PerconaXtraDBClusterBackup for PXC). Restore with a restore resource (PerconaXtraDBClusterRestore). Test a restore into a new cluster, not over production.

What goes wrong

Failures to plan for

SymptomLikely causeFirst checkFix
Cluster state error right after a size changeUnsafe node count (PXC outside 3 to 5, even counts, GR outside 3 to 9, proxies under 2)..status.messageSet an allowed size, or set the relevant unsafeFlags knowingly.
Cluster stuck initializingRolling restart in progress, pod Pending, storage or quota.kubectl get pods, describe pod, events.Fix scheduling or storage. Do not delete pods blindly during a restart.
PXC: one node left of threeTwo nodes lost, no majority.Pod status, PXC logs.Restore the other nodes. Do not force a one-node bootstrap unless you accept the data risk and know which node is newest.
PS GR: FullClusterCrashDetectedAll members down.Cluster status reason.Let the operator reboot the cluster. Check the newest member first.
PS async: no new primaryOrchestrator down, recovery blocked or disabled, replicas not in sync.Orchestrator pod logs and API (see the Orchestrator page).Fix Orchestrator. Async mode is tech preview, plan manual steps.
App errors after failoverConnections dropped, proxy not yet updated.Proxy pod health and logs.Retry in the app, reconnect through the Service name.
Backup failsStorage credentials, bucket, or cluster not ready (backups are blocked unless unsafeFlags.backupIfUnhealthy (PXC) or unsafeFlags.backupNonReadyCluster (PS)).Backup resource status.Fix credentials, or the cluster first.
Operator upgrade surprisesCRDs, crVersion mismatch.Release notes of the operator version.Upgrade the operator, then the custom resource, one step at a time, in a test namespace first.
Monitoring

What to watch, and from where

SignalWhereAlert when
Cluster .status.statekube-state-metrics or a periodic kubectl getNot ready for more than a few minutes.
Group membershipperformance_schema.replication_group_members (GR), wsrep_cluster_size and wsrep_ready (PXC)Any member not ONLINE, or a size below the expected count.
Replication lag and queuesMySQL status and PMMLag above your RPO, growing apply queue.
Orchestrator health (async)Orchestrator /metrics and /health/leaderFailed recoveries, no leader.
Backup age and last resultBackup resourcesNo success within the window.
PVC use and pod restartskubelet metricsAbove 80 percent, or restart loops.

Percona documents PMM Client as an optional sidecar, so PMM is the natural place for MySQL-level dashboards. Related pages: Orchestrator, InnoDB Cluster, running 1,000 databases.

Hands off

Let the agent do it

Every change is shown to you first and runs only after you type an approval. Reads run straight away. Use --kind pxc or --kind ps.

python3 -m dbagent.ha k8s status --kind pxc --name CLUSTER -n NS
python3 -m dbagent.ha k8s status --kind ps --name CLUSTER -n NS
python3 -m dbagent.ha k8s pause --kind pxc --name CLUSTER -n NS
python3 -m dbagent.ha k8s resume --kind pxc --name CLUSTER -n NS
python3 -m dbagent.ha k8s scale --kind ps --name CLUSTER --size N -n NS

pause and resume set spec.pause. scale sets the node count and follows the size rules above. The same commands take --kind psmdb for MongoDB.

Where this came from

Sources

Part 1 of 4 · Learn · 56 pagesAll pages

How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.

Start 1: the basicsStart 2: ten conceptsStart 3: how a query travelsStart 4: napkin mathThe courseShort videosPostgreSQL 1: why PostgreSQLPostgreSQL 2: how it stores your dataPostgreSQL 3: what happens on every writePostgreSQL 4: high availability with PatroniPostgreSQL 5: running it as a DBREPostgreSQL 6: when it breaksPostgreSQL on Kubernetes: CloudNativePGMySQL 1: why MySQLMySQL 2: how it stores your dataMySQL 3: what happens on every writeMySQL 4: high availability with InnoDB ClusterMySQL 5: running it as a DBREMySQL 6: when it breaksMySQL failover with OrchestratorMySQL on Kubernetes: the Percona operatorsMongoDB 1: why MongoDBMongoDB 2: how it stores your dataMongoDB 3: what happens on every writeMongoDB 4: high availability with replica setsMongoDB 5: running it as a DBREMongoDB 6: when it breaksMongoDB on Kubernetes: the Percona operatorB-tree and LSM treeRedis 1: why RedisRedis 2: how it stores your dataRedis 3: high availabilityRedis 4: running it as a DBRERedis 5: when it breaksCassandra 1: why CassandraCassandra 2: how it stores your dataCassandra 3: high availabilityCassandra 4: running it as a DBRECassandra 5: when it breaksVector databases 1: why vector searchVector databases 2: how it stores your dataVector databases 3: high availabilityVector databases 4: running it as a DBREVector databases 5: when it breaksDatabase familiesEngines side by sideQueries that look fine and are notLost updates and write skewMany servers 1: keep a copy runningMany servers 2: who is the leaderMany servers 3: CAP as settingsMany servers 4: unique IDsMany servers 5: split the dataMany servers 6: across servicesMany servers 7: a thousand databasesStaff path, zero to architect