Skip to content

PostgreSQL database hosted on Google Kubernetes Engine using CloudNative-PG

Notifications You must be signed in to change notification settings

J-sephB-lt-n/postgresql-k8s-gke

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

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:

  1. A single API gateway pod which accepts external requests

  2. 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

  3. 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"

References

About

PostgreSQL database hosted on Google Kubernetes Engine using CloudNative-PG

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published