This repo contains code to set up and run a PostgreSQL database on Google Kubernetes Engine (GKE) using CloudNativePG.
!!!this repo is still a work in progress!!!
Structure of the cluster:
-
A single API gateway pod which accepts external requests
-
A postgreSQL database hosted on GKE
-
Using CloudNative-PG
-
Runs scheduled backups writing to cloud storage
-
Illustrates how to recover the database after a failure, or to a desired point in time
-
-
An auto-scaling flask app which performs basic CRUD operations on the database
gcloud auth login
gcloud config set project $GCP_PROJECT_ID
gcloud config set run/region $GCP_REGION
gcloud components install kubectl
# create cluster #
gcloud beta container \
--project $GCP_PROJECT_ID \
clusters create-auto \
"cloud-native-postgresql-cluster" \
--region $GCP_REGION
# get authentication credentials to interact with the cluster #
gcloud container clusters \
get-credentials \
"cloud-native-postgresql-cluster" \
--region $GCP_REGION \
--project $GCP_PROJECT_ID
# deploy CloudNative-PostGreSQL #
kubectl apply -f \
https://github.com/cloudnative-pg/cloudnative-pg/releases/download/v1.22.1/cnpg-1.22.1.yaml
# create a service account for the PostGreSQL operator #
export CN_POSTGRESQL_OPERATOR_SERV_ACCT_NAME="cloudnative-postgresql-operator"
gcloud iam service-accounts create $CN_POSTGRESQL_OPERATOR_SERV_ACCT_NAME \
--description="A service account for the Cloud-Native PostGreSQL operator on GKE"
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID
--member="serviceAccount:${CN_POSTGRESQL_OPERATOR_SERV_ACCT_NAME}@${GCP_PROJECT_ID}.iam.gserviceaccount.com"
--role="roles/storage.admin"
gcloud projects add-iam-policy-binding $GCP_PROJECT_ID
--member="serviceAccount:${CN_POSTGRESQL_OPERATOR_SERV_ACCT_NAME}@${GCP_PROJECT_ID}.iam.gserviceaccount.com"
--role="roles/iam.workloadIdentityUser"