Upload
doannga
View
240
Download
4
Embed Size (px)
Citation preview
Containerizing PostgreSQL and Making it Cloud Native Ready
August 25, 2016
Jeff McCormick
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
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
Why Containers for PostgreSQL?
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?
Design Goals
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
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
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
DBaaS Features
11
NFS
PostgreSQL
Container
Restored
PostgreSQL
Container
Backup
Container
Backup and Restore
12
PostgreSQL
Master
Container
PostgreSQL
Slave
Container
pgPool
Container
Watch
Container
High Availability
13
Data
Store
Kubernetes Pod
PostgreSQL
Container
Collection
ContainerGrafana
Container
Prometheus
Container
Gateway
Container
Database Monitoring
14
creates
creates Vacuum
JobVacuum
Job
Backup
JobBackup
Job
PostgreSQL
Container
DBA
Container
(cron)
DBA Utility Microservices
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
Orchestration
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?
18
Swarm Deployment
19
Kubernetes Deployment
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
21
ADVANCED EXAMPLE
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
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
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
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
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
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
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
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
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
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
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
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
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
35
Kitchensink Example
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