public inbox for [email protected]
help / color / mirror / Atom feedFrom: first last <[email protected]>
To: [email protected]
To: [email protected]
Subject: Access a Postgres storage with two independent instances
Date: Tue, 7 May 2024 00:47:40 +0530
Message-ID: <CAG3FJTaRdS1asGHcuMk3NFB0Ap+kcjO7mk1gMY2jSZ4T0a_62A@mail.gmail.com> (raw)
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.
view thread (5+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Access a Postgres storage with two independent instances
In-Reply-To: <CAG3FJTaRdS1asGHcuMk3NFB0Ap+kcjO7mk1gMY2jSZ4T0a_62A@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox