Kubernetes with postgres on Fedora

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-deployment
  labels:
    app: postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      volumes:
        - name: pg-pv
          hostPath:
            path: /mnt/data/postgres
            type: Directory
      containers:
        - name: pg
          image: postgres:15
          imagePullPolicy: Always
          ports:
            - containerPort: 5432
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: pg-pv
          env:
            - name: POSTGRES_DB
              value: postgres
            - name: POSTGRES_USER
              value: user
            - name: POSTGRES_PASSWORD
              value: user

---
apiVersion: v1
kind: Service
metadata:
  name: pg-entrypoint
  namespace: default
spec:
  type: NodePort
  selector:
    app: postgres
  ports:
    - port: 5432
      targetPort: 5432

according to this document, I installed and ran Kubernetes on Fedora 40. Error after running postgres yaml

chmod: changing permissions of '/var/lib/postgresql/data': Permission denied
find: ‘/var/lib/postgresql/data’: Permission denied

/mnt/data/postgres
ls -al 
drwx------. 1 systemd-coredump systemd-coredump  0 Jul 17 19:24 postgres

Where am I wrong? What should I do?

Added f40, kubernetes, postgresql

Edited your formatting, you can use the </> button to add preformatted/ monospace/ codeblock text :wink:

1 Like

I will take a look tomorrow (Saturday) AM.

Meanwhile - have you seen this thread: postgresql - postgres on kubernetes volume permission error - Stack Overflow?

The quick answer to get it working would be to disable selinux. I removed the postgres deploy, temporarily disabled selinux (i.e. sudo setenforce 0) and then applied the postgres deployment.

The proper answer on how to enable both selinux and postgres is something i will work on.

[vagrant@localhost src]$ kubectl get pods --all-namespaces
NAMESPACE      NAME                                            READY   STATUS    RESTARTS   AGE
default        postgres-665b7554dc-bgp9h                       1/1     Running   0          9s
kube-flannel   kube-flannel-ds-tv4b9                           1/1     Running   2          96m
kube-system    coredns-76f75df574-kndvk                        1/1     Running   11         97m
kube-system    coredns-76f75df574-vjckb                        1/1     Running   11         97m
kube-system    etcd-localhost.localdomain                      1/1     Running   2          97m
kube-system    kube-apiserver-localhost.localdomain            1/1     Running   2          97m
kube-system    kube-controller-manager-localhost.localdomain   1/1     Running   2          97m
kube-system    kube-proxy-gvj48                                1/1     Running   2          97m
kube-system    kube-scheduler-localhost.localdomain            1/1     Running   2          97m
1 Like