Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We...

23
Postgresql in Kubernetes Armin Nesiren www.cybertec-postgresql.com

Transcript of Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We...

Page 1: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Postgresql in Kubernetes

Armin Nesirenwww.cybertec-postgresql.com

Page 2: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Armin Nesirenwww.cybertec-postgresql.com

Page 3: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

About me

I Armin NesirenI DeveloperI 10 years as DBAI DevopsI Lately dealing with Kubernetes in production

Armin Nesirenwww.cybertec-postgresql.com

Page 4: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Motivation

I Service oriented aritecture - SOAI Future of kubernetesI Test it home, it’s freeI Postgresql available for everyone, quickly

Armin Nesirenwww.cybertec-postgresql.com

Page 5: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

What I will talk about

I Kubernetes basics

I Kubernetes storage

I Deploying PostgreSQL inside kubernetes simple way

I Deploying PostgreSQL automated

Armin Nesirenwww.cybertec-postgresql.com

Page 6: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Kubernetes basics

I Containers generallyI We like containers because: lightweight, standalone, on any

envI Resource efficiennt

I K8s is dealing with containersI Written in GolangI scaling, loadbalancing

Armin Nesirenwww.cybertec-postgresql.com

Page 7: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Bare betal vs Cloud provides

Figure 1: k8s providers

I Bare metal:I as low as 3-5 nodesI needs to take care of persistent storageI exposing of services

Armin Nesirenwww.cybertec-postgresql.com

Page 8: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

K8s simple arhitecture

Figure 2: Kubernetes simple

Armin Nesirenwww.cybertec-postgresql.com

Page 9: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Software distributed storage

Figure 3: rook and ceph architecture

Armin Nesirenwww.cybertec-postgresql.com

Page 10: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Kubernetes resources wise

I Concept of podsI Group of one or more containersI shared storage/networkI always co-located and co-sheduled

I namespacesI virtual cluster inside of a cluster

I secretsI storing sensitive information

I Deployment of podsI describing desired state of a pod

I ServicesI ClusterIP, NodePort, LoadBalancer, ExternalName

Armin Nesirenwww.cybertec-postgresql.com

Page 11: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

How to talk to k8s

I kubectlI command line

I YamlI Client library

I Go, Python, Java, dotnet, JavaScript and more

Armin Nesirenwww.cybertec-postgresql.com

Page 12: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Yaml example

Figure 4: yaml example

Armin Nesirenwww.cybertec-postgresql.com

Page 13: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

What if we have. . . (Spilo)

I All supported PostgreSQL versions inside one imageI Plenty of extensions (pg_partman, pg_cron, postgis. . . )I Aditional tools (pgq, pgbouncer, wal-e/wal-g)I PGDATA on external volumeI Environment-variables based configurationI Light! ~120MB

Armin Nesirenwww.cybertec-postgresql.com

Page 14: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

And than we also need. . . Patroni

I Automatic failover solution for streaming replicationI A python daemon that manages one PostgreSQL instanceI Keeps the cluster state in DCS (etcd, Zookeeper, Consul)

I Uses DCS for leader electionsI Helps automate things like:

I New cluster deploymentI Scaling out and inI Postgresql configuration management

Armin Nesirenwww.cybertec-postgresql.com

Page 15: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Spilo & Patroni together

Armin Nesirenwww.cybertec-postgresql.com

Page 16: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Simple deployment of Postgresql

I Long YAMLI Hard to configureI Not easy to manipulate with clusters (update, delete. . . )I Manual generation of DB objects after setup

Armin Nesirenwww.cybertec-postgresql.com

Page 17: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Why not helm

I Templated manifests

I Requres spetial pod (tiller) in your cluster

I Only one place for configuration

I Still problem with cluster update

Armin Nesirenwww.cybertec-postgresql.com

Page 18: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Postgresql typical lifecycle

Armin Nesirenwww.cybertec-postgresql.com

Page 19: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Kubernetes operator

I Encapsulates knoweledge of a human operating the serviceI Fully automated: deployments, cluster upgrdes, user

management

Armin Nesirenwww.cybertec-postgresql.com

Page 20: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Zalando Postgresql-Operator

I Defines CDR (Postgresql)I Watches instances, creates/updates/deletesI Create DB objects, roles, passwords. . .I Allows updating of resources (memory, cpu, volumes),

postgresql configurationI Auto-repairs, smart rolling updates

Armin Nesirenwww.cybertec-postgresql.com

Page 21: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Postgresql Manifest

Armin Nesirenwww.cybertec-postgresql.com

Page 22: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

Final operator chart

Armin Nesirenwww.cybertec-postgresql.com

Page 23: Postgresql in Kubernetes - Postgres Conference · Kubernetes basics I Containers generally I We like containers because: lightweight, standalone, on any env I Resource efficiennt

End

THANK YOU

Armin Nesirenwww.cybertec-postgresql.com