2

Situation: I have a problem with my PVC. I need to use helm chart to update our monitoring. But we dont have tiller, so we have to use helm template for creating our yaml files, so that we are able to deploy it with kubectl. We need sometimes to update our helm charts, so we need to repeat the process often.

Problem: With "Kubectl delete -f FILE_WITH_YAMLS.yaml && Kubectl create -f FILE_WITH_YAMLS.yaml ", it deletes everything, even our PVC (+ PV). But i don't want to delete the PVC.

Solution: 1. I had the idea that a delete on our PVC should be forbidden, so that we get a warning to delete it. According this: Kubernetes: Can't delete PersistentVolumeClaim (pvc) It should be possible to set

Finalizers:    [kubernetes.io/pvc-protection]

but its not working...

  1. Delete the PVC from FILE_WITH_YAMLS.yaml. It wouldn't be deleted again with "kubectl delete -f FILE_WITH_YAMLS.yaml". But its easy to forget to delete the PVC, so i think its too risky.

  2. ??? Do you have any ideas?

My PVC form cluster looks like this:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    pv.kubernetes.io/bind-completed: "yes"
    pv.kubernetes.io/bound-by-controller: "yes"
    volume.beta.kubernetes.io/storage-provisioner: cinder.csi.openstack.org
  creationTimestamp: "2020-05-11T07:15:11Z"
  finalizers:
  - kubernetes.io/pvc-protection
  labels:
    app: prometheus
    chart: prometheus-10.4.0
    component: server
    heritage: Tiller
    release: monitoring
  name: monitoring-prometheus-server
  namespace: monitoring
  resourceVersion: "114848084"
  selfLink: /api/v1/namespaces/monitoring/persistentvolumeclaims/monitoring-prometheus-server
  uid: 3430de7d-d167-41c7-92cc-eb15803cdca7
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 15Gi
  storageClassName: cinder
  volumeMode: Filesystem
  volumeName: pvc-3430de7d-d167-41c7-92cc-eb15803cdca7
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 15Gi
  phase: Bound

Thanks for any help!

goku736
  • 372
  • 2
  • 16
  • Can you simply describe your goal? your description is quite complicated. – Kamol Hasan May 11 '20 at 09:04
  • I have to delete a big yaml file with many deployments, pvcs,... etc. with "kubectl delete -f *.yaml. The PVCs are in the file. So when execute the command, my PVC are gone. I want to prevent it. – goku736 May 11 '20 at 09:07
  • 1
    If you don't want to delete the pv and pvc, then you can simply remove those yaml from `FILE_WITH_YAMLS.yaml` and maintain them in another separate yaml if possible. – Kamol Hasan May 11 '20 at 09:07
  • 1
    Yes its right, i noted it in point 2 :) But i dont like this solution that much, because we get somethimes an update to the helm chars and we have to deploy it again with kubectl. And its easy to forget to delete the PVC from the yamls. – goku736 May 11 '20 at 09:58

1 Answers1

2

I didnot try the solution but might work.Label the resources that you want delete like delete=true ..etc

After that in the delete command specify the label like

kubectl delete -f *.yaml -l delete=true
sachin
  • 1,220
  • 1
  • 14
  • 24