Bernd Ocklin
Snr Director MySQL Cluster Development
About me
Bernd Ocklin
Product Owner MySQL NDB Cluster at Oracle
with NDB and MySQL since 2005
Massively linear scale
Sharded Distributed Datasets
Parallel Real-Time Performance.
Auto-partitioning, data distribution
and replication built-in.
Read- and Write Scale-Out
TBs on commodity hardware.
Always-On 99.9999% Availability
Designed for mission critical
systems. Masterless, shared-nothing
with no single point of failure.
Always Consistent
Transactional consistency across
distributed and partitioned dataset.
Out of the box straightforward
application programming.
Standalone or with MySQL
as a SQL front-end.
Ease of use
Open Source
Written in C++.
Shared Nothing
Written in C++. Can be used standalone
or with MySQL as a SQL front-end.
MySQL Cluster Industries
Telecom
Financials
Gaming & Massive Parallel Online Games
Why Cloud Native?
Speed
Fast introduction of
new services
Scaling
Fast scaling from
hundred of users to
millions
Efficient Operations
Automation
Lifecycle
Performance / Capacity
Improved capacity
Better resource
utilisation
Fit for kubernetes?
VMs or container?
VM Containers / K8
workload isolation ++ o / ++
performance + ++
IO o ++
operations - ++
maturity / community / best practices ++ +
footprint - +
cloud native principles o ++
*) e.g. katacontainers
But running databases in a container and kubernetes?
• Yes, you can run any database in a container. Period.
• Just a matter of workload to serve and requirements.
• Milage varies with database’s suitability.
Suitable databases and cloud native principles
Resilience
Losing parts of the
system should not
be a big deal.
It should
automatically
recover and heal it
self.
Shared-Nothing
Cloud-native
databases can
operate without
centralized
management or
any single point of
failure.
Scaling, sharding
Distributed data
Scaling out, not up
Sharding.
Distributed, cloud-
native databases
should present a the
same view of data
independent of
instance queried.
With the
consistency
guarantees of a
single-machine
system.
Standards
Cloud-native
databases should
also support query
standards.
Consistency
Cloud native databases
MySQL NDB classic RDMS InnoDB Cluster
Resilience
Shared-nothing
Consistent view of data
Scaling out, sharding
Standard query language
Self healing
Stateless?
• You should architect your system to be intentional about
when, and how, you store state
• Design components to be stateless wherever 

you can
• Not stateless but smart about state, 

state optimized!
Kubernetes
Analytics
Reporting
Orchestration Operation
Orchestration
& Automation
State”less”
Microservices
Data Layer
Platform 

Services
(Cloud)
Infrastructure
Highly Available
Object Store
Kubernetes Objects running a database
Container
Container
docker hub
. . .
containers:
- image: mysql/mysql-cluster:8.0.22
imagePullPolicy: IfNotPresent
name: ndb
command: ["/bin/bash"]
args:
- -ecx
- /usr/sbin/ndbd -c mgmd-0.ndb-svc.default.svc.cluster.local 
—initial --nodaemon -v
Kubernetes Objects running a database
Pod
Container
Container
docker hub
Workload Resources
Pod
Pod
Container
Container
Workload API
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: StatefulSet
...
spec:
...
serviceName: ndb-svc
template:
spec:
containers:
- image: mysql/mysql-cluster:8.0.22
...
volumeMounts:
- name: ndb-persistent-storage
mountPath: /var/lib/ndb
- name: config-volume
mountPath: /var/lib/ndb/config
....
Running MySQL Cluster in Kubernetes with StatefulSets
Pod
StatefulSet
Pod
Container
Container
• Stable, unique network identifiers.
• Stable, persistent storage.
• Ordered, graceful deployment and scaling.
• Ordered, automated rolling updates.
Headless Service providing network identity
Pod
Headless
Service
StatefulSet
Network
identity
Pod
Container
Container
apiVersion: v1
kind: Service
metadata:
name: ndb-svc
labels:
app: ndb
spec:
ports:
- port: 1186
selector:
app: ndb
clusterIP: None
ConfigMaps to “inject” configuration into Pods/Containers
Pod
Headless
Service
StatefulSet
Network
identity
ConfigMap
Pod
Container
Container
Config as volume
kind: ConfigMap
apiVersion: v1
metadata:
name: ndb-configmap
namespace: default
data:
config.ini: |
[ndbd default]
# NDB redundancy level
NoOfReplicas=3
....
Persistent
Volume Claim
Use Persistent Volumes for storage
Pod
Headless
Service
Persistent
Volume
StatefulSet
Network
identity
Persistent
Volume Claim
Persistent
Volume
ConfigMap
Pod
Container
Container
Config as volume
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ndb-pv-claimp
labels:
app: ndb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
NDB Architecture
“stateless”

Microservices
optional
SQL Layer
MySQL NDB Cluster
Partitioning- and distribution engine
MySQL NDB Cluster in Kubernetes
Pod
Sidecar container
Data Node container
Persistent
Volume Claim
Persistent
Volume
ConfigMap
Pod
Sidecar container
Management Node container
Config
Data- and trace files
MySQL NDB Cluster in Kubernetes
Deployment
Cluster
StatefulSet
NDB Cluster
Data Node
Data Node
Data Node
Data Node
Mgm Node
StatefulSet
Mgm Node
Pod
Pod
Pod
Pod
Pod
Pod
Demo - deploying manually
https://www.github.com/ocklin/ndb-k8-manually
Best practices
DNS “stability”
• Pods
• reschedule on other Kubernetes nodes
• change IP addresses
• consider DNS TTL, time to resolve new host address
• GRANT … TO 

‘username’@<IP-address>
• Use AllowUnresolvedHostnames=1
• Retry
!
Service Mesh Istio
• Envoy is a proxy
• connects to cluster will “look like” connects 

from localhost
• cluster expects connects from remote host
• use TcpBind_INADDR_ANY = 1
Sidecars
• Always use a most minimal maintenance container
• idle, low resource
• but allows parallel access to volumes 

and stored data
• easier debugging if things go wrong
Kubernetes is complex
• Many layers and teams responsible
• Lots of people or resources to blame if 

something goes wrong
• Observability is key!
PodDisruptionBudgets and Eviction API
• Eviction API considers pod disruption budgets
• e.g. used when draining kubernetes nodes
• makes sure that you do not accidentally 

shutdown all your nodes of the database
• kubectl delete ignores 

PodDisruptionBudgets!
PodAffinity and AntiAffinity
• All nodes have labels, make heavy use of labels!
• PodAffinity allows to prefer k8 nodes with labels to e.g.
• keep database nodes apart across racks or ADs
• avoid collocation of instances sharing 

same data
• prefer faster storage (e.g. SSD)
MySQL NDB Operator
Kubernetes Operators
• Declarative approach
• Manages services “like a human”
• Based on 

Custom Resource Definitions
Operator reconciliation driving towards desired state
K8
Object
Store
kube
controller
etcd
kube
scheduler
api server
container
Container
Runtime
image
Kublet
image
container
get
wanted state
get
actual state
take mitigation
actions
operator controllers workers
…
…
control plane
$ kubectl apply -f operator-crd.yaml
MySQL NDB Cluster in Kubernetes
Deployment
Kubernete
StatefulSet
NDB Cluster
Ndb operator
backup /
restore
controller
mysql
controll
NDB
controller
Data Node
Data Node
Data Node
Data Node
Mgm Node
StatefulSet
Mgm Node
CRD
Operator Demo
Ndb Custom Resource Definition
apiVersion: mysql.oracle.com/v1alpha1
kind: Ndb
metadata:
name: example-ndb
spec:
containerImage: mysql/mysql-cluster:8.0.22
nodecount: 2
redundancyLevel: 2
mysqld:
nodecount: 2
Thank You
Bernd Ocklin
Snr Director
MySQL Cluster Development

Run Cloud Native MySQL NDB Cluster in Kubernetes

  • 1.
    Bernd Ocklin Snr DirectorMySQL Cluster Development
  • 2.
    About me Bernd Ocklin ProductOwner MySQL NDB Cluster at Oracle with NDB and MySQL since 2005
  • 3.
    Massively linear scale ShardedDistributed Datasets Parallel Real-Time Performance. Auto-partitioning, data distribution and replication built-in. Read- and Write Scale-Out TBs on commodity hardware. Always-On 99.9999% Availability Designed for mission critical systems. Masterless, shared-nothing with no single point of failure. Always Consistent Transactional consistency across distributed and partitioned dataset. Out of the box straightforward application programming. Standalone or with MySQL as a SQL front-end. Ease of use Open Source Written in C++. Shared Nothing Written in C++. Can be used standalone or with MySQL as a SQL front-end.
  • 4.
  • 5.
    Why Cloud Native? Speed Fastintroduction of new services Scaling Fast scaling from hundred of users to millions Efficient Operations Automation Lifecycle Performance / Capacity Improved capacity Better resource utilisation
  • 6.
  • 7.
    VMs or container? VMContainers / K8 workload isolation ++ o / ++ performance + ++ IO o ++ operations - ++ maturity / community / best practices ++ + footprint - + cloud native principles o ++ *) e.g. katacontainers
  • 8.
    But running databasesin a container and kubernetes? • Yes, you can run any database in a container. Period. • Just a matter of workload to serve and requirements. • Milage varies with database’s suitability.
  • 9.
    Suitable databases andcloud native principles Resilience Losing parts of the system should not be a big deal. It should automatically recover and heal it self. Shared-Nothing Cloud-native databases can operate without centralized management or any single point of failure. Scaling, sharding Distributed data Scaling out, not up Sharding. Distributed, cloud- native databases should present a the same view of data independent of instance queried. With the consistency guarantees of a single-machine system. Standards Cloud-native databases should also support query standards. Consistency
  • 10.
    Cloud native databases MySQLNDB classic RDMS InnoDB Cluster Resilience Shared-nothing Consistent view of data Scaling out, sharding Standard query language Self healing
  • 11.
    Stateless? • You shouldarchitect your system to be intentional about when, and how, you store state • Design components to be stateless wherever 
 you can • Not stateless but smart about state, 
 state optimized!
  • 12.
  • 13.
    Analytics Reporting Orchestration Operation Orchestration & Automation State”less” Microservices DataLayer Platform 
 Services (Cloud) Infrastructure Highly Available Object Store
  • 14.
    Kubernetes Objects runninga database Container Container docker hub . . . containers: - image: mysql/mysql-cluster:8.0.22 imagePullPolicy: IfNotPresent name: ndb command: ["/bin/bash"] args: - -ecx - /usr/sbin/ndbd -c mgmd-0.ndb-svc.default.svc.cluster.local —initial --nodaemon -v
  • 15.
    Kubernetes Objects runninga database Pod Container Container docker hub
  • 16.
    Workload Resources Pod Pod Container Container Workload API apiVersion:apps/v1 # for versions before 1.9.0 use apps/v1beta2 kind: StatefulSet ... spec: ... serviceName: ndb-svc template: spec: containers: - image: mysql/mysql-cluster:8.0.22 ... volumeMounts: - name: ndb-persistent-storage mountPath: /var/lib/ndb - name: config-volume mountPath: /var/lib/ndb/config ....
  • 17.
    Running MySQL Clusterin Kubernetes with StatefulSets Pod StatefulSet Pod Container Container • Stable, unique network identifiers. • Stable, persistent storage. • Ordered, graceful deployment and scaling. • Ordered, automated rolling updates.
  • 18.
    Headless Service providingnetwork identity Pod Headless Service StatefulSet Network identity Pod Container Container apiVersion: v1 kind: Service metadata: name: ndb-svc labels: app: ndb spec: ports: - port: 1186 selector: app: ndb clusterIP: None
  • 19.
    ConfigMaps to “inject”configuration into Pods/Containers Pod Headless Service StatefulSet Network identity ConfigMap Pod Container Container Config as volume kind: ConfigMap apiVersion: v1 metadata: name: ndb-configmap namespace: default data: config.ini: | [ndbd default] # NDB redundancy level NoOfReplicas=3 ....
  • 20.
    Persistent Volume Claim Use PersistentVolumes for storage Pod Headless Service Persistent Volume StatefulSet Network identity Persistent Volume Claim Persistent Volume ConfigMap Pod Container Container Config as volume apiVersion: v1 kind: PersistentVolumeClaim metadata: name: ndb-pv-claimp labels: app: ndb spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi
  • 21.
    NDB Architecture “stateless”
 Microservices optional SQL Layer MySQLNDB Cluster Partitioning- and distribution engine
  • 22.
    MySQL NDB Clusterin Kubernetes Pod Sidecar container Data Node container Persistent Volume Claim Persistent Volume ConfigMap Pod Sidecar container Management Node container Config Data- and trace files
  • 23.
    MySQL NDB Clusterin Kubernetes Deployment Cluster StatefulSet NDB Cluster Data Node Data Node Data Node Data Node Mgm Node StatefulSet Mgm Node Pod Pod Pod Pod Pod Pod
  • 24.
    Demo - deployingmanually https://www.github.com/ocklin/ndb-k8-manually
  • 25.
  • 26.
    DNS “stability” • Pods •reschedule on other Kubernetes nodes • change IP addresses • consider DNS TTL, time to resolve new host address • GRANT … TO 
 ‘username’@<IP-address> • Use AllowUnresolvedHostnames=1 • Retry !
  • 27.
    Service Mesh Istio •Envoy is a proxy • connects to cluster will “look like” connects 
 from localhost • cluster expects connects from remote host • use TcpBind_INADDR_ANY = 1
  • 28.
    Sidecars • Always usea most minimal maintenance container • idle, low resource • but allows parallel access to volumes 
 and stored data • easier debugging if things go wrong
  • 29.
    Kubernetes is complex •Many layers and teams responsible • Lots of people or resources to blame if 
 something goes wrong • Observability is key!
  • 30.
    PodDisruptionBudgets and EvictionAPI • Eviction API considers pod disruption budgets • e.g. used when draining kubernetes nodes • makes sure that you do not accidentally 
 shutdown all your nodes of the database • kubectl delete ignores 
 PodDisruptionBudgets!
  • 31.
    PodAffinity and AntiAffinity •All nodes have labels, make heavy use of labels! • PodAffinity allows to prefer k8 nodes with labels to e.g. • keep database nodes apart across racks or ADs • avoid collocation of instances sharing 
 same data • prefer faster storage (e.g. SSD)
  • 32.
  • 33.
    Kubernetes Operators • Declarativeapproach • Manages services “like a human” • Based on 
 Custom Resource Definitions
  • 34.
    Operator reconciliation drivingtowards desired state K8 Object Store kube controller etcd kube scheduler api server container Container Runtime image Kublet image container get wanted state get actual state take mitigation actions operator controllers workers … … control plane $ kubectl apply -f operator-crd.yaml
  • 35.
    MySQL NDB Clusterin Kubernetes Deployment Kubernete StatefulSet NDB Cluster Ndb operator backup / restore controller mysql controll NDB controller Data Node Data Node Data Node Data Node Mgm Node StatefulSet Mgm Node CRD
  • 36.
  • 37.
    Ndb Custom ResourceDefinition apiVersion: mysql.oracle.com/v1alpha1 kind: Ndb metadata: name: example-ndb spec: containerImage: mysql/mysql-cluster:8.0.22 nodecount: 2 redundancyLevel: 2 mysqld: nodecount: 2
  • 38.
    Thank You Bernd Ocklin SnrDirector MySQL Cluster Development