Skip to content

Commit

Permalink
non working attempt at persistent volume for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
lrvick committed Nov 28, 2020
1 parent de95681 commit 89b1376
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 10 deletions.
7 changes: 4 additions & 3 deletions images/postgres/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN mkdir -p \
~/rootfs/lib/x86_64-linux-gnu \
~/rootfs/lib64 \
~/rootfs/data \
~/rootfs/config \
~/rootfs/bin \
~/rootfs/tmp \
~/rootfs/usr/lib/locale \
Expand All @@ -34,14 +35,14 @@ RUN mkdir -p \
&& cp /lib64/ld-linux-x86-64.so.2 ~/rootfs/lib64 \
&& cp -a ~/out/. ~/rootfs/ \
&& chmod -R 700 ~/rootfs/data/ \
&& PGDATA=~/rootfs/data/ ~/rootfs/bin/initdb -U nobody \
&& echo "listen_addresses='*'" > ~/rootfs/data/postgresql.conf
&& echo "listen_addresses='*'" > ~/rootfs/config/postgresql.conf \
&& echo "data_directory='/data'" >> ~/rootfs/config/postgresql.conf

FROM scratch
COPY --from=build --chown=100:100 /home/build/rootfs /
STOPSIGNAL SIGQUIT
EXPOSE 5432
USER 100:100
ENV PGDATA=/data
ENV PGDATA=/config
ENV PATH=/bin
ENTRYPOINT ["/bin/postgres"]
77 changes: 74 additions & 3 deletions pods/userdb/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

apiVersion: apps/v1
kind: Deployment
metadata:
name: userdb-db-write
labels:
app: userdb
spec:
replicas: 1
selector:
Expand All @@ -12,6 +15,12 @@ spec:
labels:
deployment: userdb-db-write
spec:
volumes:
- name: userdb-data
persistentVolumeClaim:
claimName: userdb-data
securityContext:
fsGroup: 100
containers:
- name: postgres
image: registry.localhost:5000/postgres
Expand All @@ -25,14 +34,17 @@ spec:
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: userdb-data
name: userdb-db-write
key: password

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: userdb-api
labels:
app: userdb
spec:
replicas: 3
selector:
Expand All @@ -51,9 +63,9 @@ spec:
containerPort: 3000
env:
- name: PGRST_SERVER_PORT
value: 3000
value: '3000'
- name: PGPORT
value: 5432
value: '5432'
- name: PGHOST
value: userdb-db-write
- name: PGDATABASE
Expand All @@ -67,3 +79,62 @@ spec:
key: password
- name: PGRST_DB_URL
value: postgresql://$(PGDATABASE)?host=$(PGHOST)&user=$(PGUSER)

#---
#
#apiVersion: v1
#kind: Pod
#metadata:
# name: userdb-init
# labels:
# app: userdb
#spec:
# volumes:
# - name: userdb-data
# persistentVolumeClaim:
# claimName: userdb-data
# containers:
# - name: userdb-init
# image: debian:buster
# volumeMounts:
# - mountPath: /data
# name: userdb-data
# command: ["/bin/sh"]
# args: ["-c","chown -R 100:100 /data; ls -lah /data;"]
# restartPolicy: Never

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: userdb-data
labels:
app: userdb
spec:
storageClassName: ""
volumeName: userdb-data
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi

---

apiVersion: v1
kind: PersistentVolume
metadata:
name: userdb-data
labels:
app: userdb
spec:
storageClassName: ""
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
claimRef:
name: userdb-data
hostPath:
path: /volumes/userdb-data
4 changes: 3 additions & 1 deletion pods/userdb/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: userdb-db-write
labels:
app: userdb
data:
password: REPLACE_VIA_KUSTOMIZE
password: UkVQTEFDRU1FCg==
6 changes: 3 additions & 3 deletions pods/userdb/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ kind: Service
metadata:
name: userdb-api
labels:
app: userdb-api
app: userdb
spec:
ports:
- name: http
port: 80
targetPort: http
selector:
app: userdb-api
app: userdb

---
apiVersion: v1
kind: Service
metadata:
name: userdb-db-write
labels:
app: userdb-db-write
app: userdb
spec:
ports:
- name: tcp
Expand Down

0 comments on commit 89b1376

Please sign in to comment.