# Uninstall Platforma

How do I remove Platforma, and what stays?

The removal deletes the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) and the parts that the installation made. The installers, the Terraform modules (The Terraform code that MiLaboratories provides to install Platforma. The cloud-specific Terraform modules make the cluster and its cloud parts in AWS or Google Cloud; the cloud-agnostic Terraform modules install Platforma into the cluster.) and the Helm chart keep the results and the database. Thus a mistake does not delete them: you delete them later, on purpose. In Single Server mode (The mode in which the Backend and all its jobs run on one Linux machine, the server, with no Kubernetes cluster.), you delete the data folder yourself, as the last step. In each case, make a backup first.

## Before you remove Platforma

1. **Make a backup** of the database: see [Make a backup now](/maintain-backup-and-restore/#make-a-backup-now). Copy it out of the installation: the backup files are in the primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.).

2. **Keep the master secret** outside the installation: without it, a kept database cannot read the credentials that it stores. See [What to keep](/maintain-backup-and-restore/#what-to-keep).

3. **Write down the storage of the installation**, when a new installation will use it again: see [Kept data and reuse](/configuration-storage/#kept-data-and-reuse).

## Remove Platforma

#### Variant: AWS installer

Delete the CloudFormation stack. The stack removes Platforma, the cluster and the network. It keeps these parts, and you delete them later, when you do not need them:

- the bucket of the primary storage, with the results of all projects and the database backups;
- the workspace (The storage where the Backend and all jobs keep the working files of running jobs. The Backend and the jobs use it at the same time. In Kubernetes, it is a network file system; in Single Server mode, it is a folder on the server.);
- the volumes of the database (all projects) and the logs;
- the master secret.

For the steps, the rights, what stays and the commands that delete it, see [Uninstall an installer installation](/maintain-uninstalling-cloud-installer/).

#### Variant: Google Cloud installer

Run `teardown.sh` of the release of the last `install.sh` run. By default, it keeps the bucket of the primary storage, the workspace, the database disk and the VPC network. With `DELETE_ALL_DATA=true`, it also deletes them: the results of all projects, the database backups and all projects. The default mode needs the role `roles/config.admin` and the permission `compute.disks.setLabels`: the script checks them before it changes anything.

For the steps, the rights, what stays and the commands that delete it, see [Uninstall an installer installation](/maintain-uninstalling-cloud-installer/).

#### Variant: Terraform modules

Remove the roots in the reverse order of the installation: `services`, then `cluster`, then `cloud`. The commands use the folders of the reference setup in the clone of [platforma-install](https://github.com/milaboratory/platforma-install). For a cluster that exists, run `terraform destroy` in your folders `services` and `cluster`, and skip step 4. `<cloud>` is `aws` or `gcp`.

Give each destroy the same `-var-file` and `-var` options as the apply of its root. The destroy checks the input values too, and the defaults do not pass the checks. `<values file>` is the file with the values of the root, `terraform.tfvars` in the [install guide](/install-cloud-terraform/). When the apply had `-var aws_profile=<profile>`, add it to the destroy too.

1. **Make a backup** and write down the storage of the installation (see [Before you remove Platforma](#before-you-remove-platforma)).

2. **Destroy the root `services`.** This removes the Backend.

   ```sh
   cd <platforma-install>/terraform/cloud-agnostic/examples/services
   terraform destroy -var-file=<values file> \
     -var infrastructure_file=../../../<cloud>/examples/handoff/infrastructure.json \
     -var cluster_connection_file=../../../<cloud>/examples/handoff/cluster-connection.json
   ```

3. **Destroy the root `cluster`.** This removes Kueue (A Kubernetes add-on that holds jobs in a queue until the cluster has free CPU, memory and GPU for them.), AppWrapper (A Kubernetes add-on that wraps the pods of one job into a single unit, so that Kueue admits and starts them together.) and the other parts of Platforma in the cluster.

   ```sh
   cd <platforma-install>/terraform/<cloud>/examples/cluster
   terraform destroy
   ```

   The destroy can take up to about 30 minutes: it waits until the namespaces of Platforma are gone. They stay in the state `Terminating` until the load balancer controller of the cloud deletes its cloud objects, some minutes after step 2. If the destroy stops with `timeout while waiting for resource to be gone`, run the same destroy again.

4. **Destroy the root `cloud`.** Only for AWS and Google Cloud. The modules protect the bucket and the workspace against removal. Thus, first take them out of the Terraform state: they stay in the cloud, with the data. Then destroy the rest.

   #### Variant: AWS

   ```sh
   cd <platforma-install>/terraform/aws/examples/cloud
   terraform state rm \
     'module.cloud_base.aws_s3_bucket.primary[0]' \
     'module.cloud_base.aws_s3_bucket_ownership_controls.primary[0]' \
     'module.cloud_base.aws_s3_bucket_public_access_block.primary[0]' \
     'module.cloud_base.aws_s3_bucket_server_side_encryption_configuration.primary[0]' \
     'module.cloud_base.aws_s3_bucket_lifecycle_configuration.primary[0]' \
     'module.cloud_base.aws_s3_bucket_policy.primary[0]' \
     'module.cloud_base.aws_efs_file_system.workspace[0]'
   terraform destroy -var-file=<values file>
   ```

   #### Variant: Google Cloud

   ```sh
   cd <platforma-install>/terraform/gcp/examples/cloud
   terraform state rm 'module.cloud_base.google_storage_bucket.primary[0]' \
                      'module.cloud_base.google_filestore_instance.workspace[0]'
   terraform destroy -var-file=<values file>
   ```

For what stays and how to delete it, see [What stays](#what-stays).

#### Variant: Helm chart

Make a backup first (see [Before you remove Platforma](#before-you-remove-platforma)). Then remove the Backend:

```sh
helm uninstall platforma -n platforma
```

The team that runs the cluster then removes the parts that it made for Platforma, for example Kueue and AppWrapper. The chart never made the Secrets, so they stay.

#### Variant: Single Server

1. **Make a backup** (see [Before you remove Platforma](#before-you-remove-platforma)), and copy `/etc/platforma` to a safe place. It holds the master secret and the license key in `platforma.env`, the file of the static list of users (A sign-in provider that is a file with the logins and the password hashes of the users, in the htpasswd format. The Backend reads it again when it changes.) and the private key of the certificate.

2. **Stop the Backend and remove the service:**

   ```sh
   sudo systemctl disable --now platforma
   sudo rm /etc/systemd/system/platforma.service
   sudo systemctl daemon-reload
   ```

3. **Remove the program and its settings:**

   ```sh
   sudo rm -rf /opt/platforma /etc/platforma
   ```

4. **Delete the data folder last.** `/data/platforma` holds the database, the logs, the workspace and, when the primary storage is a folder, the results of all projects. Delete it only after you copied the backup and the results that you need. When the primary storage is a bucket, the bucket stays.

   ```sh
   sudo rm -rf /data/platforma
   sudo userdel platforma
   ```

## What stays

- **AWS installer:** the bucket, the workspace, the volumes of the database and the logs, and the master secret. The log groups of the stack and the DNS validation record also stay.

- **Google Cloud installer:** by default, the bucket, the workspace, the database disk and the VPC network. After a teardown with `DELETE_ALL_DATA=true`, no data stays. After each teardown, the master secret, the service account of the installer and the Cloud DNS zone stay.

  For the installers, see [What stays and how to delete it](/maintain-uninstalling-cloud-installer/#what-stays-and-how-to-delete-it).

- **Terraform modules:** the bucket of the primary storage, the workspace and the database volume, whose reclaim policy is `Retain`. The logs volume stays only with `disks.logs.reclaim_policy = "Retain"`; the default is `Delete`, and a new installation works the same with a new, empty logs volume. On Google Cloud, a kept Filestore instance works again only when the network of the installation is kept too. On AWS, the image caches also stay: the ECR repositories `<name>-software/milaboratories/pl-containers` and `<name>-backend/milaboratories/platforma`, which ECR made at the first pull of an image. Delete them with `aws ecr delete-repository --repository-name <repository> --force`.

- **Helm chart:** the claims of the database, the logs and the workspace (`helm.sh/resource-policy: keep`), and the volumes that they hold. A new installation with the same release name in the same namespace gets the same data. When you delete the claims, the reclaim policy of their StorageClass decides whether the volumes are deleted too.

- **Single Server mode:** what you do not delete in the steps; a bucket of the primary storage always stays.

To use the kept data again, see [Kept data and reuse](/configuration-storage/#kept-data-and-reuse). To delete it, delete the bucket, the file system and the volumes in the console of the cloud. Do this only after you copied the backup and the results that you need. The bucket holds the results of all projects, and the database volume holds all projects. With the Terraform modules on AWS, find the volumes by the tag `platforma-installation`:

```sh
aws ec2 describe-volumes --filters Name=tag:platforma-installation,Values=<name> \
  --query 'Volumes[].[VolumeId,Tags[?Key==`platforma-component`].Value|[0]]' --output text
aws ec2 delete-volume --volume-id <VOLUME_ID>
```

## Next

- [Uninstall an installer installation](/maintain-uninstalling-cloud-installer/)
- [Get help](/maintain-get-help/)

Source: https://docs.platforma.bio/maintain-uninstalling/
