Hello Kubernetes community,
I am currently facing challenges in deploying PostgreSQL on Kubernetes with iSCSI external storage.
Environment:
- Kubernetes Version:
- Client Version: v1.28.4
- Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
- Server Version: v1.28.4
- PostgreSQL Version: latest
- Operating System on Kubernetes Nodes: Ubuntu 20.04
PostgreSQL Deployment:
Create a new YAML configuration (postgres-pv.yaml) file
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
iscsi:
targetPortal: 192.168.1.1:3260
iqn: iqn.1991-05.com.microsoft:win-volti8mk571-pgdata5-target
lun: 0
fsType: ext4
persistentVolumeReclaimPolicy: Retain
Create a new YAML configuration (postgres-pvc.yaml) file
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
Create a new YAML configuration (postgres-deployment.yaml) file
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:latest
env:
- name: POSTGRES_USER
value: <YOUR_DB_USER>
- name: POSTGRES_PASSWORD
value: <YOUR_DB_PASSWORD>
- name: POSTGRES_DB
value: <YOUR_DB_NAME>
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-pvc
Apply the YAML files to your Kubernetes cluster:
1. kubectl apply -f postgres-pv.yaml
2. kubectl apply -f postgres-pvc.yaml
3. kubectl apply -f postgres-deployment.yaml
i have facing the problem below mention
> kubectl logs postgres-8ff8f8d9f-5g4hb
Defaulted container "postgres" out of: postgres, init-db (init)
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
initdb: detail: It contains a lost+found directory, perhaps due to it being a mount point.
initdb: hint: Using a mount point directly as the data directory is not recommended.
Create a subdirectory under the mount point.
how to resolve the problem or any other solution, as soon as possible