|29 Sep 2023
|14 Dec 2023
|03 Jan 2024
|15 Feb 2024
juju deploy mysql --channel 8.0/stable
MySQL is the world’s most popular open source database. The “Charmed MySQL” is a Juju-based operator to deploy and support MySQL from day 0 to day 2, it is based on the MySQL Community Edition using the built-in cluster functionality: MySQL InnoDB ClusterSet.
HLD (High Level Design)
The charm design leverages on the SNAP “charmed-mysql” which is deployed by Juju on the specified VM/MAAS/bare-metal machine based on Ubuntu Jammy/22.04. SNAP allows to run MySQL service(s) in a secure and isolated environment (strict confinement). The installed SNAP:
> juju ssh mysql/0
> snap list charmed-mysql
Name Version Rev Tracking Publisher Notes
charmed-mysql 8.0.34 69 latest/stable dataplatformbot held
The SNAP ships the following components:
- MySQL Community Edition (based on Ubuntu APT package “mysql-server-8.0”)
- MySQL Router (based on Ubuntu APT package “mysql-router”)
- MySQL Shell (based on Canonical backport)
- Percona XtraBackup (based on Canonical backport)
- Prometheus MySQLd Exporter (based on Canonical backport)
- Prometheus MySQL Router Exporter (based on Canonical backport)
- Prometheus Grafana dashboards and Loki alert rules are part of the charm revision and missing in SNAP.
Versions of all the components above are carefully chosen to fit functionality of each other.
The Charmed MySQL unit consisting of a several services which are enabled/activated accordingly to the setup:
> snap services charmed-mysql
Service Startup Current Notes
charmed-mysql.mysqld enabled active -
charmed-mysql.mysqld-exporter disabled inactive -
charmed-mysql.mysqlrouter-service disabled inactive -
charmed-mysql.mysqlrouterd-exporter disabled inactive -
mysqld snap service is a main MySQL instance which is normally up and running right after the charm deployment.
exporter services are activated after the relation with COS Monitoring only.
Note: it is possible to star/stop/restart snap services manually but it is NOT recommended to avoid a split brain with a charm state machine! Do it with a caution!!!
Important: all snap resources must be executed under the special user
The snap “charmed-mysql” also ships list of tools used by charm:
mysql) - mysql client to connect
charmed-mysql.mysqlsh- new mysql-shell client to configure MySQL cluster.
charmed-mysql.xbcloud- a tool to download and upload full or part of xbstream archive from/to the cloud.
charmed-mysql.xbstream- a tool to support simultaneous compression and streaming.
charmed-mysql.xtrabackup- a tool to backup/restore MySQL DB.
mysqlsh are well known and popular tools to manage MySQL.
xtrabackup (xbcloud+xbstream) used for MySQL Backups only to store backups on S3 compatible storage.
MySQL Router is part of MySQL InnoDB Cluster, and is lightweight middle-ware that provides transparent routing between your application and back-end MySQL Servers. The “Charmed MySQL Router” is an independent charm “Charmed MySQL” can be related with.
TLS Certificates Operator
TLS Certificates charm responsible for distributing certificates through relationship. Certificates are provided by the operator through Juju configs. For the playground deployments, the self-signed operator is available as well.
S3 Integrator is an integrator charm for providing S3 credentials to Charmed MySQL which seek to access shared S3 data. Store the credentials centrally in the integrator charm and relate consumer charms as needed.
Data Integrator charm is a solution to request DB credentials for non-native Juju applications. Not all applications implement a data_interfaces relation but allow setting credentials via config. Also, some of the applications are run outside of juju. This integrator charm allows receiving credentials which can be passed into application config directly without implementing juju-native relation.
MySQL Test App
The charm “MySQL Test App” is a Canonical test application to validate the charm installation / functionality and perform the basic performance tests.
Grafana is an open-source visualization tools that allows to query, visualize, alert on, and visualize metrics from mixed datasources in configurable dashboards for observability. This charms is shipped with its own Grafana dashboard and supports integration with the Grafana Operator to simplify observability. Please follow COS Monitoring setup.
Prometheus is an open-source systems monitoring and alerting toolkit with a dimensional data model, flexible query language, efficient time series database and modern alerting approach. This charm is shipped with a Prometheus exporters, alerts and support for integrating with the Prometheus Operator to automatically scrape the targets. Please follow COS Monitoring setup.
LLD (Low Level Design)
Please check the charm state machines displayed on workflow diagrams. The low-level logic is mostly common for both VM and K8s charms.
Accordingly to the Juju SDK: “an event is a data structure that encapsulates part of the execution context of a charm”.
For this charm, the following events are observed:
- on_install: install the snap “charmed-mysql” and perform basic preparations to bootstrap the cluster on the first leader (or join the already configured cluster).
- leader-elected: generate all the secrets to bootstrap the cluster.
- leader-settings-changed: Handle the leader settings changed event.
- start: Init/setting up the cluster node.
- config_changed: usually fired in response to a configuration change using the GUI or CLI. Create and set default cluster and cluster-set names in the peer relation databag (on the leader only).
- update-status: Takes care of workload health checks.
Charm Code Overview
__init__ method guarantees that the charm observes all events relevant to its operation and handles them.
charmcraft list-lib mysql
Library name API Patch
backups 0 7
mysql 0 45
s3_helpers 0 4
tls 0 2