Post on 22-May-2020
Postgresql in Kubernetes
Armin Nesirenwww.cybertec-postgresql.com
Armin Nesirenwww.cybertec-postgresql.com
About me
I Armin NesirenI DeveloperI 10 years as DBAI DevopsI Lately dealing with Kubernetes in production
Armin Nesirenwww.cybertec-postgresql.com
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
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
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
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
K8s simple arhitecture
Figure 2: Kubernetes simple
Armin Nesirenwww.cybertec-postgresql.com
Software distributed storage
Figure 3: rook and ceph architecture
Armin Nesirenwww.cybertec-postgresql.com
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
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
Yaml example
Figure 4: yaml example
Armin Nesirenwww.cybertec-postgresql.com
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
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
Spilo & Patroni together
Armin Nesirenwww.cybertec-postgresql.com
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
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
Postgresql typical lifecycle
Armin Nesirenwww.cybertec-postgresql.com
Kubernetes operator
I Encapsulates knoweledge of a human operating the serviceI Fully automated: deployments, cluster upgrdes, user
management
Armin Nesirenwww.cybertec-postgresql.com
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
Postgresql Manifest
Armin Nesirenwww.cybertec-postgresql.com
Final operator chart
Armin Nesirenwww.cybertec-postgresql.com
End
THANK YOU
Armin Nesirenwww.cybertec-postgresql.com