Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Containerized MySQL
Running MySQL in containers and on Kubernetes
Patrick Galbraith
Principal Platform Engineer
Platform Engineering, Dyn + Oracle
October 22, 2018
Confidential – Oracle Internal/Restricted/Highly
Restricted
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
About
2
Oracle + Dyn Platform Services
● Oracle Dyn, HP, Blue Gecko, MySQL AB, Classmates, Slashdot, Cobalt
Group, US Navy
● MySQL projects: memcached UDFs, DBD::mysql, federated storage engine,
Galera on Kubernetes example, Percona helm chart, etc
● Learning, Languages, Family, Outdoors
● Chile
● Not a designer, as you can see :)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
About my team
• DNS -- https://dyn.com
– Dyn provides managed DNS for the world’s largest and most admired web properties
– One of the largest, fastest, and most resilient DNS networks in the world
– Over 3,500 enterprises, including preeminent digital brands like Netflix, Twitter, Linkedin and
CNBC
• Email
– Dyn Email Delivery has helped organizations with large sending needs for over a decade
• Oracle Cloud (OCI) https://cloud.oracle.com/home
– Dyn providing Edge Services for Oracle Cloud Infrastructure
– We’re hiring! https://dyn.com/careers/
3
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
What is this presentation about?
• De-mystifying containers
• MySQL running in containers
• MySQL on Kubernetes
• Stateful applications – StatefulSets
• Operators - MySQL Operator
• Sharding - Vitess
• Time permitting…
• Save questions until the end 
4
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
What are containers and Docker?
• Set of tools for managing containers
• Command line tool client and daemon
• Kernel namespaces – the core ingredient to containers working
• PID
• IPC
• uts (what will be seen by a group of processes)
• Mount
• Network
• User
• Cgroups (control groups) -- limit, account and isolate resource usage
• Cgroups (CPU, memory, disk I/O, etc.) of process groups
5
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
VMs and Containers
comparison
6
VM Container
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Patterns and AntiPatterns
• Patterns
• Keep it simple – simple containers
• Containers are cattle
• Vanilla Hosts
• Keep your images small
• Use the source, Luke!
• Anti-patterns
• Containers are not VMs!
• Containers are NOT pets
• Don’t run containers with a provisioner built-in
• Do. Not. Build. Your. Own. Scheduler. (!)
• Using containers to container persistent data
7
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Orchestrating Containers
• Mesos
• OpenStack
• CoreOS
• Kubernetes
• Hashicorp Nomad
8
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
A tale of two open source projects
• MySQL (MySQL, MariaDB, Percona, etc)
– World’s most popular open source database
– Ubiquitous
– 20+ years
• Kubernetes
– Fastest growing open source project
– Application deployment done right
– Community-driven
– Moving target, rapidly developing
– Borg Paper https://research.google.com/pubs/pub43438.html?hl=es
9
MySQL and Kubernetes
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Databases: Pets vs. Cattle
10
● Database containers tend to be more pets than cattle
● A pod of multiple database instances or one?
● “Kubernetes Pods are mortal.”
● A database is a complex stateful application
● Consistent access: applications get the same database
● Safety: don’t scale if unhealthy (obvious)
● Persistent storage
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Kubernetes ingredients for stateful applications
11
● Labels
● Services
● KubeDNS
● Helm Charts
● PV/PVC, StorageClass
● StatefulSets
○ Init containers
○ VolumeClaimTemplates
● Operators
○ CustomResourceDefinition
● Side-car containers
● nodeSelector
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
NodeSelector
12
● Can be used to achieve affinity to a specific node
● Label assigned to node
kubectl label nodes ip-172.xxx.ec2.internal boxtype=c3.medium
spec:
containers:
- image: mysql:5.6
name: mysql
...<snip>...
nodeSelector:
boxtype: c3.medium
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Node and Pod Affinity/AntiAffinity
● Based on labels
● nodeAffinity/nodeAntiAffinity uses labels on node
● podAffinity/podAntiAffinity labels of pods already running on node
metadata:
name: with-node-affinity (or with-pod-affinity)
spec:
affinity:
nodeAffinity:
● Hard - “must” requiredDuringSchedulingIgnoredDuringExecution
● Soft - “preferred” preferredDuringSchedulingIgnoredDuringExecution
13
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
StatefulSets
14
● Provide guarantees about ordering and uniqueness of pods and pod resources
○ Maintains persistent, sticky identity for each of their pods, across rescheduling
○ Ensures ordinality - Deterministic initialization order.
○ At most one pod per index
○ Pods are not interchangeable and won’t attempt to run a pod with the same name
● Stable network identity
○ Consistent pod name set as subdomain within domain of headless service, eg “mysql”,
nodes name “node-N.mysql”
○ DNS name is stable across restarts
● Stable Storage/Stateful resources.
○ Pods re-mount same persistent storage across restarts
● Safety
○ Scaling is blocked if system is unhealthy
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Deployment/ReplicaSet
● Started in no specific order
● name-<depid>-<rand alpha>
● Will scale if crash and
replace with another non-
unique name
Deployment
/ReplicaSet
Crash!
mysql-1389738847-bmsg7
mysql-1389738847-nz828
mysql-1389738847-x99km
mysql-1389738847-t542x
15
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
StatefulSet
● Started in order
● Names unique and
distinct per node-ordinal
● Must replace failed node
by name
● Won’t scale when cluster
is unhealthy
StatefulSet
Crash!
mysql-0
mysql-1
mysql-2
Don’t scale and
must replace
mysql-2
16
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Headless Service
17
● Service with clusterIP of None
○ Makes it so all nodes have an A-
record of service-
<ord>.<service name>
○ This service is not used for
application or clients
● For read-only, create another service
- mysql-read which can be of any
type (nodePort, clusterIP,
loadBalancer)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
VolumeClaimTemplate
18
● Define a ServiceType
● Specify type in VolumeClaimTemplate
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 19
mysql-0
mysql-2
mysql-1
MySQL simple replication StatefulSet
https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/
Mysql-read
service
read/write
-h mysql-0.mysql
App /
client
replication
Read only
-h mysql-read
replication
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
mysql-N pod
App containers
Init containers
20
data
Mysql
clone-mysql
init-mysql
conf
backup/etc/mysql/conf.d
Config-map
Contains
master.cnf
slave.cnf
/var/lib/mysql
/var/lib/mysqlCopy master.cnf or
slave.cnf depending
on ordinal
mysql-(N+1) pod
clone-mysql
init-mysql
● Init Containers
● App Containers
● Sidecar Containers
clone-mysql only
restores if ordinal > 0
(slave)
An operator would have this
functionality built-in
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Operators
● Application-specific domain controller
● Encodes application-specific domain knowledge through extending
Kubernetes API using custom resource definitions (CRD)
● Enables users to create, configure, and manage stateful applications
● Built upon resources and controllers concepts
● Leverage Kubernetes primitives like ReplicaSets, StatefulSets, and
Services
● Operator executes common application tasks
● Installed as a deployment
● Application run using custom resource definition types for operator
eg. EtcdCluster, Prometheus, MySQL Cluster, Backup,
Restore, Oracle WebLogic etc
21
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Operators
22
observe
Analyze
Act
“etcdX” cluster has 2 running pods
● etcd-0, version 3.1.1
● etcd-1, version 3.2.10
How get desired config
● Recover 1 member
● Upgrade etcd-0 to 3.2.10
Differences from desired config
● Should be version 3.2.10
● Should have 3 members
https://coreos.com/blog/introducing-the-etcd-operator.html
● Create/Destroy: No need for
specifications of each member.
Just size of cluster.
● Resize: Only specify size.
Operator will deploy, destroy,
or reconfigure as needed
● Backup: built-in, only need to
specify backup policy
● Upgrade: operator will ensure
members are correct version
avoiding headaches
● Etcd operator
https://youtu.be/tPSys734iNk
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
MySQL Operator
● New Open source project from Oracle -- released in early in 2018
● https://github.com/oracle/mysql-operator
● Deploy a highly-available clustered MySQL instance into Kubernetes
with a single command
● Watches the API server for Custom Resource Definitions related to
MySQL (Cluster) and acts on those resources
● Backup/Restore made simple with Backup, BackupSchedule,
and Restore custom resources
● PV/PVC Block Storage
● Utilizes Group replication
● Automated backup/restore to/from object storage
23
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
MySQL Operator
Features:
Create/Scale/Destroy: Easily create, scale and
delete self healing MySQL clusters inside a
Kubernetes namespace
● Simple Configuration: Provide configuration
for your MySQL cluster with simple
Kubernetes objects (Secrets and
ConfigMaps)
● Backups: Defined scheduled backup policies
as part of your cluster to make sure your
data is always protected or, alternatively,
create on-demand snapshot backups with a
single command.
24
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Examples : StorageClass
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
kubectl.kubernetes.io/last-applied-
configuration: |
{"apiVersion":"storage.k8s.io/v1beta1","kind":
"StorageClass","metadata":{"annotations":{"storagecl
ass.beta.kubernetes.io/is-default-
class":"true"},"name":"oci","namespace":""},"provisi
oner":"oracle.com/oci"}
storageclass.beta.kubernetes.io/is-default-
class: "true"
creationTimestamp: 2018-09-03T02:38:04Z
name: oci
resourceVersion: "313"
selfLink:
/apis/storage.k8s.io/v1/storageclasses/oci
uid: 61e52032-af22-11e8-aa27-0a580aed2e0f
25
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Examples : Dynamic volume
apiVersion: "mysql.oracle.com/v1"
kind: Cluster
metadata:
name: mysql
spec:
replicas: 3
volumeClaimTemplate:
metadata:
name: data
annotations:
volume.alpha.kubernetes.io/storage-class: oci
spec:
storageClassName: oci
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
26
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Examples: simple cluster
apiVersion: "mysql.oracle.com/v1"
kind: Cluster
metadata:
name: mysql
Create a cluster:
kubectl apply -f mysql-test-cluster.yaml
List clusters:
kubectl get mysql-operator.mysql.oracle.com
27
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Examples: simple cluster and backup
apiVersion: "mysql.oracle.com/v1"
kind: Backup
metadata:
name: mysql-backup
spec:
executor:
mysqldump:
databases:
- wordpress
storageProvider:
s3:
endpoint: s3.us-east-1.amazonaws.com
region: us-east-1
bucket: mysql-demo-backup
forcePathStyle: true
credentialsSecret:
name: s3-credentials
cluster:
name: mysql
Create a backup:
kubectl apply -f backup.yaml
List backups:
kubectl get mysqlbackups
Fetch an individual backup:
kubectl get mysqlbackup primary/123
28
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Examples: simple restore
apiVersion: "mysql.oracle.com/v1"
kind: Restore
metadata:
name: mysql-restore
spec:
clusterRef:
name: mysql
backupRef:
name: mysql-backup
Restore a cluster:
kubectl apply -f mysql-restore.yaml
29
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Examples: scheduled backup
apiVersion: mysql.oracle.com/v1
kind: BackupSchedule
metadata:
name: mysql-morning-backup
spec: schedule: '* 01 * * *'
backupTemplate:
executor:
provider: mysqldump
databases:
- wordpress
storageProvider:
s3:
endpoint: s3.us-east-1.amazonaws.com
region: us-east-1
bucket: mysql-demo-backup
credentialsSecret:
name: s3-credentials
cluster:
name: mysql
30
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Connecting
● Read-only service
● Write to single pod
● Read/Write service
● MySQL Router
31
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Scaling
● Pods
● Write to single pod
● Disk
● ExpandPersistentVolumes, PersistentVolumeClaimResize
● Requires StorageClass to specify allowVolumeExpansion: true
32
https://youtu.be/RGvcANwi6PU
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Other MySQL Operators
● https://www.percona.com/community-blog/2018/10/11/deploying-
mysql-on-kubernetes-with-a-percona-based-operator/
(https://github.com/presslabs/mysql-operator)
● https://github.com/grtl/mysql-operator
● Good Comparison https://banzaicloud.com/blog/mysql-on-
kubernetes/
33
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
MySQL Operator Demos
● Create a 3-node MySQL backed by OCI block storage, utilizing
external DNS, and running Wordpress, using MySQLBackup/Restore
https://youtu.be/RGvcANwi6PU
● Create a 3-node MySQL cluster!
https://youtu.be/SeD5eSh3lL8
● Backups made easy! On-demand backup of an existing cluster
https://youtu.be/h_W5xtdce0k
34
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
: sharding on a silver platter (http://vitess.io)
35
● Database solution for deploying, scaling and managing large
clusters of MySQL instances
● YouTube database store since 2011
● Looks like MySQL database in usage, but is sharded underneath
● Cloud ready (The cloud is coming!)
● Helps you scale with transparent dynamic sharding and ability to
continue sharding out (or in)
● Cluster management – tools for backups, shards, and schema
● MySQL client protocol, gRPC
● Connection pooling
● Protects MySQL with query - de-duping, re-writing, sanitization,
black-listing, adding LIMIT on unbound queries, etc
● Monitoring tools - built into all Vitess binaries.
● If you want to migrate your MySQL application to the cloud, Vitess
is an excellent vehicle to use!
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 36
orchestrator
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Sharding
● A shard consists of a single master that handles writes, one or more slaves that
handle reads
● Horizontal - split or merge shards in a sharded keyspace
● Vertical - moving tables from an unsharded keyspace to a different keyspace
● Re-sharding
○ split, merge, add new cells and replicas
○ Filtered replication using GTID key ingredient ensures source tablet data is
transferred to proper destination VTtablet
● Vschema - Vitess Schema - ties together all databases managed by Vitess and
helps to decide where queries should go
● Vindex - cross-shard index provides a way to map a column value to a keyspace ID
37
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Schema and Vschema
# schema - user keyspace
create table user(
user_id bigint,
name varchar(128),
primary key(user_id)
);
// vschema - user keyspace
{
"sharded": true,
"vindexes": {
"hash": {
"type": "hash"
},
"tables": {
"user": {
"column_vindexes": [
{
"column": "user_id",
"name": "hash" # NOTE: vindex name
}
]
}
}
}
38
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Reparenting
● Reparenting
○ Changing shard’s master tablet to another host
○ Changing slave tablet to have a different master
● GTID
○ GTID is used to initialize replication
○ GTID replication stream is used in parenting
● Types of reparenting
○ PlannedReparentShard - healthy master tablet to new master
○ EmergencyReparentShard - forces reparent to a new master when master unavailable. Data connect be
retrieved from current master
● Re-sharding
○ split, merge, add new cells and replicas
○ Filtered replication key ingredient ensures source tablet data is transferred to proper destination VTtablet
39
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
backups
● Backup
○ Plugins for NFS, GCS, S3, Ceph
○ VTtablet must have access to where storage, flags to provided to vtctl
○ Replica MySQL instance stopped, data copied, instanced started
○ vtctl backup <tablet-alias>
● Restore
○ For restore, VTtablet started with arguments specifying whether to restore from a backup, the storage
implementation and backup storage root (path)
● Commands
○ vtctl backup <tablet-alias>
○ vtctl ListBackups <keyspace/shard>
○ vtctl RemoveBackup <keyspace/shard>
vttablet
mysql
Storage (NFS, S3, GCS,
Ceph)
Object
storage
Mysqlctl
backup
40
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Vitess Operator
● VitessCluster – top level specification
● VitessCell – Failure domain/AZ
● EtcdCluster
● Deployment(s) orchestrator, vtctld, vtgate
● VitessKeyspace – comprised of multiple shards
● VitessShard – multiple vttablets, creates multiple StatefulSets of pods and
PersistentVolumeClaims
● kubectl get vitessclusters
41
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Vitess StatefulSet Demo
https://youtu.be/9in5HenJ9xY
● Create two shards
● Load database schema and vschema
● Scale one shard from 2 replicas to 3
● Delete StatefulSet, delete master pod, reparent
● Anthony Yeh, https://github.com/enisoc/vitess.git,
statefulset-demo branch
42
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Questions Preguntas Fragen सवाल...
Patg at Patg dot net
http://patg.net
43
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Thank you!
Special thanks to:
Platform Team Oracle Dyn
Ali Mukadam
Anthony Yeh
Sugu Sougoumarane
Owain Lewis
44
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Extra slides - resources
45
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Collectbeats
● Open Source effort within Ebay
● Inspired by Metricbeat module “drop in”
concept.
● Find all pods exposing metrics and start polling
● Ability to
○ Collect metrics from any pod that exposes
them
○ Collect logs from STDOUT or logs on
container
○ Append pod metadata to logs and metrics
○ Allow pods to push metrics through
Graphite protocol and parse them
uniquely
○ Stitch stack-traces for application logs
● http://bit.ly/2zT4VNZ
46
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Other MySQL installation examples
● helm install --name kubeconf stable/percona
○ https://www.youtube.com/watch?v=kZOk0w6YKMA
● Simple replication with a stateful set https://kubernetes.io/docs/tasks/run-
application/run-replicated-stateful-application/
○ https://www.youtube.com/watch?v=M7EWFL83Vdc
● Galera StatefulSet by SeveralNines https://severalnines.com/blog/mysql-
docker-running-galera-cluster-kubernetes
○ https://youtu.be/3vn7Jd9z4kc
47

Containerized MySQL OpenWorld talk

  • 1.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Containerized MySQL Running MySQL in containers and on Kubernetes Patrick Galbraith Principal Platform Engineer Platform Engineering, Dyn + Oracle October 22, 2018 Confidential – Oracle Internal/Restricted/Highly Restricted
  • 2.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | About 2 Oracle + Dyn Platform Services ● Oracle Dyn, HP, Blue Gecko, MySQL AB, Classmates, Slashdot, Cobalt Group, US Navy ● MySQL projects: memcached UDFs, DBD::mysql, federated storage engine, Galera on Kubernetes example, Percona helm chart, etc ● Learning, Languages, Family, Outdoors ● Chile ● Not a designer, as you can see :)
  • 3.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | About my team • DNS -- https://dyn.com – Dyn provides managed DNS for the world’s largest and most admired web properties – One of the largest, fastest, and most resilient DNS networks in the world – Over 3,500 enterprises, including preeminent digital brands like Netflix, Twitter, Linkedin and CNBC • Email – Dyn Email Delivery has helped organizations with large sending needs for over a decade • Oracle Cloud (OCI) https://cloud.oracle.com/home – Dyn providing Edge Services for Oracle Cloud Infrastructure – We’re hiring! https://dyn.com/careers/ 3
  • 4.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | What is this presentation about? • De-mystifying containers • MySQL running in containers • MySQL on Kubernetes • Stateful applications – StatefulSets • Operators - MySQL Operator • Sharding - Vitess • Time permitting… • Save questions until the end  4
  • 5.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | What are containers and Docker? • Set of tools for managing containers • Command line tool client and daemon • Kernel namespaces – the core ingredient to containers working • PID • IPC • uts (what will be seen by a group of processes) • Mount • Network • User • Cgroups (control groups) -- limit, account and isolate resource usage • Cgroups (CPU, memory, disk I/O, etc.) of process groups 5
  • 6.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | VMs and Containers comparison 6 VM Container
  • 7.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Patterns and AntiPatterns • Patterns • Keep it simple – simple containers • Containers are cattle • Vanilla Hosts • Keep your images small • Use the source, Luke! • Anti-patterns • Containers are not VMs! • Containers are NOT pets • Don’t run containers with a provisioner built-in • Do. Not. Build. Your. Own. Scheduler. (!) • Using containers to container persistent data 7
  • 8.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Orchestrating Containers • Mesos • OpenStack • CoreOS • Kubernetes • Hashicorp Nomad 8
  • 9.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | A tale of two open source projects • MySQL (MySQL, MariaDB, Percona, etc) – World’s most popular open source database – Ubiquitous – 20+ years • Kubernetes – Fastest growing open source project – Application deployment done right – Community-driven – Moving target, rapidly developing – Borg Paper https://research.google.com/pubs/pub43438.html?hl=es 9 MySQL and Kubernetes
  • 10.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Databases: Pets vs. Cattle 10 ● Database containers tend to be more pets than cattle ● A pod of multiple database instances or one? ● “Kubernetes Pods are mortal.” ● A database is a complex stateful application ● Consistent access: applications get the same database ● Safety: don’t scale if unhealthy (obvious) ● Persistent storage
  • 11.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Kubernetes ingredients for stateful applications 11 ● Labels ● Services ● KubeDNS ● Helm Charts ● PV/PVC, StorageClass ● StatefulSets ○ Init containers ○ VolumeClaimTemplates ● Operators ○ CustomResourceDefinition ● Side-car containers ● nodeSelector
  • 12.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | NodeSelector 12 ● Can be used to achieve affinity to a specific node ● Label assigned to node kubectl label nodes ip-172.xxx.ec2.internal boxtype=c3.medium spec: containers: - image: mysql:5.6 name: mysql ...<snip>... nodeSelector: boxtype: c3.medium
  • 13.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Node and Pod Affinity/AntiAffinity ● Based on labels ● nodeAffinity/nodeAntiAffinity uses labels on node ● podAffinity/podAntiAffinity labels of pods already running on node metadata: name: with-node-affinity (or with-pod-affinity) spec: affinity: nodeAffinity: ● Hard - “must” requiredDuringSchedulingIgnoredDuringExecution ● Soft - “preferred” preferredDuringSchedulingIgnoredDuringExecution 13
  • 14.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | StatefulSets 14 ● Provide guarantees about ordering and uniqueness of pods and pod resources ○ Maintains persistent, sticky identity for each of their pods, across rescheduling ○ Ensures ordinality - Deterministic initialization order. ○ At most one pod per index ○ Pods are not interchangeable and won’t attempt to run a pod with the same name ● Stable network identity ○ Consistent pod name set as subdomain within domain of headless service, eg “mysql”, nodes name “node-N.mysql” ○ DNS name is stable across restarts ● Stable Storage/Stateful resources. ○ Pods re-mount same persistent storage across restarts ● Safety ○ Scaling is blocked if system is unhealthy
  • 15.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Deployment/ReplicaSet ● Started in no specific order ● name-<depid>-<rand alpha> ● Will scale if crash and replace with another non- unique name Deployment /ReplicaSet Crash! mysql-1389738847-bmsg7 mysql-1389738847-nz828 mysql-1389738847-x99km mysql-1389738847-t542x 15
  • 16.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | StatefulSet ● Started in order ● Names unique and distinct per node-ordinal ● Must replace failed node by name ● Won’t scale when cluster is unhealthy StatefulSet Crash! mysql-0 mysql-1 mysql-2 Don’t scale and must replace mysql-2 16
  • 17.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Headless Service 17 ● Service with clusterIP of None ○ Makes it so all nodes have an A- record of service- <ord>.<service name> ○ This service is not used for application or clients ● For read-only, create another service - mysql-read which can be of any type (nodePort, clusterIP, loadBalancer)
  • 18.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | VolumeClaimTemplate 18 ● Define a ServiceType ● Specify type in VolumeClaimTemplate
  • 19.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | 19 mysql-0 mysql-2 mysql-1 MySQL simple replication StatefulSet https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/ Mysql-read service read/write -h mysql-0.mysql App / client replication Read only -h mysql-read replication
  • 20.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | mysql-N pod App containers Init containers 20 data Mysql clone-mysql init-mysql conf backup/etc/mysql/conf.d Config-map Contains master.cnf slave.cnf /var/lib/mysql /var/lib/mysqlCopy master.cnf or slave.cnf depending on ordinal mysql-(N+1) pod clone-mysql init-mysql ● Init Containers ● App Containers ● Sidecar Containers clone-mysql only restores if ordinal > 0 (slave) An operator would have this functionality built-in
  • 21.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Operators ● Application-specific domain controller ● Encodes application-specific domain knowledge through extending Kubernetes API using custom resource definitions (CRD) ● Enables users to create, configure, and manage stateful applications ● Built upon resources and controllers concepts ● Leverage Kubernetes primitives like ReplicaSets, StatefulSets, and Services ● Operator executes common application tasks ● Installed as a deployment ● Application run using custom resource definition types for operator eg. EtcdCluster, Prometheus, MySQL Cluster, Backup, Restore, Oracle WebLogic etc 21
  • 22.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Operators 22 observe Analyze Act “etcdX” cluster has 2 running pods ● etcd-0, version 3.1.1 ● etcd-1, version 3.2.10 How get desired config ● Recover 1 member ● Upgrade etcd-0 to 3.2.10 Differences from desired config ● Should be version 3.2.10 ● Should have 3 members https://coreos.com/blog/introducing-the-etcd-operator.html ● Create/Destroy: No need for specifications of each member. Just size of cluster. ● Resize: Only specify size. Operator will deploy, destroy, or reconfigure as needed ● Backup: built-in, only need to specify backup policy ● Upgrade: operator will ensure members are correct version avoiding headaches ● Etcd operator https://youtu.be/tPSys734iNk
  • 23.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | MySQL Operator ● New Open source project from Oracle -- released in early in 2018 ● https://github.com/oracle/mysql-operator ● Deploy a highly-available clustered MySQL instance into Kubernetes with a single command ● Watches the API server for Custom Resource Definitions related to MySQL (Cluster) and acts on those resources ● Backup/Restore made simple with Backup, BackupSchedule, and Restore custom resources ● PV/PVC Block Storage ● Utilizes Group replication ● Automated backup/restore to/from object storage 23
  • 24.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | MySQL Operator Features: Create/Scale/Destroy: Easily create, scale and delete self healing MySQL clusters inside a Kubernetes namespace ● Simple Configuration: Provide configuration for your MySQL cluster with simple Kubernetes objects (Secrets and ConfigMaps) ● Backups: Defined scheduled backup policies as part of your cluster to make sure your data is always protected or, alternatively, create on-demand snapshot backups with a single command. 24
  • 25.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Examples : StorageClass --- apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: annotations: kubectl.kubernetes.io/last-applied- configuration: | {"apiVersion":"storage.k8s.io/v1beta1","kind": "StorageClass","metadata":{"annotations":{"storagecl ass.beta.kubernetes.io/is-default- class":"true"},"name":"oci","namespace":""},"provisi oner":"oracle.com/oci"} storageclass.beta.kubernetes.io/is-default- class: "true" creationTimestamp: 2018-09-03T02:38:04Z name: oci resourceVersion: "313" selfLink: /apis/storage.k8s.io/v1/storageclasses/oci uid: 61e52032-af22-11e8-aa27-0a580aed2e0f 25
  • 26.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Examples : Dynamic volume apiVersion: "mysql.oracle.com/v1" kind: Cluster metadata: name: mysql spec: replicas: 3 volumeClaimTemplate: metadata: name: data annotations: volume.alpha.kubernetes.io/storage-class: oci spec: storageClassName: oci accessModes: - ReadWriteOnce resources: requests: storage: 50Gi 26
  • 27.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Examples: simple cluster apiVersion: "mysql.oracle.com/v1" kind: Cluster metadata: name: mysql Create a cluster: kubectl apply -f mysql-test-cluster.yaml List clusters: kubectl get mysql-operator.mysql.oracle.com 27
  • 28.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Examples: simple cluster and backup apiVersion: "mysql.oracle.com/v1" kind: Backup metadata: name: mysql-backup spec: executor: mysqldump: databases: - wordpress storageProvider: s3: endpoint: s3.us-east-1.amazonaws.com region: us-east-1 bucket: mysql-demo-backup forcePathStyle: true credentialsSecret: name: s3-credentials cluster: name: mysql Create a backup: kubectl apply -f backup.yaml List backups: kubectl get mysqlbackups Fetch an individual backup: kubectl get mysqlbackup primary/123 28
  • 29.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Examples: simple restore apiVersion: "mysql.oracle.com/v1" kind: Restore metadata: name: mysql-restore spec: clusterRef: name: mysql backupRef: name: mysql-backup Restore a cluster: kubectl apply -f mysql-restore.yaml 29
  • 30.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Examples: scheduled backup apiVersion: mysql.oracle.com/v1 kind: BackupSchedule metadata: name: mysql-morning-backup spec: schedule: '* 01 * * *' backupTemplate: executor: provider: mysqldump databases: - wordpress storageProvider: s3: endpoint: s3.us-east-1.amazonaws.com region: us-east-1 bucket: mysql-demo-backup credentialsSecret: name: s3-credentials cluster: name: mysql 30
  • 31.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Connecting ● Read-only service ● Write to single pod ● Read/Write service ● MySQL Router 31
  • 32.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Scaling ● Pods ● Write to single pod ● Disk ● ExpandPersistentVolumes, PersistentVolumeClaimResize ● Requires StorageClass to specify allowVolumeExpansion: true 32 https://youtu.be/RGvcANwi6PU
  • 33.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Other MySQL Operators ● https://www.percona.com/community-blog/2018/10/11/deploying- mysql-on-kubernetes-with-a-percona-based-operator/ (https://github.com/presslabs/mysql-operator) ● https://github.com/grtl/mysql-operator ● Good Comparison https://banzaicloud.com/blog/mysql-on- kubernetes/ 33
  • 34.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | MySQL Operator Demos ● Create a 3-node MySQL backed by OCI block storage, utilizing external DNS, and running Wordpress, using MySQLBackup/Restore https://youtu.be/RGvcANwi6PU ● Create a 3-node MySQL cluster! https://youtu.be/SeD5eSh3lL8 ● Backups made easy! On-demand backup of an existing cluster https://youtu.be/h_W5xtdce0k 34
  • 35.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | : sharding on a silver platter (http://vitess.io) 35 ● Database solution for deploying, scaling and managing large clusters of MySQL instances ● YouTube database store since 2011 ● Looks like MySQL database in usage, but is sharded underneath ● Cloud ready (The cloud is coming!) ● Helps you scale with transparent dynamic sharding and ability to continue sharding out (or in) ● Cluster management – tools for backups, shards, and schema ● MySQL client protocol, gRPC ● Connection pooling ● Protects MySQL with query - de-duping, re-writing, sanitization, black-listing, adding LIMIT on unbound queries, etc ● Monitoring tools - built into all Vitess binaries. ● If you want to migrate your MySQL application to the cloud, Vitess is an excellent vehicle to use!
  • 36.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | 36 orchestrator
  • 37.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Sharding ● A shard consists of a single master that handles writes, one or more slaves that handle reads ● Horizontal - split or merge shards in a sharded keyspace ● Vertical - moving tables from an unsharded keyspace to a different keyspace ● Re-sharding ○ split, merge, add new cells and replicas ○ Filtered replication using GTID key ingredient ensures source tablet data is transferred to proper destination VTtablet ● Vschema - Vitess Schema - ties together all databases managed by Vitess and helps to decide where queries should go ● Vindex - cross-shard index provides a way to map a column value to a keyspace ID 37
  • 38.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Schema and Vschema # schema - user keyspace create table user( user_id bigint, name varchar(128), primary key(user_id) ); // vschema - user keyspace { "sharded": true, "vindexes": { "hash": { "type": "hash" }, "tables": { "user": { "column_vindexes": [ { "column": "user_id", "name": "hash" # NOTE: vindex name } ] } } } 38
  • 39.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Reparenting ● Reparenting ○ Changing shard’s master tablet to another host ○ Changing slave tablet to have a different master ● GTID ○ GTID is used to initialize replication ○ GTID replication stream is used in parenting ● Types of reparenting ○ PlannedReparentShard - healthy master tablet to new master ○ EmergencyReparentShard - forces reparent to a new master when master unavailable. Data connect be retrieved from current master ● Re-sharding ○ split, merge, add new cells and replicas ○ Filtered replication key ingredient ensures source tablet data is transferred to proper destination VTtablet 39
  • 40.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | backups ● Backup ○ Plugins for NFS, GCS, S3, Ceph ○ VTtablet must have access to where storage, flags to provided to vtctl ○ Replica MySQL instance stopped, data copied, instanced started ○ vtctl backup <tablet-alias> ● Restore ○ For restore, VTtablet started with arguments specifying whether to restore from a backup, the storage implementation and backup storage root (path) ● Commands ○ vtctl backup <tablet-alias> ○ vtctl ListBackups <keyspace/shard> ○ vtctl RemoveBackup <keyspace/shard> vttablet mysql Storage (NFS, S3, GCS, Ceph) Object storage Mysqlctl backup 40
  • 41.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Vitess Operator ● VitessCluster – top level specification ● VitessCell – Failure domain/AZ ● EtcdCluster ● Deployment(s) orchestrator, vtctld, vtgate ● VitessKeyspace – comprised of multiple shards ● VitessShard – multiple vttablets, creates multiple StatefulSets of pods and PersistentVolumeClaims ● kubectl get vitessclusters 41
  • 42.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Vitess StatefulSet Demo https://youtu.be/9in5HenJ9xY ● Create two shards ● Load database schema and vschema ● Scale one shard from 2 replicas to 3 ● Delete StatefulSet, delete master pod, reparent ● Anthony Yeh, https://github.com/enisoc/vitess.git, statefulset-demo branch 42
  • 43.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Questions Preguntas Fragen सवाल... Patg at Patg dot net http://patg.net 43
  • 44.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Thank you! Special thanks to: Platform Team Oracle Dyn Ali Mukadam Anthony Yeh Sugu Sougoumarane Owain Lewis 44
  • 45.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Extra slides - resources 45
  • 46.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Collectbeats ● Open Source effort within Ebay ● Inspired by Metricbeat module “drop in” concept. ● Find all pods exposing metrics and start polling ● Ability to ○ Collect metrics from any pod that exposes them ○ Collect logs from STDOUT or logs on container ○ Append pod metadata to logs and metrics ○ Allow pods to push metrics through Graphite protocol and parse them uniquely ○ Stitch stack-traces for application logs ● http://bit.ly/2zT4VNZ 46
  • 47.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Other MySQL installation examples ● helm install --name kubeconf stable/percona ○ https://www.youtube.com/watch?v=kZOk0w6YKMA ● Simple replication with a stateful set https://kubernetes.io/docs/tasks/run- application/run-replicated-stateful-application/ ○ https://www.youtube.com/watch?v=M7EWFL83Vdc ● Galera StatefulSet by SeveralNines https://severalnines.com/blog/mysql- docker-running-galera-cluster-kubernetes ○ https://youtu.be/3vn7Jd9z4kc 47