27
Galera on Kubernetes Running sychronous MySQL replication on Kubernetes Patrick Galbraith, ATG April 2016

Galera on Kubernetes - percona.com

  • Upload
    lyminh

  • View
    255

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Galera on Kubernetes - percona.com

Galera on KubernetesRunning sychronous MySQL replication on Kubernetes

Patrick Galbraith, ATGApril 2016

Page 2: Galera on Kubernetes - percona.com

HPE ATG

HPE's (HP Enterprise) Advanced Technology Group for Open Source and Cloud embraces a vision that is two steps ahead of today's solutions. We use this vision to drive product adoption and incubate technologies to advance HPE. Through Open Source initiatives we foster collaboration across HPE and beyond.

2

Page 3: Galera on Kubernetes - percona.com

3

About the speaker

● Patrick Galbraith

● HP Advanced Technology Group

● Has worked at Blue Gecko, MySQL AB, Classmates, Slashdot, Cobalt Group, US Navy, K-mart

● MySQL projects: memcached UDFs, DBD::mysql, federated storage engine

● Family

● Outdoors

Page 4: Galera on Kubernetes - percona.com

Purpose of this talk – why are you here?

4

• Docker

• Containers vs. Virtualization

• Simple Docker usage

• Clustered Docker

• Kubernetes

• Understand what Kubernetes is

• Using Kubernetes to do work, in this case what it means to

MySQL users

• Galera

• Synchronous replication – excellent solution to clustering

MySQL

Page 5: Galera on Kubernetes - percona.com

What are containers?

5

• Operating-system-level isolation

• Encapsulated, hermetically sealed applications

• Portable. And did I mention, portable?!

• Small footprint of container images

• Fast to launch!

• Use of host OS and Kernel

• Execution consists of time to startup application in question

• LXC, Docker, Solaris Zones, BSD Jails, Parallels Virtuozzo,

OpenVZ, …

Page 6: Galera on Kubernetes - percona.com

VM vs. Containers

Server

Host OS

Hypervisor

Gues

t OS

Gues

t OS

Gues

t OS

Bins/

Libs

Bins/

Libs

Mysql

Bins/

Libs

Mysql App

Server

Host OS

Bins/LibsBins/Libs

M

y

s

q

l

M

y

s

q

l

A

p

p

A

p

p

A

p

p

M

y

s

q

l D

o

c

k

e

r

VM Containers

Page 7: Galera on Kubernetes - percona.com

What is Docker?

7

• Set of tools for managing containers

• Command line tool that doubles as a 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

(CPU, memory, disk I/O, etc.) of process groups

• Originally used lxc, now defaults to Libcontainer but meant for any containerization mechanism

• Much more light weight than VMs

• Encapsulated application containers in a relatively isolated but lightweight operating environment

• Written in Go

Page 8: Galera on Kubernetes - percona.com

Docker – common terms and usage

8

• Dockerfile

• EXPOSE ports

• Entrypoints and CMD• docker build

• docker push

• docker run

• docker inspect

• docker exec

• docker commit

Page 9: Galera on Kubernetes - percona.com

Dockerfile

9

• https://github.com/CaptTofu/percona_xtradb_cluster_docker

Page 10: Galera on Kubernetes - percona.com

Running a docker container

10

$ docker run \

--name mybox \

-e MYSQL_ROOT_PASSWORD=secret \

-d \

mysql/mysql-server --log-bin --server-id=100$

$ cat minimal.cnf

[mysqld]

user=mysql

log-bin=mysql-bin

server-id=100

$ docker run \

--name mybox \

-e MYSQL_ROOT_PASSWORD=secret \

-d --hostname mybox \

-v $PWD/minimal.cnf:/etc/my.cnf

mysql/mysql-server

Page 11: Galera on Kubernetes - percona.com

Clustered Docker

11

• Kubernetes -- http://kubernetes.io

• CoreOS -- https://coreos.com/

• Mesos + Marathon -- http://mesos.apache.org/ Apache project, Zookeeper, etc

• Project Atomic -- http://www.projectatomic.io/-- RH/Fedora/Centos designed for running

• Docker Openstack -- https://wiki.openstack.org/wiki/Docker Hypervisor Driver for Openstack

• Swarm/Compose/Machine

• RancherOS http://rancher.com/rancher-os Minimalist Linux, Docker daemon runs as PID 1 first process the kernel starts known as “System

• Flocker -- https://clusterhq.com

• Spotify Helios -- https://github.com/spotify/helios -- Zookeeper

• Deis (http://deis.io)

• Maestro (https://github.com/toscanini/maestro)

• Shipyard (http://shipyard-project.com)

• … others to come!

Page 12: Galera on Kubernetes - percona.com

Kubernetes

12

• “An open source system for managing containerized applications across multiple hosts, providing basic mechanisms for deployme

• Lean

• Portable – will run cloud, bare metal, hybrid, etc

• Extensible – using modular design allowing for plug-ability and hooks

• Self-healing – auto-placement, auto-restart, auto-replication

• Google engineering bring good work to the Open-source world

Page 13: Galera on Kubernetes - percona.com

Kubernetes concepts

13

• Pod

• Group of closely-related containers on the same host

• Service

• Virtual abstraction

• Basic load-balancer

• Single consistent access point to a pod

• Replication controller

• Defines pods to be horizontally scaled

• Uses a label query for identifying what containers to run

• Maintains specified number of replicas of a particular thing to run

• Dynamic resizing

• Label

• Key/value tag to mark work units a part of group

• Management and action targeting

• Definition file – YAML/json describing a pod, service, or replication controller

Page 14: Galera on Kubernetes - percona.com

Kubernetes pod

14

Page 15: Galera on Kubernetes - percona.com

Kubernetes Master

15

• kube-apiserver – API Server (RESTful)

• primary management for cluster

• reconciles etcd entries with deployed containers• kube-controllermanager — Controller Manager Server

• Handle replication precesses defined by replication tasks

• Writes details to etcd

• Monitors changes and implements procedure to reflect the

change• kube-scheduler -- Scheduler Server

• Assigns workloads to specific minions in cluster taking into

account service’s operating requirements and infrastructure

environment • kube-register -- Register Server

Page 16: Galera on Kubernetes - percona.com

Kubernetes minion

16

• kubelet

• Communicates with the master, relaying information to/from

• Reads and updates etcd

• Receives work in a manifest that defines the workload and operating

parameters.

• Assumes responsibility for the state of work on minion• kube-proxy

• Ensures network environment is accessible but isolated.

• Makes services available externally by forwarding requests to containers.

• Can perform rudimentary load balancing.

Page 17: Galera on Kubernetes - percona.com

Kubernetes Basic Setup

17

Page 18: Galera on Kubernetes - percona.com

Kubernetes diagram

18

Page 19: Galera on Kubernetes - percona.com

Kubernetes usage

19

• Pod configuration file – YAML or JSON

• Service configuration file

• Replication controller configuration file

• export KUBERNETES_API=http://kube-master:8080

• kubectl create –f mysql_master.json

• kubectl create –f mysql_master_service.json

• …

Page 20: Galera on Kubernetes - percona.com

How can I run Kubernetes?

20

• https://github.com/CaptTofu/vagrant-kubernetes-cluster.git

• https://github.com/Samsung-AG/kraken.git

• http://kubernetes.io/docs/hellonode/

• https://github.com/pires/kubernetes-vagrant-coreos-cluster

• https://github.com/TheNewNormal/kube-solo-osx

Page 21: Galera on Kubernetes - percona.com

Other deployment Strategies for Kubernetes

21

• Helm -- http://helm.sh/ -- Package Manager for k8s

• Deis v2 – Builds, deploys, 12-factor PaaS

• Kupak

• RedSpread

• KPM

Page 22: Galera on Kubernetes - percona.com

Galera Replication on Kubernetes

22

• One pod per node (pxc_node1, pxc_node2, and pxc_node03)

• Utilizes SkyDNS

• Single container per pod

• Secret sauce

• The pod configuration file passes environment variables to set root password, sst user and password

• Entrypoint script:

• wsrep cluster address on pxc_node1 set to gcomm://

• pxc_node2 set to gcomm://pxc_node1

• pxc_node3 set to gcomm://pxc_node1,pxc_node2

Page 23: Galera on Kubernetes - percona.com

Galera replication on Kubernetes

23

https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-galera

Page 24: Galera on Kubernetes - percona.com

Galera on Kubernetes

24

Page 25: Galera on Kubernetes - percona.com

Galera on Kubernetes Process

25

minion minion minion

Api server

pxc_node1pod

pxc_node2pod

pxc_node3pod

pxc container pxc container pxc container

pxc_node1 service

pxc_node2 service

pxc_node3 service

pxc_cluster service

pxc_node1 pod and

service file

pxc_node2pod and

service file

pxc_node3pod and

service file

kubectl

pxc_clusterService file

Page 26: Galera on Kubernetes - percona.com

Demo

26

Page 27: Galera on Kubernetes - percona.com

Demo: set up Kubernetes with Ansible

27