Access a Postgres storage with two independent instances

From: first last <ny(dot)otherwrks(at)gmail(dot)com>
To: pgsql-novice(at)lists(dot)postgresql(dot)org, pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Access a Postgres storage with two independent instances
Date: 2024-05-06 19:17:40
Message-ID: CAG3FJTaRdS1asGHcuMk3NFB0Ap+kcjO7mk1gMY2jSZ4T0a_62A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I tried to deploy Postgres deployment with Kubernetes, having three
replicas that are accessing the same storage(PVC). Here is the configuration
```
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-volume
labels:
type: local
spec:
persistentVolumeReclaimPolicy: Delete
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/postgresql
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-volume-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 3
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: 'postgres:14'
env:
- name: POSTGRES_DB
value: db
- name: POSTGRES_USER
value: user
- name: POSTGRES_PASSWORD
value: pwd
volumeMounts:
- name: postgresdata
mountPath: /var/lib/postgresql/data
volumes:
- name: postgresdata
persistentVolumeClaim:
claimName: postgres-volume-claim
---
apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgres
spec:
type: NodePort
ports:
- port: 5432
protocol: TCP
targetPort: 5432
nodePort: 32001
selector:
app: postgres

```

When you apply this configuration file `kubectl apply -f file_name.yaml`,
you can create three pods. Here I have given the configuration to create
the pods that use a single storage as a data store. But what actually
happening is, that it uses separate storage. I have tested all the replicas
manually by creating a db and table and see, if other database stores are
affected or not. Anyway, it is not affected. And then I tried to apply the
same config file change the image name and the env variables suit for MySQL
and tried to deploy it. It works as expected. Anyway, it can not use single
storage(
https://stackoverflow.com/questions/78436945/access-a-mysql-storage-with-two-independent-instances
).

Finally, my question is, why the scenario is different for MySQL and
Postgres? Could you please help me to figure out the issue? This is for my
Final year project testing Kubernetes using fuzzing.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Alan Hodgson 2024-05-06 20:36:59 Re: Access a Postgres storage with two independent instances
Previous Message TIM CHILD 2024-04-24 22:08:36 Re: Hello, novice Postgres user, seg fault investigation