Top Banner
Crunchy Data PostgreSQL Operator September 2017
33

Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Jul 28, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Crunchy DataPostgreSQL Operator

September 2017

Page 2: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Crunchy Data

Emphasis on Data Security and Compliance

PostgreSQL for Public, Private and Hybrid Cloud

Commitment to Community and Open Source

5

Page 3: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

3

What is an Operator?

Page 4: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Operator Basics

4

● Open Source - project at https://github.com/crunchydata/postgres-operator● Controller - an Operator is essentially a controller component you run on your Kubernetes or

OpenShift cluster● Automation - the Operator implements the necessary workflow orchestration logic to enable

the automation of PostgreSQL related tasks● Leverages the Kube API - the Operator is implemented in golang and leverages the Kubernetes

Client API heavily to look for events, update labels, create containers, etc. https://github.com/kubernetes/client-go

● Command Line Interface - the Operator has a Command Line Interface that lets users manipulate the Operator and define metadata used to catalog your PostgreSQL deployments

● Deployment - the Operator runs as a standard Deployment, it watches for Third Party Resources that we define to manage PostgreSQL deployments

● Third Party Resources - the operator makes use of Kubernetes Third Party Resources currently to store metadata about PostgreSQL deployments, this will change to using Kubernetes Custom Resource Definitions in future versions.

● Custom PostgreSQL Cluster Definitions - a template based approach for allowing users an ability to define the makeup of a PostgreSQL cluster rather than the current default

Page 5: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Operator Basics

5

Page 6: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Operator Basics

6

Page 7: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

7

Why?

Page 8: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Why Do I Need This?

8

• Automation - working with databases requires different workflows that involve multiple steps and verifications, the Operator allows for automating those sort of workflows in a consistent way and can reduce human errors; working with large numbers of complex database deployments can get time consuming without some sort of automation

• Standard Practices - advanced users will want to have a standard set of database objects created so the ability to categorize databases with metadata and also build/apply SQL policies for them is useful to support a set of standards

• Ease of Use - a simple CLI that is focused solely on deploying and managing a set of PostgreSQL clusters enables users to focus on getting real work done instead of having to build their own set of scripts or adjust to learning the details of kubectl commands

• Large Scale Deployments - the Operator supports environments where you might have possibly hundreds of PostgreSQL clusters and being able to query these assets in a managed way is useful

• Complex Orchestrations - the Operator provides a means of developing advanced database orchestration logic using a standards-based approach

Page 9: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

9

Building Blocks

Page 10: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Building Blocks

10

• https://github.com/crunchydata/crunchy-containers/• crunchy-postgres• crunchy-proxy• crunchy-backup• crunchy-upgrade

Page 11: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

11

Installation

Page 12: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Installation

12

● https://github.com/CrunchyData/postgres-operator/blob/master/docs/build.asciidoc● Requirements

○ Kubernetes 1.5.3+○ OpenShift Origin 1.5.1+ and OpenShift Container Platform 3.5○ PostgreSQL 9.5+ Container (crunchy-postgres)○ PostgreSQL Backup Container (crunchy-backup)○ PostgreSQL Upgrade Container (crunchy-upgrade)

● Building the project● Get packaged dependencies/build from source● Bash completion● View operator resources

○ kubectl get thirdpartyresources○ kubectl get pgclusters○ kubectl get pgbackups○ kubectl get pgupgrades○ kubectl get pgpolicies○ kubectl get pgclones

Page 13: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Installing Kubernetes

13

• https://gist.github.com/xenophenes/05552cadbba42c6abcc039aad7273e60 ○ (https://goo.gl/22fopq)

• Minikube○ minikube addons disable default-storageclass

Page 14: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

14

Features

Page 15: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Create a Database Cluster

15

The most basic function of the Operator is to let a user create a new Database “Cluster”. Here Cluster refers to a set of resources (services, Deployments, Pods, etc.)

Page 16: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Test a Database

16

You can test the database cluster with a simple test as follows:

Page 17: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Delete a Database Cluster

17

You can delete the set of Database Cluster resources by name as follows:

Page 18: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Backup a Database

18

You can execute a backup job, jobs can run for a very long time so the Operator is able to watch for their completion using the Kubernetes Watch API, when complete the Operator is notified:

Page 19: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Show Backup PVCs

19

This displays the contents of a PVC (pgo show pvc) - not just the backup pvc as displayed here. This is the equivalent of the kubectl get pvc command.

Page 20: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Restore from Backup

20

Create a restored database cluster from a previous backup using passed in variables to define the backup pvcs.

Page 21: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Show Restored Cluster

21

Display information about the cluster we just restored; verify everything looks OK.

Page 22: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Scale a Database

22

You can scale up the number of read-only replicas as follows:

Page 23: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Perform a Minor Database Upgrade

23

You can upgrade to a new minor release as follows:

Page 24: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Perform a Major Database Upgrade

24

You can upgrade to a new major release as follows:

Page 25: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Create a Database Policy

25

You can define a set of SQL statements which we call a Policy:

Page 26: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Apply a Database Policy

26

You can apply a Policy against a set of databases as follows:

Page 27: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Create Policy from GitHub

27

You can define a set of SQL statements which we call a Policy and import the file from GitHub:

Page 28: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Clone Database

28

Clone an existing PostgreSQL cluster, waits for the replica to complete replication, decouples the replica from the master by triggering a recovery and re-labeling the replica to become a fully functioning master, becomes a fully functioning master, creates a service for the new master and an empty replica deployment.

Page 29: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Multiple Clusters

29

Command line parameters can be passed in with multiple values, and all clusters can be viewed.

Page 30: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

.pgo.yaml

30

Configuration YAML file for the postgres-operator.

https://github.com/CrunchyData/postgres-operator/blob/master/docs/config.asciidoc

https://kubernetes.io/docs/concepts/storage/persistent-volumes/

https://kubernetes.io/docs/concepts/storage/volumes/

Page 31: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

Strategies (Resources)

31

● https://github.com/CrunchyData/postgres-operator/blob/master/docs/design.asciidoc

● https://github.com/CrunchyData/postgres-operator/tree/master/conf/postgres-operator/cluster/1

● https://github.com/CrunchyData/postgres-operator/blob/master/examples/pgo.yaml.emptydir

● https://github.com/CrunchyData/postgres-operator/blob/master/docs/config.asciidoc

Page 32: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

32

Summary

Page 33: Crunchy Data PostgreSQL Operator · 2017-09-07 · PostgreSQL 9.5+ Container (crunchy-postgres) PostgreSQL Backup Container (crunchy-backup) PostgreSQL Upgrade Container (crunchy-upgrade)

33

THANK YOU!

Learn more: • https://www.youtube.com/watch?v=HX10WWTRiTY• https://github.com/CrunchyData/postgres-operator• https://www.crunchydata.com/

Slides are available at:• https://www.sarahconway.com/slides/postgres-operator.pdf

Sarah Conway: [email protected] McCormick: [email protected]