sql >> Database teknologi >  >> RDS >> PostgreSQL

mkdir /mnt/data:skrivebeskyttet filsystem Back-off genstart mislykkedes postgres container

I din Persistent Volume du bruger type: local hvilket betyder, at du vil oprette en mappe i /mnt . Lokal understøtter heller ikke dynamisk volumenforsyning . Hvis du vil SSH til nogen af ​​dine noder, vil du opdage, at denne mappe er ReadOnly file system .

/mnt $ mkdir somethingmkdir:kan ikke oprette mappen 'noget':Skrivebeskyttet filsystem

Som den hurtigste løsning kunne du bare ændre i din PV YAML

    - ReadWriteMany
  hostPath:
    path: /mnt/data

Til:

    - ReadWriteMany
  hostPath:
    path: /var/lib/data

Eksempel:

$ kubectl apply -f pv-pvc.yaml
persistentvolume/postgres-pv-volume created
persistentvolumeclaim/postgres-pv-claim created
$ kubectl apply -f pos.yaml
deployment.apps/postgres created
$ kubectl get po
NAME                        READY   STATUS    RESTARTS   AGE
postgres-65d9cbd495-pcqf5   1/1     Running   0          2s

$ kubectl exec -ti postgres-65d9cbd495-pcqf5 -- /bin/bash
[email protected]:/# cd /var/lib/postgresql/data
[email protected]:/var/lib/postgresql/data# ls
base    pg_commit_ts  pg_hba.conf    pg_logical    pg_notify    pg_serial     pg_stat      pg_subtrans  pg_twophase  pg_wal   postgresql.auto.conf  postmaster.opts
global  pg_dynshmem   pg_ident.conf  pg_multixact  pg_replslot  pg_snapshots  pg_stat_tmp  pg_tblspc    PG_VERSION   pg_xact  postgresql.conf       postmaster.pid
[email protected]:/var/lib/postgresql/data# echo "Hello from postgress pod" > data.txt
[email protected]:/var/lib/postgresql/data# cat data.txt
Hello from postgress pod

Hvis du nu vil SSH til den node, som er vært for denne pod, vil du være i stand til at nå denne mappe og filer.

[email protected] ~ $ sudo su
gke-cluster-1-default-pool-463f9615-gxhl /home/user # cd /var/lib/data
gke-cluster-1-default-pool-463f9615-gxhl /var/lib/data # ls
PG_VERSION    pg_dynshmem    pg_notify     pg_stat_tmp  pg_xact
base          pg_hba.conf    pg_replslot   pg_subtrans  postgresql.auto.conf
data.txt      pg_ident.conf  pg_serial     pg_tblspc    postgresql.conf
global        pg_logical     pg_snapshots  pg_twophase  postmaster.opts
pg_commit_ts  pg_multixact   pg_stat       pg_wal       postmaster.pid
gke-cluster-1-default-pool-463f9615-gxhl /var/lib/data # cat data.txt 
Hello from postgress pod

REDIGER

YAML'er jeg har brugt.

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
  labels:
    app: postgres
data:
  POSTGRES_DB: postgresdb
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: root
---
apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  type: NodePort
  selector:
    app: postgres
  ports:
  - name: postgres
    port: 5432
    nodePort: 30432
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: postgres-pv-volume
  labels:
    app: postgres
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: /var/lib/data
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgres-pv-claim
  labels:
    app: postgres
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
---
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
          imagePullPolicy: "IfNotPresent"
          envFrom:
            - configMapRef:
                name: postgres-config
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pv-claim
            
configmap/postgres-config created
service/postgres created
persistentvolume/postgres-pv-volume created
persistentvolumeclaim/postgres-pv-claim created
deployment.apps/postgres created

$ kubectl get po
NAME                        READY   STATUS    RESTARTS   AGE
postgres-65d9cbd495-wxx4h   1/1     Running   0          19s



  1. Hvordan slipper man en skabelondatabase fra PostgreSQL?

  2. panic:sql:forventet 1 destinationsargumenter i Scan, ikke <number> golang, pq, sql

  3. Tilføj applikationsnavn / programnavn i mysql-forbindelsesstrengen

  4. Hvordan får man elementer med et unikt nummer fra et json-array i PostgreSQL?