Reputation: 392
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...
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.
??? 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!
Upvotes: 2
Views: 1952
Reputation: 1350
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
Upvotes: 2