pod has unbound immediate persistentvolumeclaims after deleting namespace

11/1/2019

I have configured the Postgres pod with static provisioning of persistence volume in my local environment . It works fine at the first time but when i delete the namespace and rerun the pod then its status is pending and give me error pod has unbound immediate persistentvolumeclaims

I tried to remove the storageClassName from Persistance Volume claim but not works I also tried to change the storeageclass from manual to block storage but same problem

my yaml file

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  namespace: manhattan
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/opt/manhattan/current/pgdata"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
  namespace: manhattan
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: postgres
  namespace: manhattan
spec:
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
        claimName: task-pv-claim
  containers:
    - name: dbr-postgres
      image: postgres-custome
      tty: true
      volumeMounts:
        -  mountPath: "/var/lib/pgsql/9.3/data"
           name: task-pv-storage
  nodeSelector:
     kubernetes.io/hostname: k8s-master

I want my pod to be running even when i delete the namespace and rerun the pod.yaml file

-- UDIT JOSHI
kubernetes
persistent-storage
postgresql-9.3

2 Answers

11/1/2019

Data will be kept in the kubernetes node because hostpath uses the node filesystem to store the data. The problem is that if you have multiple nodes, then your pod can start on any other node. To solve this, you can either specify the node where you want your pod to start or implement a nfs or glusterfs in your kubernetes nodes. This might be the cause of your problem.

There is one more thing I can think of that might be your issue. When you remove a namespace all the kubernetes resources inside it are removed as well. There is no easy way to recover those. This means that you have to create the pv, pvc and pod in the new namespace.

-- Rodrigo Loza
Source: StackOverflow

11/4/2019

I solved this issue by using persistentVolumeReclaimPolicy to recycle. Now I can rebound the persistence volume even after deleting the namespace and recreating it

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: "/opt/manhattan/current/pgdata"
-- UDIT JOSHI
Source: StackOverflow