Skip to content

Instantly share code, notes, and snippets.

@paranlee
Forked from nicerobot/README.md
Last active May 22, 2022 14:27
Show Gist options
  • Select an option

  • Save paranlee/e77ddbb0f6d2ed0ce45bfe7cfb288cdd to your computer and use it in GitHub Desktop.

Select an option

Save paranlee/e77ddbb0f6d2ed0ce45bfe7cfb288cdd to your computer and use it in GitHub Desktop.
PostgreSQL Kubernetes Service

Create the Kubernetes service

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

Run psql

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

Remove the Kubernetes service

curl -s https://gist.githubusercontent.com/nicerobot/e77ddbb0f6d2ed0ce45bfe7cfb288cdd/raw/kubectl | bash -s -- delete
FROM postgres:14.3
RUN apt-get update -y \
&& apt-get install -y \
tzdata \
locales \
locales-all \
postgresql-14-postgis-3 \
postgresql-14-postgis-3-scripts \
vim \
python3 \
&& rm -rf /var/lib/apt/lists/*
RUN localedef -i ko_KR -f UTF-8 ko_KR.UTF-8
ENV TZ 'Asia/Seoul'
ENV LANGUAGE ko_KR.UTF-8
ENV LANG ko_KR.UTF-8
ENV LC_ALL ko_KR.UTF-8
ENV LC_CTYPE ko_KR.UTF-8
ENV LC_MESSAGES ko_KR.UTF-8
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
&& echo $(date +%r)
ENV POSTGRES_USER paranlee
ENV POSTGRES_PASSWORD bluetooth
ENV POSTGRES_DB postgis
ENV POSTGRES_INITDB_ARGS " --locale='ko_Kr' "
WORKDIR /var/lib/postgresql
#!/usr/bin/env bash
kubectl ${1:-apply} -f https://gist.githubusercontent.com/nicerobot/e77ddbb0f6d2ed0ce45bfe7cfb288cdd/raw/postgres.yml
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
ports:
- port: 5432
selector:
app: postgres
clusterIP: None
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:14.3-alpine
resources:
limits:
cpu: "1"
memory: "4Gi"
requests:
cpu: "1"
memory: "4Gi"
ports:
- containerPort: 5432
env:
- name: POSTGRES_PASSWORD
value: password
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
#!/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:14.3-alpine 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