Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander...

60
Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona

Transcript of Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander...

Page 1: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

Deploying MySQL and MongoDB in Kubernetes

Alexander RubinPercona

Page 2: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

2

About me

● Working with MySQL for 10-15 years○ Started at MySQL AB, Sun Microsystems, Oracle

(MySQL Consulting)○ Joined Percona in 2013

Page 3: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

3

What is Kubernetes?

Container orchestration system/* Operating system */

* Kubernetes is an open source system for managing containerized applications across multiple hosts

Page 4: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

4

Container orchestration

Page 5: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

5

Container Orchestration in Barcelona

Page 6: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

6

Why ?

Deployment, Deployment, Deployment!○ Challenge: how to deploy massively scaled application○ Or databases: how do you deploy 100 nodes clustering system

Page 7: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

7

Kubernetes Implementations

●●●●●●●

Page 8: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

8

Let’s look under the hood

Page 9: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun
Page 10: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun
Page 11: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

●●●●●

Page 12: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

12

Databases in Containers: Challenges

1. Preserving state2. Setup as cluster/replication

Page 13: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

●○○

Page 14: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun
Page 15: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

15

Why for databases?

Page 16: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

16

MySQL In Kubernetes

● A single instance is easy○ https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-appli

cation/

Page 17: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

17

A complex setup is … more complex

● High Availability● Persistent Storage● Backup and recovery● Traffic routing● Monitoring

Page 18: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

18

Page 19: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

Replication

Page 20: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

20

Replication Options

● Traditional MySQL replication● Group Replication● Percona XtraDB Cluster

Page 21: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

21

Traditional Replication challenges

● No automatic failover○ New master detection can be quite complicated

● No automatic slave setup

Page 22: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

22

Group Replication

● Not mature enough● Still no automatic slave setup

Page 23: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

23

What is Percona XtraDB Cluster (PXC)?

Page 24: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

24

Why PXC? Auto provisioning...

Page 25: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

25

PXC: Data transfer

Page 26: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

Storage

Page 27: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 28: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

Traffic routing

Page 29: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

29

Traffic routing

● ProxySQL○ High-performance MySQL proxy○ Query Routing○ Supports Failover

Page 30: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

30

What is ProxySQL?

Page 31: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 32: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

32

ProxySQL read-write split

Page 33: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

33

PXC + ProxySQL on Kubernetes / Openshift

Page 34: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

34

Monitoring

● Percona MonitoringAnd Management

Page 35: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

35

Percona Labs - MySQL for Kubernetes

https://github.com/Percona-Lab/percona-openshift $ git clone [email protected]:Percona-Lab/percona-openshift.git

Page 36: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

Deployment options

Page 37: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

37

Deployment options

● Manual● Helm Charts● Operator

Page 38: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 39: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 40: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 41: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

41* image: RedHat OpenShift documentation

Page 42: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 43: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 44: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 45: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 46: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 47: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 48: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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 |+--------------+-----------+------+--------+---------+-------------+-----------------+----+---------+

Page 49: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 50: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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 |+--------------+-----------+------+--------------+---------+-------------+-----------------+---------+

Page 51: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

51

Let’s scale it up

kubectl scale --replicas=4 statefulset/cluster1-node

statefulset "cluster1-node" scaled

Page 52: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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 |+--------------+-----------+------+--------------+---------+-------------+-----------------+---------+

Page 54: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

54

The Road Ahead

● Operators● Encryptions

○ At Rest○ End-to-end

● Key Management

Page 55: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 56: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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/

Page 57: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

57

Operator

MongoDB server: Operator

https://github.com/Percona-Lab/percona-server-mongodb-operator

Page 58: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

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

Page 59: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

59

Thank you!

Page 60: Kubernetes MongoDB in Deploying MySQL and...Deploying MySQL and MongoDB in Kubernetes Alexander Rubin Percona 2 About me Working with MySQL for 10-15 years Started at MySQL AB, Sun

60

Thank You Sponsors!!