MySQL is a stateful application that can be deployed and managed on Kubernetes. However, running a database on Kubernetes can be challenging due to the unique characteristics of databases and the way they use resources. To deploy a MySQL Cluster, a NdbCluster custom resource with a specific configuration has to be created inside the K8s Cluster. The Ndb Operator will then start deploying the MySQL Cluster in that K8s Cluster.
Deployment Database Management
Kubernetes is designed to handle stateless applications, so running a database through the platform may seem daunting. However, this live event will allay your fears and demonstrate that running MySQL on the forum is possible and incredibly simple. The MySQL Operator is a custom Kubernetes resource that manages a MySQL InnoDB Cluster’s full lifecycle inside a Kubernetes ssis 816 cluster.
It deploys the MySQL servers, replicates them using the MySQL Group Replication plugin, and sets up a MySQL Router Pod before the MySQL Cluster for query routing. The Operator also automatically backs up databases to Object Storage at predefined intervals.
By default, the Management and MySQL services are ClusterIP and can only be accessed within the Kubernetes cluster. To make these services accessible from outside the Kubernetes cluster, upgrade them to a LoadBalancer service type. You can do this by setting the pec.managementNode.enableLoadBalancer and spec.mysqlNode.enableLoadBalancer fields to true when creating the NdbCluster resource or updating them after deployment. You should deploy your NdbCluster in a dedicated Kubernetes namespace to separate it from other services. You can use storage of a pd-balanced Persistent Disk to balance performance and cost, and the volumeBindingMode should be WaitForFirstConsumer. This ensures that GKE delays the provisioning of a PersistentVolume for your MySQL instance until the first consumer starts up.
Unlike other applications that can be fully run in containers, databases require a physical host. This is because a database server must have access to mass storage, which is typically not available in containers. The Oracle MySQL Kubernetes Operator addresses this issue through a PersistentVolumeClaim. Pods managed by the Operator are bound to the claimed PersistentVolume, which is a part of the database cluster. As the number of Pods grows, the Operator will automatically add more host nodes to the MySQL Cluster.
The number of hosts can be configured using the kubectl command line or via YAML files. The MySQL Operator also offers a self-healing solution. When a MySQL process dies, the Operator will detect it and immediately restart a new database instance. This allows for high availability and avoids data loss in a database failure.
The operator pattern has become a popular solution for automating day-to-day tasks such as deployment, scaling, and backups for stateful applications. Besides easing the burden on DevOps teams, it also delivers hybrid and multi-cloud portability.
Several operators have been built in the community to run stateful Kubernetes applications, such as Cloud Native PG and Zalando’s Postgres operator. Moreover, Oracle is an open-source operator that helps modernize and transform database operations while offering a consistent management experience for stateful and stateless applications.
Although horizontally scaling MySQL adds resiliency, external backups are still vital if the cluster is compromised or data is accidentally deleted. Luckily, the MySQL operator makes storing an entire database dump in a K8s ephemeral volume or an Amazon S3-compatible object storage bucket simple. The backup can be restored if necessary, simplifying the post-disaster recovery process.
The yaml file in the example above defines a BackupPolicy that specifies the location of the backup Pod, the ServiceAccount to run it, and the environment variables to pass credentials. It also sets the name of the temporary volume to use as the working directory.
Local persistent volumes are another option, but they are less robust since the backup will reside inside your Kubernetes cluster. To keep the database available, the MySQL Operator uses semi-synchronous replication. This ensures that completed transactions won’t be lost when a MySQL node fails. The Operator also supports a wide variety of quotas, including reserved quotas.
Oracle MySQL Kubernetes Operator provides a full management lifecycle of MySQL InnoDB Cluster setups inside a Kubernetes Cluster. It manages the deployment, StatefulSets, storage, and automated upgrades and backups. It was developed by Oracle and made it to the General Availability (GA) stage in April 2022. It supports only MySQL 8.0 and deploys a MySQL server Pod with Group Replication and a MySQL router Pod for query routing. It also helps a Private registry.
It uses MySQL Shell under the hood and is written in Python. Initially, Kubernetes was designed for simple stateless microservices, but it’s also growing fast to support other workloads. Some applications require special treatment – like databases. They don’t fit well into a model that aims to make everything immutable
. This is why the Kubernetes platform has Operators. Operators are software extensions that tie a specific kind of application to the Kubernetes platform. Running complex applications like a database on Kubernetes requires knowledge of the underlying platform and specific orchestration, scaling, and maintenance skills.
These complexities were the reason why many administrators experienced apprehension when it came to running their database on Kubernetes. This course will dispel these fears by showing how a fully managed, highly available, and easily customizable MySQL server can be deployed on Kubernetes with the help of the MySQL Operator.