Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active May 22, 2022 12:57
Show Gist options
  • Select an option

  • Save nicerobot/fef144c9328b487e85f7a6ccbd5f70bc to your computer and use it in GitHub Desktop.

Select an option

Save nicerobot/fef144c9328b487e85f7a6ccbd5f70bc to your computer and use it in GitHub Desktop.
PostgreSQL Kubernetes Service

Create the Kubernetes service

curl -s https://gist.githubusercontent.com/nicerobot/fef144c9328b487e85f7a6ccbd5f70bc/raw/kubectl | bash -s -- apply

Run psql

bash -i <(curl -s https://gist.githubusercontent.com/nicerobot/fef144c9328b487e85f7a6ccbd5f70bc/raw/psql)

Remove the Kubernetes service

curl -s https://gist.githubusercontent.com/nicerobot/fef144c9328b487e85f7a6ccbd5f70bc/raw/kubectl | bash -s -- delete
#!/usr/bin/env bash
kubectl ${1:-apply} -f https://gist.githubusercontent.com/nicerobot/fef144c9328b487e85f7a6ccbd5f70bc/raw/postgres.yml
apiVersion: v1
kind: Service
metadata:
name: db
labels:
app: db
spec:
type: NodePort
ports:
- port: 5432
targetPort: 5432
name: db
selector:
app: db
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: db
labels:
app: db
spec:
template:
metadata:
labels:
app: db
spec:
containers:
- name: db
image: postgres:10
ports:
- containerPort: 5432
name: db
#!/usr/bin/env bash
PGDATABASE=postgres
PGHOST=host.docker.internal
PGPASSWORD=postgres
PGPORT=$(kubectl get svc db -o jsonpath="{.spec.ports[0].nodePort}")
PGUSER=postgres
docker run --rm -it postgres:10 psql -h ${PGHOST} -p ${PGPORT} ${PGDATABASE} ${PGUSER}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment