This repo has support code for a Virtual Office Hours demo given at the 2022 Kubecon Valencia, on 2022-05-18 by me (Jaime).
Contains:
- Liquibase config and initial migration
- Webapp in Go
- Makefile and cheat-sheet (to aid this poor typist)
- Dockerfile and K8s YAML's for the webapp
Assumed to be installed on demo machine:
- KinD cluster
- CloudNativePG operator
- Liquibase
Uses the cluster-example.yaml
sample in docs/src/samples
.
The purpose of the demo is to show CloudNativePG is a great tool to develop web applications on dev machines, and opens up possibilities to do all sorts of things before putting in prod.
We try to show a viable workflow using Liquibase for schema migrations,
and a webapp written in Go using only the standard
net/http
, database/sql
and lib/pq
packages.
Two halves to the demo:
-
"Average" or "old-style" approach: postgres installed locally, possibly even dockerized. Webapp developed locally, executed natively or dockerized. We ape this by installing a 1-pod cluster using the
cluster-example.yaml
sample with 1 replica instead of 3. We run the webapp outside of KinD and hitlocalhost:5432
from it. -
Better way: we dockerize the webapp, push to the KinD nodes, create a deployment and a service for it. We hit the
cluster-example-rw
service. We show the possibilities that open up.
Show diagram for "Case 2" from the cnpg docs
- Basic web application written in Go (aka golang)
- Kubernetes cluster (in this case KinD running on macOS)
- The CloudNativePG operator installed on KinD
- Schema migration tool: Liquibase
- Create the simplest CloudNativePG cluster
- Start with an empty PostgreSQL DB
- Get DB connection credentials
- Apply migrations with Liquibase - comment on Postgres's Transactional DDL
- Add port forwarding to expose DB (necessary if running KinD on macOS)
- Start the webapp natively
Show first diagram for "Case 1" from the cnpg docs
Take opportunity to show the web page for cnpg and the documentation link.
- Let’s Dockerize our webapp and load it into our KinD cluster
- Make a deployment and a loadBalancer for our webapp
- The webapp should now hit the -rw (cluster-example-rw) Service
- Let’s scale our CloudNativePG cluster to 3 instances
- Close the running webapp
- Deploy the webapp (show Dockerfile and K8s YAML while cluster scales up)
- Let’s add a watch on the cluster. Let’s put some load on it
- Let’s kill the primary!!
- (with enough time) - Have a look around in the
cloudnative-pg
repo
Talk about how once we start leveraging CloudNativePG, we enable developers to do experiments that require DBA skills. And we allow them to develop locally with a DB much more similar to what production will look like. When they deal with prod issues on their app, those developers will have gained hands-on experience already.
And bridging the gap between dev and prod is one of the tenets of the DevOps movement.