> ## 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.

<Warning>
  CRM and Fees guidance marked legacy on this page applies only to legacy releases that already exist. Midaz v4 deploys the unified Ledger and serves CRM and Fees on `/v2`.
</Warning>

The Helm repository retains a `crm.enabled` workload and the `plugin-fees-helm` chart for older application releases. These are legacy compatibility surfaces, not the Midaz v4 deployment model.

This guide walks you through fully removing a Midaz deployment from Kubernetes. `helm uninstall` removes the Helm-managed resources. What happens to the database volumes depends on the bundled subcharts, so read their storage settings before you run it.

<Warning>
  Uninstalling Midaz can permanently delete application data. 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)                                        |
| PersistentVolumeClaims of the bundled PostgreSQL, MongoDB, and RabbitMQ                      | Depends on how each subchart creates them. Read the storage settings of the version you run |
| 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, list the claims so that you know what exists:

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

Then back up your databases:

```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
```

```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 a module inside the `midaz-helm` chart. You enable it with the `crm` values block. No CRM chart exists. You do not back it up or uninstall it separately.
</Note>

Verify all releases that the uninstall affects:

```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 the Kubernetes resources that the Helm chart created: Deployments, StatefulSets, Services, Ingresses, ConfigMaps, chart-managed Secrets, ServiceAccounts, RBAC resources, and bootstrap Jobs. It does not remove Secrets you created outside Helm, or the namespace.

Verify that no Helm-managed pods remain:

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

***

## Cleaning up persistent resources

***

### PersistentVolumeClaims

List the claims that survived the uninstall:

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

Delete only the Midaz PVCs that you identified above. Do not use a namespace-wide delete when other workloads share the namespace:

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

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

### Secrets

`helm uninstall` does not remove secrets created outside the Helm release lifecycle (e.g., `kubectl create secret`). List all secrets in the namespace and identify any that you no longer need:

```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

***

When no resources remain inside the namespace, 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. The script assumes a namespace that holds Midaz alone. It removes every claim, Secret and ConfigMap in that namespace.
</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.
  2. **Export critical data.** If you must migrate or preserve any data, 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.
  5. **Verify no traffic.** Confirm that no active traffic reaches the services before you proceed.
</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.
for release in plugin-fees plugin-br-pix-direct-jd; do
  if err=$(helm status "$release" -n midaz-plugins 2>&1 >/dev/null); then
    if ! helm uninstall "$release" -n midaz-plugins; then
      echo "Aborting: failed to uninstall $release." >&2
      exit 1
    fi
  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/deploy/midaz/midaz-installation): Installation guide if you need to reinstall
* [Upgrading Midaz and plugins via Helm](/en/platform/deploy/midaz/midaz-upgrade-guide): Upgrade and rollback procedures
* [Troubleshooting](/en/platform/deploy/midaz/midaz-troubleshooting): Diagnose issues before deciding to uninstall
* [Midaz chart version compatibility](/en/platform/deploy/helm-version-compatibility): Current chart and application metadata
