containerizing postgresql and making it cloud native...

37
Containerizing PostgreSQL and Making it Cloud Native Ready August 25, 2016 Jeff McCormick

Upload: doannga

Post on 06-Feb-2018

238 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

Containerizing PostgreSQL and Making it Cloud Native Ready

August 25, 2016

Jeff McCormick

Page 2: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

About Crunchy Data…

Leading provider of trusted open source PostgreSQL

and PostgreSQL related technologies, support and

training to enterprises.

2

Powering Innovation With The World’s Most

Advanced Open Source Database

Page 3: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

Crunchy Certified PostgreSQL

Crunchy’s trusted distribution of 100% Open Source PostgreSQL including:

100% Open Source PostgreSQL 9.5

Support for Containers and Cloud-Native Environments

Enhanced Multi-Level Security and Audit Capability

Support for Geo-Spatial and JSON Data Types

First commercially available 100% Open Source RDBMS to receive Common Criteria certification.

3

Page 4: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

Why Containers for PostgreSQL?

Page 5: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

5

• Encapsulates complexities of databases into a uniform package

• Provides for a separation of concerns (backup, database, admin, etc.)

• Relatively lightweight, provides for high density deployments

• Supports a cloud-based model of deployment

• Micro instead of Macro services

• Implemented using Docker technology, wide adoption

Why Containers for PostgreSQL?

Page 6: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

Design Goals

Page 7: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

7

• Crunchy images are built on Centos7 or RHEL7 base images,

functionally equivalent

• Docker-style Deployment - standalone Docker deployment, would use

Docker networking and Docker Swarm to provide multi-host capabilities

• Kubernetes-style Deployment - deploys to Kubernetes single-node or

multi-node cluster, leverages Kubernetes persistence

• OpenShift-style Deployment - deploys to OpenShift single-node or

multi-node cluster, leverages Kubernetes persistence plus other Red

Hat added features

• Local mounted volumes or Docker volumes

Deployment Options

Page 8: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

8

• Custom setup.sql can be used to implement any SQL statements you

want when a new PostgreSQL container is created

• Custom pg_hba.conf and postgresql.conf files can be used to provide a

custom behavior

• /pgconf can be mounted from a networked file location to provide a

common location of setup.sql, pg_hba.conf, and postgresql.conf

• Common PostgreSQL settings can be set using environment variables

• Build your own image using the Dockerfile, for example, your own

contrib modules or remove unnecessary packages (e.g. PostGIS)

Customizing Your PostgreSQL Containers

Page 9: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

9

• Clustering - runs as a master or as a replica

• Replication - allows for either sync or async replication

• Predefined objects - defines some example objects in setup.sql upon initialization

• Locale support - allows you to specify a locale to use

• Secrets support - in Kube, you can use secrets for user id and password storage

• Config override - pg_hba.conf, postgresql.conf, setup.sql can be overridden with your own

custom versions

• Random UID - allows you to use a random UID for the postgres user (Kube, OpenShift)

• Restore - allows you to restore using a predefined backup archive

PostgreSQL Container Design Features

Page 10: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

DBaaS Features

Page 11: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

11

NFS

PostgreSQL

Container

Restored

PostgreSQL

Container

Backup

Container

Backup and Restore

Page 12: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

12

PostgreSQL

Master

Container

PostgreSQL

Slave

Container

pgPool

Container

Watch

Container

High Availability

Page 13: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

13

Data

Store

Kubernetes Pod

PostgreSQL

Container

Collection

ContainerGrafana

Container

Prometheus

Container

Gateway

Container

Database Monitoring

Page 14: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

14

creates

creates Vacuum

JobVacuum

Job

Backup

JobBackup

Job

PostgreSQL

Container

DBA

Container

(cron)

DBA Utility Microservices

Page 15: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

15

• crunchy-pg - runs PostgreSQL and also performs a backup restore

• crunchy-backup - performs a pg_basebackup on a database container

• crunchy-pgbadger - hosts a simple http server that executes pgbadger against a database

container to produce HTML reports that provide detailed PostgreSQL log analysis

• crunchy-pgpool - provides a pgpool container that lets applications access a PostgreSQL

cluster via a single connection

• crunchy-watch - provides a form of automated failover by watching a PostgreSQL cluster’s

master and triggers a failover on a slave if the master is not responding

• crunchy-collect - collects 30+ different PostgreSQL metrics from a database container and

pushed them to a Prometheus time series data store

• crunchy-grafana - provides a web based graphing dashboard for collected PostgreSQL metrics

• crunchy-prometheus - provides a Prometheus datastore for metrics collection

• crunchy-vacuum - provides a container that performs a Postgres vacuum

• crunchy-dba - provides a cron scheduler for scheduling backups and vacuum jobs

• crunchy-pgadmin4 – provides a web console for Postgres databases

DBaaS Example: Crunchy Container Suite

Page 16: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

Orchestration

Page 17: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

17

• Requires advanced lower-level frameworks to work at scale

• Dynamic provisioning of networking and storage

• Networking, service discovery

• https://docs.docker.com/engine/userguide/networking/get-started-overlay/

• http://kubernetes.io/docs/admin/networking/

• Multiple hosts for scaling and high availability

• Provides deployment abstractions around simple containers such as services and

pods

• Provides scaling features such as ReplicationController

• Examples include Docker, Docker Swarm, Kubernetes, custom, OpenShift,

others…

• Crunchy containers currently tested on Kube 1.2.4, OSE 3.2, Docker 1.10,

Portworx (beta)

What About Orchestrating Containers?

Page 18: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

18

Swarm Deployment

Page 19: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

19

Kubernetes Deployment

Page 20: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

20

Local disk is faster than networked disk but servers can crash...

Docker volume drivers (e.g. Portworx) allow for features like replication

https://docs.docker.com/engine/extend/plugins_volume/

Docker containers CPU performance mirrors closely the performance of

bare metal

http://domino.research.ibm.com/library/cyberdig.nsf/papers/0929052195

DD819C85257D2300681E7B/$File/rc25482.pdf

PostgreSQL master on local disk, replica(s) on local and network disk is

one deployment option, best of both worlds?

Disk storage choices (Ceph, Gluster, local disk, shared, not-shared,

EBS, latency, consistency, throughput)

Performance Considerations

Page 21: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

21

ADVANCED EXAMPLE

Page 22: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

22

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 23: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

23

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 24: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

24

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 25: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

25

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 26: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

26

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 27: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

27

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 28: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

28

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 29: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

29

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 30: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

30

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 31: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

31

Master pod

Postgres

master

container

Metrics

Collector

container

Pgbadger

container

Replica DC Sync Replica Pod

Postgres

sync replica

container

replica

service

Master

service

pgpool DC

pgpool

service

watch pod

watch

containerprometheus

Postgres slave

container

Postgres

replica

container

pgpool

container

pgpool

containerApplications

Kitchensink Example

Page 32: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

32

kubectl create -f $LOC/kitchensink-master-service.json

kubectl create -f $LOC/kitchensink-slave-service.json

kubectl create -f $LOC/kitchensink-pgpool-service.json

envsubst < $LOC/kitchensink-sync-slave-pv.json | kubectl create -f -

envsubst < $LOC/kitchensink-master-pv.json | kubectl create -f -

kubectl create -f $LOC/kitchensink-sync-slave-pvc.json

kubectl create -f $LOC/kitchensink-master-pvc.json

envsubst < $LOC/kitchensink-master-pod.json | kubectl create -f -

envsubst < $LOC/kitchensink-slave-dc.json | kubectl create -f -

envsubst < $LOC/kitchensink-sync-slave-pod.json | kubectl create -f -

envsubst < $LOC/kitchensink-pgpool-rc.json | kubectl create -f -

kubectl create -f $LOC/kitchensink-watch-sa.json

envsubst < $LOC/kitchensink-watch-pod.json | kubectl create -f -

A developer deploys the example to Kubernetes using the kubectl command,. Each deployed component (service,

pod, Deployment, ReplicationController) is defined in a JSON template.

Kitchensink (OpenShift) Example

Page 33: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

33

},

"spec": {

"securityContext": {

"fsGroup": 26

},

"containers": [{

"name": "pg-badger",

"image": "172.30.240.45:5000/jeff-project/crunchy-pgbadger:${CCP_IMAGE_TAG}",

"imagePullPolicy": "Always",

"ports": [{

"containerPort": 15000,

"protocol": "TCP"

}],

"env": [],

"securityContext": {

"

A developer constructs the JSON to indicate what container image to deploy as well as configuration parameters that get

referenced when the container is deployed.

Kitchensink Example

Page 34: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

34

https://github.com/crunchydata/crunchy-containers/examples/kube/kitchensink

The complete example for Kubernetes is found in our examples/kube directory on github, other examples of running

the containers in Openshift and standalone Docker environments are also included.

Kitchensink Example

Page 35: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

35

Kitchensink Example

Page 36: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

Summary• Crunchy PostgreSQL Container Suite is just one example of a DBaaS

• Networking and storage are particularly difficult in a deployment

which places a premium on what platform you deploy on

• Database monitoring and administration need to scale along with

database deployment

• Open source databases like PostgreSQL make deploying a DBaaS

easier than closed source models

• One size does not fit all….places a premium on configuration design

36

Page 37: Containerizing PostgreSQL and Making it Cloud Native …schd.ws/hosted_files/cnd2016/8d/Containerizing PostgreSQL and... · Containerizing PostgreSQL and Making it Cloud Native Ready

37

THANK YOU!WWW.CRUNCHYDATA.COM

[email protected]://GITHUB.COM/CRUNCHYDATA/CRUNCHY-CONTAINERS