<p>I made a Kafka and zookeeper as a statefulset and exposed Kafka to the outside of the cluster. However, whenever I try to delete the Kafka statefulset and re-create one, the data seemed to be gone? (when I tried to consume all the message using <code>kafkacat</code>, the old messages seemed to be gone) even if it is using the same PVC and PV. I am currently using EBS as my persistent volume. </p>

<p>Can someone explain to me what is happening to PV when I delete the statefulset? Please help me.</p>

<p>Kubernetes default prevent deleting <code>PersistentVolumeClaims</code> and bounded <code>PersistentVolume</code> objects when you scaling <code>StatefulSet</code> down or deleting them.</p>
<p>Retaining <code>PersistentVolumeClaims</code> is the default behavior, but you can configure the <code>StatefulSet</code> to delete them via the <code>persistentVolumeClaimRetentionPolicy</code> field.</p>
<p>This example shows part of <code>StatefulSet</code> manifest file, where retention policy causes deleting <code>PersistentVolumeClaim</code> when <code>StatefulSet</code> is scaled down, and retaining when <code>StatefulSet</code> is deleted.</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: quiz
  spec:
    persistentVolumeClaimRetentionPolicy:
      whenScaled: Delete
      whenDeleted: Retain
</code></pre>
<p>Make sure you have properly configured StatefulSet manifest and Kafka cluster.</p>
<p>NOTE</p>
<blockquote>
<p>If you want to delete a StatefulSet but keep the Pods and the
PersistentVolumeClaims, you can use the --cascade=orphan option. In
this case, the PersistentVolumeClaims will be preserved even if the
retention policy is set to Delete.</p>
</blockquote>
<p><a href="https://www.manning.com/books/kubernetes-in-action-second-edition" rel="nofollow noreferrer">Marko Lukša &quot;Kubernetes in Action, Second Edition&quot;</a></p>
