Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander...
Transcript of Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander...
Deploying MySQL and MongoDB in Kubernetes
Alexander RubinPercona
2
About me
● Working with MySQL for 10-15 years○ Started at MySQL AB, Sun Microsystems, Oracle
(MySQL Consulting)○ Joined Percona in 2013
3
What is Kubernetes?
Container orchestration system/* Operating system */
* Kubernetes is an open source system for managing containerized applications across multiple hosts
4
Container orchestration
5
Container Orchestration in Barcelona
6
Why ?
Deployment, Deployment, Deployment!○ Challenge: how to deploy massively scaled application○ Or databases: how do you deploy 100 nodes clustering system
7
Kubernetes Implementations
●●●●●●●
8
Let’s look under the hood
●●●●●
○
12
Databases in Containers: Challenges
1. Preserving state2. Setup as cluster/replication
●○○
15
Why for databases?
16
MySQL In Kubernetes
● A single instance is easy○ https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-appli
cation/
17
A complex setup is … more complex
● High Availability● Persistent Storage● Backup and recovery● Traffic routing● Monitoring
18
Replication
20
Replication Options
● Traditional MySQL replication● Group Replication● Percona XtraDB Cluster
21
Traditional Replication challenges
● No automatic failover○ New master detection can be quite complicated
● No automatic slave setup
22
Group Replication
● Not mature enough● Still no automatic slave setup
23
What is Percona XtraDB Cluster (PXC)?
24
Why PXC? Auto provisioning...
25
PXC: Data transfer
Storage
27
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
Traffic routing
29
Traffic routing
● ProxySQL○ High-performance MySQL proxy○ Query Routing○ Supports Failover
30
What is ProxySQL?
31
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
32
ProxySQL read-write split
33
PXC + ProxySQL on Kubernetes / Openshift
34
Monitoring
● Percona MonitoringAnd Management
35
Percona Labs - MySQL for Kubernetes
https://github.com/Percona-Lab/percona-openshift $ git clone [email protected]:Percona-Lab/percona-openshift.git
Deployment options
37
Deployment options
● Manual● Helm Charts● Operator
38
Manual
● Manual juggling multiple YAML files
● Cumbersome and error-prone● Practically not feasible for a complicated setup● Deployment logic and configuration parameters are mixed together
backup-volume.yamlmysql-configmap.yamlproxysql-pxc.yamlpxc.yamlsecret.yamlxtrabackup-job.yaml
39
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
40
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
41* image: RedHat OpenShift documentation
42
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
43
$ 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
44
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
45
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
46
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
47
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
48
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 |+--------------+-----------+------+--------+---------+-------------+-----------------+----+---------+
49
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
50
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 |+--------------+-----------+------+--------------+---------+-------------+-----------------+---------+
51
Let’s scale it up
kubectl scale --replicas=4 statefulset/cluster1-node
statefulset "cluster1-node" scaled
52
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 |+--------------+-----------+------+--------------+---------+-------------+-----------------+---------+
54
The Road Ahead
● Operators● Encryptions
○ At Rest○ End-to-end
● Key Management
55
Additional resources
● Oracle’s MySQL Operator (Alpha quality) https://github.com/oracle/mysql-operator
● Presslab’s Operatorhttps://github.com/presslabs/mysql-operator
● MariaDB Helm https://github.com/mariadb-corporation/mariadb-kubernetes
● GRTL MySQL Operator https://github.com/grtl/mysql-operator
56
Helm for MongoDB
https://github.com/Percona-Lab/percona-server-mongodb-openshift/tree/master/helm/mongodb-replicaset
Install Helm in OpenShiftFor the details see https://blog.openshift.com/getting-started-helm-openshift/
57
Operator
MongoDB server: Operator
https://github.com/Percona-Lab/percona-server-mongodb-operator
58
Conclusion
● Openshift provides easy deployment for MySQL (Percona XtraDB Cluster)○ Great for deployment and testing
● ProxySQL provides the cluster endpoint○ Implements read-write split
59
Thank you!
60
Thank You Sponsors!!