General information and hints on deploying MariaDB Kubernetes (K8s) containers, an open source container orchestration system which automates deployments, horizontal scaling, configuration, and operat
Operators basically instruct Kubernetes about how to manage a certain technology. Kubernetes comes with some default operators, but it is possible to create custom operators. Operators created by the community can be found on OperatorHub.io.
Kubernetes provides a declarative API. To support a specific (i.e. MariaDB) technology or implement a desired behavior (i.e. provisioning a replica), we extend Kubernetes API. This involves creating two main components:
A custom resource.
A custom controller.
A custom resource adds an API endpoint, so the resource can be managed via the API server. It includes functionality to get information about the resource, like a list of the existing servers.
A custom controller implements the checks that must be performed against the resource to check if its state should be corrected using the API. In the case of MariaDB, some reasonable checks would be verifying that it accepts connections, replication is running, and a server is (or is not) read only.
MariaDB Enterprise Operator provides a seamless way to run and operate containerized versions of MariaDB Enterprise Server and MaxScale on Kubernetes, allowing you to leverage Kubernetes orchestration and automation capabilities. This document outlines the features and advantages of using Kubernetes and the MariaDB Enterprise Operator to streamline the deployment and management of MariaDB and MaxScale instances.
Find the documentation here.
mariadb-operator is a Kubernetes operator that allows you to run and operate MariaDB in a cloud native way. It aims to declaratively manage MariaDB instances using Kubernetes CRDs instead of imperative commands.
It's available in both Artifact Hub and Operator Hub and supports the following features:
Easily provision and configure MariaDB servers in Kubernetes.
Multiple HA modes: Galera Cluster or MariaDB Replication.
Automated Galera primary failover and cluster recovery.
Advanced HA with MaxScale: a sophisticated database proxy, router, and load balancer for MariaDB.
Flexible storage configuration. Volume expansion.
Physical backups based on mariadb-backup and Kubernetes VolumeSnapshots.
Logical backups based on mariadb-dump.
Multiple backup storage types: S3 compatible, PVCs, Kubernetes volumes and VolumeSnapshots
.
Flexible backup configuration: scheduling, compression, retention policy, timeout, staging area...
Target recovery time: restore the closest available backup to the specified time.
Bootstrap new instances from: Physical backups, logical backups, S3, PVCs, VolumeSnapshots
...
Cluster-aware rolling update: roll out replica Pods one by one, wait for each of them to become ready, and then proceed with the primary Pod, using ReplicasFirstPrimaryLast
.
Manual update strategies: OnDelete
and Never
.
Automated data-plane updates.
my.cnf change detection. Automatically trigger updates when my.cnf changes.
Suspend operator reconciliation for maintenance operations.
Issue, configure and rotate TLS certificates and CAs.
Native integration with cert-manager. Automatically create Certificate
resources.
Prometheus metrics via mysqld-exporter and maxscale-exporter.
Native integration with prometheus-operator. Automatically create ServiceMonitor
resources.
Declaratively manage SQL resources: users, grants and logical databases.
Configure connections for your applications.
Orchestrate and schedule sql scripts.
Validation webhooks to provide CRD immutability.
Additional printer columns to report the current CRD status.
CRDs designed according to the Kubernetes API conventions.
Install it using helm, OLM or static manifests.
Multiple deployment modes: cluster-wide and single namespace.
Helm chart to deploy MariaDB clusters and its associated CRs.
Multi-arch distroless image.
GitOps friendly.
Please, refer to the documentation, the API reference and the example suite for further detail.
This page is licensed: CC BY-SA / Gnu FDL
Kubernetes, or K8s, is software to orchestrate containers. It is released under the terms of an open source license, Apache License 2.0.
Kubernetes was originally developed by Google. Currently it is maintained by the Cloud Native Computing Foundation (CNCF), with the status of Graduated Project.
For information about how to setup a learning environment or a production environment, see Getting started in Kubernetes documentation.
Kubernetes runs in a cluster. A cluster runs a workload: a set of servers that are meant to work together (web servers, database servers, etc).
A Kubernetes cluster consists of the following components:
Nodes run containers with the servers needed by our applications.
Controllersconstantly check the cluster nodes current state, and compare it with the desired state.
A Control Plane is a set of different components that store the cluster desired state and take decisions about the nodes. The Control Plane provides an API that is used by the controllers.
For more information on Kubernetes architecture, see Concepts and Kubernetes Components in Kubernetes documentation.
A node is a system that is responsible to run one or more pods. A pod is a set of containers that run a Kubernetes workload or part of it. All containers that run in the same pod are also located on the same node. Usually identical pods run on different nodes for fault tolerance.
For more details, see Nodes in the Kubernetes documentation.
Every node must necessarily have the following components:
kubelet
kubelet
has a set of PodSpecs
which describe the desired state of pods. It checks that the current state of the pods matches the desired state. It especially takes care that containers don't crash.
kube-proxy
In a typical Kubernetes cluster, several containers located in different pods need to communicate with other containers within the same pods for performance and fault tolerance reasons. When developing and deploying applications, the IP addresses of these containers are unknown in advance. For instance, an application server may need to connect to a MariaDB instance, but the MariaDB's IP will vary for each pod.
The primary role of kube-proxy
is to manage Kubernetes services. When an application needs to connect to MariaDB, it connects to the MariaDB service instead.
kube-proxy
then receives the request and redirects it to a running MariaDB container within the same pod.
Container Runtime
Kubernetes orchestrates containers within a pod using a container runtime that complies with the Kubernetes Container Runtime Interface (CRI). Approved container runtimes are detailed on the Container Runtimes page of the Kubernetes documentation. Additional details about the CRI can be found on GitHub.
Initially, Kubernetes defaulted to using Docker as its container runtime. Though now deprecated, Docker images remain viable with any compatible container runtime.
Controllers constantly check if there are differences between the pod's current state and their desired state. When differences are found, controllers try to fix them. Each node type controls one or more resource types. Several types of controllers are needed to run a cluster.
Most of the actions taken by the controllers user the API server in the Control Plane. However, this is not necessarily true for custom controllers. Also, some actions cannot be performed via the Control Plane. For example, if some nodes crashed, adding new nodes involves taking actions outside of the Kubernetes cluster, and controllers will have to do this themselves.
It is possible to write custom controllers to perform checks that require knowledge about a specific technology. For example, a MariaDB custom controller may want to check if replication is working by issuing SHOW REPLICA STATUS commands. This logic is specific to the way MariaDB works, and can only be implemented in a customer controller. Custom controllers are usually part of operators.
For more information, see Controllers in the Kubernetes documentation.
The control plane consists of the following components.
For more information about the control plane, see Control Plane Components in Kubernetes documentation.
An API Server exposes API functions both internally and externally. It is essential to coordinate Kubernetes components so that they react to node's change of state, and it allows the user to send commands.
The default implementation of the API Server is kube-apiserver. It is able to scale horizontally and to balance the load between its instances.
kube-controller-manager
Most controllers run in this component.
etcd
Contains all data used by a Kubernetes cluster. Taking regular backups of etcd data is advisable.
kube-scheduler
Decides which node should host a new pod based on criteria like resource requirements.
cloud-controller-manager
Implements logic and API of a cloud provider. Handles requests from the API Server and performs actions specific to a cloud vendor, like creating instances.
Kubernetes comes with a set of tools that allow us to communicate with the API server and test a cluster.
kubectl
Enables communication with the API server and allows running commands on a Kubernetes cluster.
kubeadm
Facilitates the creation of a Kubernetes cluster ready to receive commands from kubectl.
kind
Used to create and manage test clusters on a personal machine. It creates a cluster consisting of Docker containers, requiring Docker to be installed. Available on Linux, MacOS, and Windows.
minikube
Runs a single-node cluster on the local machine. Available on Linux, MacOS, and Windows.
Kubernetes on Wikipedia.
Kubernetes organization on GitHub.
(video) MariaDB database clusters on Kubernetes, by Pengfei Ma, at MariaDB Server Fest 2020.
Series of posts by Anel Husakovic on the MariaDB Foundation blog:
Content initially contributed by Vettabase Ltd.
This page is licensed: CC BY-SA / Gnu FDL