Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona
About me ● Working with MySQL for 10-15 years ○ Started at MySQL AB, Sun Microsystems, Oracle (MySQL Consulting) ○ Joined Percona in 2013 2
What is Kubernetes? Container orchestration system /* Operating system */ * Kubernetes is an open source system for managing containerized applications across multiple hosts 3
Container orchestration 4
Container Orchestration in Barcelona 5
Why ? Deployment, Deployment, Deployment! ○ Challenge: how to deploy massively scaled application ○ Or databases: how do you deploy 100 nodes clustering system 6
Kubernetes Implementations ● ● ● ● ● ● ● 7
Let’s look under the hood 8
● ● ● ● ● ○
Databases in Containers: Challenges 1. Preserving state 2. Setup as cluster/replication 12
● ○ ○
Why for databases? 15
MySQL In Kubernetes ● A single instance is easy ○ https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-appli cation/ 16
A complex setup is … more complex ● High Availability ● Persistent Storage ● Backup and recovery ● Traffic routing ● Monitoring 17
18
Replication
Replication Options ● Traditional MySQL replication ● Group Replication ● Percona XtraDB Cluster 20
Traditional Replication challenges ● No automatic failover ○ New master detection can be quite complicated ● No automatic slave setup 21
Group Replication ● Not mature enough ● Still no automatic slave setup 22
What is Percona XtraDB Cluster (PXC)? 23
Why PXC? Auto provisioning... 24
PXC: Data transfer 25
Storage
Storage options ● Local storage ○ Can be fast (SSD, NVMe options) ○ Still limited management capabilities in Kubernetes ● Network storage ○ Management and Flexibility if supported by your setup Supported by major cloud providers ■ ○ On-premise setup may require Ceph or SAN ○ The dynamic provision of persistent volumes is required 27
Traffic routing
Traffic routing ● ProxySQL ○ High-performance MySQL proxy ○ Query Routing ○ Supports Failover 29
What is ProxySQL? 30
ProxySQL read/write split Query routing is one of the core features of ProxySQL. Read/write split is perhaps one of the most common query routing use 31
ProxySQL read-write split 32
PXC + ProxySQL on Kubernetes / Openshift 33
Monitoring ● Percona Monitoring And Management 34
Percona Labs - MySQL for Kubernetes https://github.com/Percona-Lab/percona-openshift $ git clone git@github.com:Percona-Lab/percona-openshift.git 35
Deployment options
Deployment options ● Manual ● Helm Charts ● Operator 37
Manual ● Manual juggling multiple YAML files backup-volume.yaml mysql-configmap.yaml proxysql-pxc.yaml pxc.yaml secret.yaml xtrabackup-job.yaml ● Cumbersome and error-prone ● Practically not feasible for a complicated setup ● Deployment logic and configuration parameters are mixed together 38
Helm Charts Helm - The package manager for Kubernetes ● Separate configuration from logic To continue “Kubernetes is an Operating System” analogy - Helm chart is like RPM/DEB packages 39
Operator ● Method of packaging, deploying and managing a Kubernetes application ● The most advanced way of the deployment ● Requires software engineering efforts ● A way to think about “Operator” is it’s goal is to replace a human in typical operations ● Assumes a high degree of automation 40
41 * image: RedHat OpenShift documentation
Demo: Let’s start our PXC cluster $ helm install --name cluster1 . -f values.yaml Will start: ● 3 nodes of Percona XtraDB Cluster, each with PMM Client ● ProxySQL instance Configure ProxySQL to route traffic 42
$ kubectl get pods NAME READY STATUS RESTARTS AGE cluster1-node-0 2/2 Running 0 5m cluster1-node-1 2/2 Running 0 4m cluster1-node-2 2/2 Running 0 2m cluster1-proxysql-0 2/2 Running 0 5m monitoring-0 1/1 Running 0 16m 43
Let’s take a minute here With a single command we ● Started multiple MySQL nodes (and Kubernetes will handle a node failure) ● Started and configured ProxySQL ● Added all nodes under PMM Server 44
What’s so big deal about it? ● One can do it with reasonably simple Ansible playbooks? Kubernetes is Cloud-agnostic; provides an uniform API; “write once - run anywhere” approach 45
Demo / Howto - pods $ kubectl get pods NAME READY STATUS RESTARTS cluster1-proxysql-0 2/2 Running 0 cluster1-node-0 2/2 Running 0 cluster1-node-1 2/2 Running 0 cluster1-node-2 2/2 Running 0 46
Demo / Howto $ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) cluster1-proxysql ClusterIP 10.11.251.66 <none> 3306/TCP,6032/TCP MySQL Port (for app) Proxy Admin Port 47
ProxySQL Admin Configuration kubectl exec cluster1-proxysql-0 -it -- mysql -uadmin -padmin -h127.0.0.1 -P6032 mysql> select * from mysql_servers; +--------------+-----------+------+--------+---------+-------------+-----------------+----+---------+ | hostgroup_id | hostname | port | status | weight | compression | max_connections | .. | comment | +--------------+-----------+------+--------+---------+-------------+-----------------+----+---------+ | 10 | 10.8.2.10 | 3306 | ONLINE | 1000000 | 0 | 1000 | .. | WRITE | | 11 | 10.8.1.6 | 3306 | ONLINE | 1000 | 0 | 1000 | .. | READ | | 11 | 10.8.0.10 | 3306 | ONLINE | 1000 | 0 | 1000 | .. | READ | +--------------+-----------+------+--------+---------+-------------+-----------------+----+---------+ 48
Let’s kill one pod… NAME READY STATUS RESTARTS AGE cluster1-node-0 0/2 Terminating 0 41m cluster1-node-1 2/2 Running 0 41m cluster1-node-2 2/2 Running 0 40m cluster1-proxysql-0 2/2 Running 0 41m monitoring-0 1/1 Running 0 35m 49
Kubernetes will restart it mysql> select * from mysql_servers; +--------------+-----------+------+--------------+---------+-------------+-----------------+---------+ | hostgroup_id | hostname | port | status | weight | compression | max_connections | comment | +--------------+-----------+------+--------------+---------+-------------+-----------------+---------+ | 11 | 10.8.2.10 | 3306 | OFFLINE_HARD | 1000 | 0 | 1000 | READ | | 11 | 10.8.1.6 | 3306 | ONLINE | 1000 | 0 | 1000 | READ | | 10 | 10.8.0.10 | 3306 | ONLINE | 1000000 | 0 | 1000 | WRITE | | 11 | 10.8.2.12 | 3306 | ONLINE | 1000 | 0 | 1000 | READ | +--------------+-----------+------+--------------+---------+-------------+-----------------+---------+ 50
Let’s scale it up kubectl scale --replicas=4 statefulset/cluster1-node statefulset "cluster1-node" scaled 51
mysql> select * from mysql_servers; +--------------+-----------+------+--------------+---------+-------------+-----------------+---------+ | hostgroup_id | hostname | port | status | weight | compression | max_connections | comment | +--------------+-----------+------+--------------+---------+-------------+-----------------+---------+ | 11 | 10.8.2.10 | 3306 | OFFLINE_HARD | 1000 | 0 | 1000 | READ | | 11 | 10.8.1.6 | 3306 | ONLINE | 1000 | 0 | 1000 | READ | | 10 | 10.8.0.10 | 3306 | ONLINE | 1000000 | 0 | 1000 | WRITE | | 11 | 10.8.2.12 | 3306 | ONLINE | 1000 | 0 | 1000 | READ | | 11 | 10.8.1.7 | 3306 | ONLINE | 1000 | 0 | 1000 | READ | +--------------+-----------+------+--------------+---------+-------------+-----------------+---------+ 52
Demo Failover 53
The Road Ahead ● Operators ● Encryptions ○ At Rest ○ End-to-end ● Key Management 54
Additional resources ● Oracle’s MySQL Operator (Alpha quality) https://github.com/oracle/mysql-operator ● Presslab’s Operator https://github.com/presslabs/mysql-operator ● MariaDB Helm https://github.com/mariadb-corporation/mariadb-kubernetes ● GRTL MySQL Operator https://github.com/grtl/mysql-operator 55
Helm for MongoDB https://github.com/Percona-Lab/percona-server-mongodb-openshi ft/tree/master/helm/mongodb-replicaset Install Helm in OpenShift For the details see https://blog.openshift.com/getting-started-helm-openshift/ 56
Recommend
More recommend