- You deleted the StatefulSet, PVC, PV, and StorageClass, but the Azure File Share still has the data because of the
reclaimPolicy: Retain
. - A new PVC was automatically created when you redeployed the StatefulSet, but you want the StatefulSet to use the old PVC (
pvc-84031045-6eaa-4680-8c4f-ee32528b17eb
) with the retained data instead.
Solution Steps
Delete the newly created PVC: First, delete the newly created PVC (
pvc-4f8c6892-d973-4213-9325-7ed9ee128772
), as you want the StatefulSet to reuse the existing one. This can be done with:Retain the Existing PV: You need to manually reclaim the existing PV (Persistent Volume) that was retained (
pvc-84031045-6eaa-4680-8c4f-ee32528b17eb
) and bind it to a new PVC. Since the PV is in the Retain state, you'll need to manually associate it with the PVC.Here's how to reclaim and rebind it to your StatefulSet:
Identify the PV: First, get the list of the Persistent Volumes (PV) and check if the old PV is in the
Released
state.The output should list the existing PV with the old PVC name (in
Released
status):Edit the PV: Edit the PV (
pvc-84031045-6eaa-4680-8c4f-ee32528b17eb
) and remove the existing claim reference (this is necessary to bind it to a new PVC):In the PV YAML, you will see a reference to the old PVC under the
spec.claimRef
section. Delete the entireclaimRef
section to unbind the PV from the old PVC.Remove this block and save the changes.
Create a New PVC: Now that the PV is unbound, create a new PVC that will bind to this existing PV. Create a YAML file for the new PVC, ensuring that the size, storage class, and access mode match the old PV. Here's an example of how the PVC should look:
Apply the PVC:
After the PVC is created, Kubernetes should automatically bind this new PVC to the existing PV (
pvc-84031045-6eaa-4680-8c4f-ee32528b17eb
) because it matches the size, storage class, and access mode.You can verify that the new PVC is bound to the existing PV:
You should see the new PVC (
mssql-data-existing
) in theBound
state.Update StatefulSet to Use the Existing PVC: Now that the PVC is bound to the existing PV, update your StatefulSet to reference the existing PVC. In your
StatefulSet
YAML, replace thevolumeClaimTemplates
section with a direct reference to the existing PVC:Apply the updated StatefulSet:
Verify the Pod: After deploying the updated StatefulSet, verify that the pod is using the existing PVC:
You can also describe the pod to ensure that the volume is mounted correctly:
Make sure that the pod is mounting the existing PVC (
mssql-data-existing
) at/var/opt/mssql
.
No comments:
Post a Comment