> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Uninstalling Midaz deployment

> Fully remove a Midaz Helm deployment from Kubernetes — Helm-managed resources, persistent volumes, secrets, and the namespace itself.

This guide walks you through fully removing a Midaz deployment from Kubernetes. `helm uninstall` removes the Helm-managed resources — and, importantly, **it also deletes the MongoDB PersistentVolumeClaim along with them**. Only the PostgreSQL volumes survive, because they are created from a StatefulSet `volumeClaimTemplate`. This page covers what goes with the release, what stays behind, and how to clean the rest up.

<Warning>
  Uninstalling Midaz permanently deletes application data. `helm uninstall` alone is enough to destroy the MongoDB volume — back up **before** running it, not after. This operation is irreversible.
</Warning>

## What uninstall deletes and what survives

***

| Resource                                                                                     | On `helm uninstall`                                                                             |
| :------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------- |
| Deployments, Services, ConfigMaps, Secrets, ServiceAccounts, RBAC, HPA, PDB, NetworkPolicy   | Deleted                                                                                         |
| Bootstrap Jobs (`<release>-bootstrap-postgres`, `-bootstrap-mongodb`, `-bootstrap-rabbitmq`) | Deleted (they also self-delete 300s after finishing)                                            |
| **PVC `<release>-mongodb`**                                                                  | **Deleted — MongoDB data is lost**                                                              |
| PVCs `data-<release>-postgresql-primary-0`, `data-<release>-postgresql-replication-0`        | Survive (StatefulSet volumeClaimTemplates are not garbage-collected)                            |
| RabbitMQ storage                                                                             | Nothing to delete — RabbitMQ runs on `emptyDir`, so its data is already gone when the pod stops |
| Secrets you created yourself (`kubectl create secret`)                                       | Survive                                                                                         |
| The namespace                                                                                | Survives                                                                                        |

<Danger>
  No chart resource carries a `helm.sh/resource-policy: keep` annotation. Do not rely on Helm to protect any volume.
</Danger>

## Prerequisites

***

Before uninstalling, back up your databases — `helm uninstall` destroys the MongoDB volume:

```bash theme={null}
kubectl exec -n midaz midaz-mongodb-0 -- mongodump --archive=/tmp/dump.gz --gzip
kubectl cp midaz/midaz-mongodb-0:/tmp/dump.gz ./mongo-backup.gz
```

The PostgreSQL volumes survive `helm uninstall`, but the PVC cleanup below destroys them. Dump PostgreSQL too if you intend to run that step:

```bash theme={null}
kubectl exec -n midaz midaz-postgresql-primary-0 -- \
  pg_dumpall -U postgres > ./postgres-backup.sql
```

Then back up your current Helm values so you can reinstall with the same configuration if needed:

```bash theme={null}
helm get values midaz -n midaz > midaz-values-backup.yaml
```

Also back up any plugin releases you run separately (plugins install into their own namespace, `midaz-plugins`):

```bash theme={null}
helm get values plugin-fees -n midaz-plugins > plugin-fees-values-backup.yaml
helm get values plugin-br-pix-direct-jd -n midaz-plugins > plugin-pix-values-backup.yaml
```

<Note>
  CRM is part of the Midaz chart, not a separate release — there is no `plugin-crm` chart to back up or uninstall.
</Note>

Verify all releases that will be affected:

```bash theme={null}
helm list -n midaz
helm list -n midaz-plugins
```

***

## Uninstalling the Helm release

***

Run the following command to uninstall the Midaz Helm release:

```bash theme={null}
helm uninstall midaz -n midaz
```

This removes all Kubernetes resources created by the Helm chart — Deployments, StatefulSets, Services, Ingresses, ConfigMaps, chart-managed Secrets, ServiceAccounts, RBAC resources, bootstrap Jobs, **and the `midaz-mongodb` PVC**. It does not remove the PostgreSQL StatefulSet PVCs, Secrets you created outside Helm, or the namespace.

Verify that all Helm-managed pods have been removed:

```bash theme={null}
kubectl get pods -n midaz
```

***

## Cleaning up persistent resources

***

### PersistentVolumeClaims

After uninstall, the PostgreSQL claims are what remains. List them to confirm:

```bash theme={null}
kubectl get pvc -n midaz
```

You should see `data-midaz-postgresql-primary-0` and `data-midaz-postgresql-replication-0`. The `midaz-mongodb` claim is already gone — Helm deleted it with the release.

Delete all remaining PVCs in the namespace (this destroys the PostgreSQL data):

```bash theme={null}
kubectl delete pvc --all -n midaz
```

Or delete specific PVCs by name:

```bash theme={null}
kubectl delete pvc <pvc-name> -n midaz
```

<Danger>
  Deleting these PVCs permanently destroys the PostgreSQL volume data — the ledger's system of record. Make sure database backups are in place before running this command.
</Danger>

### Secrets

Secrets created outside the Helm release lifecycle (e.g., `kubectl create secret`) are not removed by `helm uninstall`. List all secrets in the namespace and identify any that are no longer needed:

```bash theme={null}
kubectl get secrets -n midaz
```

Delete individual orphaned secrets:

```bash theme={null}
kubectl delete secret <secret-name> -n midaz
```

Or delete all secrets in the namespace:

```bash theme={null}
kubectl delete secrets --all -n midaz
```

### ConfigMaps

ConfigMaps created manually or by bootstrap jobs may also remain. List them:

```bash theme={null}
kubectl get configmaps -n midaz
```

Delete orphaned ConfigMaps:

```bash theme={null}
kubectl delete configmap <configmap-name> -n midaz
```

***

## Namespace cleanup

***

Once all resources inside the namespace have been removed, delete the namespace itself:

```bash theme={null}
kubectl delete namespace midaz
```

<Note>
  Deleting the namespace will forcefully remove any remaining resources inside it. If a resource is stuck in `Terminating` state, you may need to remove its finalizers manually.
</Note>

Verify the namespace is gone:

```bash theme={null}
kubectl get namespace midaz
```

***

## Complete cleanup

***

For staging, evaluation, or CI environments where a full teardown is safe, the following script automates the entire process:

<Danger>
  **Data loss is permanent.** Run this only in environments where you have confirmed backups or where data loss is acceptable (staging, evaluation, CI). Do not run this in production without a full backup and team sign-off.
</Danger>

```bash expandable theme={null}
#!/bin/bash
set -e

NAMESPACE=midaz
RELEASE=midaz

echo "==> Uninstalling Helm release: $RELEASE"
helm uninstall "$RELEASE" -n "$NAMESPACE" || true

echo "==> Deleting all PersistentVolumeClaims"
kubectl delete pvc --all -n "$NAMESPACE" || true

echo "==> Deleting all Secrets"
kubectl delete secrets --all -n "$NAMESPACE" || true

echo "==> Deleting all ConfigMaps"
kubectl delete configmaps --all -n "$NAMESPACE" || true

echo "==> Deleting namespace: $NAMESPACE"
kubectl delete namespace "$NAMESPACE" || true

echo "==> Done. Midaz has been fully removed."
```

Save this as `midaz-cleanup.sh`, make it executable (`chmod +x midaz-cleanup.sh`), and run it with `./midaz-cleanup.sh`.

***

## Production considerations

***

<Warning>
  In production, a full uninstall requires careful coordination. Follow these steps before running any cleanup commands:

  1. **Back up all databases *before* `helm uninstall`.** Export a full snapshot of PostgreSQL and MongoDB — the MongoDB volume is destroyed by the uninstall itself, not by the cleanup steps.
  2. **Export critical data.** If any data needs to be migrated or preserved, export it before uninstalling.
  3. **Coordinate with your team.** Notify all stakeholders of planned downtime and confirm the maintenance window.
  4. **Uninstall plugins first.** Remove plugin releases (Fees, Pix) before uninstalling the core Midaz release. CRM needs no separate uninstall — it ships inside the Midaz chart.
  5. **Verify no traffic.** Confirm that no active traffic is hitting the services before proceeding.
</Warning>

Uninstall plugins before the core release:

```bash theme={null}
# Skips a release that is genuinely absent, and aborts on anything else
# (auth, API, timeout) instead of silently leaving it installed.
# On Helm 3.13+ this is just: helm uninstall <release> -n midaz-plugins --ignore-not-found
for release in plugin-fees plugin-br-pix-direct-jd; do
  if err=$(helm status "$release" -n midaz-plugins 2>&1 >/dev/null); then
    helm uninstall "$release" -n midaz-plugins
  elif printf '%s' "$err" | grep -q 'release: not found'; then
    echo "Skipping $release — not installed."
  else
    echo "Aborting: helm status $release failed: $err" >&2
    exit 1
  fi
done
helm uninstall midaz -n midaz
```

Then proceed with the persistent resource cleanup steps described above.

***

## Related resources

* [Deploy Midaz using Helm](/en/platform/helm/midaz/midaz-installation) — Installation guide if you need to reinstall
* [Upgrading Midaz and plugins via Helm](/en/platform/helm/midaz/midaz-upgrade-guide) — Upgrade and rollback procedures
* [Troubleshooting](/en/platform/helm/midaz/midaz-troubleshooting) — Diagnose issues before deciding to uninstall
* [Version compatibility](/en/platform/helm/helm-version-compatibility) — Version mapping reference
