gMemegen

CircleCI

gMemegen is a sample application, showcasing Cloud SQL Postgres connectivity from a Kubernetes cluster running on Google Kubernetes Engine.

Deployment

You can find the complete instructions (including resource setup) in the form a codelab, located here.

The app attempts a connection to a postgres server located at 127.0.0.1 unless otherwise specificed. For a full list of available flags, use python app/main.py -help.

Local deployment

Install the requirements (inside a virtualenv)

pip install -r app/requirements.txt

With cloud_sql_proxy running, start the application on the debug server:

python app/main.py --DB_USER <db_user> --DB_PASS <db_pass>

Verify the app is running by navigating to http://127.0.0.1:5000.

Use Ctrl+C to stop the application at any time.

Local deployment inside Docker:

Build the docker with:

docker build -t gmemegen .

With cloud_sql_proxy running, start the container:

docker run  --net="host" -it --rm --name runtime -e "DB_PASS=1qaz2wsx" gmemegen

Verify the app is running by navigating to http://127.0.0.1:5000.

Use Ctrl+C to stop the application at any time.

Kubernetes Deployment

Create a kubernetes secret named cloudsql-instance-credentials from your service account key:

kubectl create secret generic cloudsql-instance-credentials \
    --from-file=credentials.json=service_account_key.json

Create a kubernetes secret named cloudsql-db-credentials from your database credentials key:

kubectl create secret generic cloudsql-db-credentials \
    --from-literal=username=[DB_USER] \
    --from-literal=password=[DB_PASS]

Update the gmemegen_deployment.yaml by replacing variables in the following sections:

Create your deployment on your cluster:

kubectl create -f gmemegen_deployment.yaml

To access your deployment via the web, expose it with a LoadBalancer object:

kubectl expose deployment gmemegen --type "LoadBalancer" --port 80 --target-port 8080

After 2-3 minutes, describe the service to find the "LoadBalancer Ingress".

kubectl describe services gmemegen

Your service should be ready at http://[LoadBalancer Ingress]:80. Navigate to your URL and make some memes!

Disclaimer

This is not an official Google product.