Skip to content

Install in cloud with Terraform

guideinstall-cloud-terraform

Install Platforma in AWS or Google Cloud with the Terraform modules.

Other ways: Install in cloud with installer, Install in custom infrastructure, Install in Single Server mode.

The cloud-specific Terraform modulescloud-specific Terraform modules — The Terraform modules platforma-tf-cloud-base and platforma-tf-cloud-cluster. There is one pair for each cloud, AWS and Google Cloud. The roots cloud and cluster apply them. They make the network, the Kubernetes cluster, the storage, the cloud identities and the registry caches. They give the hand-off file cluster_config to the cloud-agnostic Terraform modules. Glossary make the cluster and all its cloud parts. Then the cloud-agnostic Terraform modulescloud-agnostic Terraform modules — The Terraform modules platforma-tf-services-cluster and platforma-tf-services. They do not depend on the infrastructure and install Platforma into any cluster that meets the Kubernetes contract, in a cloud or in the company's own infrastructure. Glossary, the same as for any cluster, install Platforma. Each module checks its inputs before it changes anything. You apply three Terraform roots, one after the other: cloud, cluster and services (see The roots). For a KubernetesKubernetes — A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster. Glossary cluster that the company already has, see Install in custom infrastructure. The installer is the other installation pathinstallation path — A set of tools and steps that installs Platforma. There are five installation paths: the AWS installer, the Google Cloud installer, the Terraform modules, the Helm chart and Single Server mode. Glossary in these clouds: for which of the two fits, see Installation paths.

What you get

The Terraform modulesTerraform 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. Glossary for AWS make all the infrastructure in an AWS account. You give only a region, a name, a host, the DNS zone of the host and the networks that can reach the Kubernetes API. With these settings, the modules make:

  • a VPC in two availability zones, with one NAT gateway;
  • an EKS cluster with two system nodes and one node of 8 CPUsCPUs — The compute units of a node or of the server, as Kubernetes and the operating system count them. A job asks for a number of CPUs. The cloud quotas call them vCPUs. Glossary and 32 GiB for the BackendBackend — The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs. Glossary, which run all the time. The jobjob — One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster. Glossary node groups ui and batch scale from zero: a job node starts only when a job needs it. The largest batch nodes have 32 CPUs and 256 GiB;
  • an S3 bucket as the primary storageprimary storage — The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files. Glossary, which the Backend reads and writes with its cloud identity, with no access keys;
  • an Amazon EFS file system as the workspaceworkspace — 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. Glossary, and EBS volumes for the database and the logs of the Backend;
  • the entry pointentry point — The way in to the Backend from outside the cluster, a load balancer or an Ingress with a DNS name. It usually ends TLS and sends the traffic to the Backend pod. Glossary: an Application Load Balancer with an ACM certificate for the host, and the DNS record of the host in the Route 53 zone. TLS ends at the load balancer, and ACM renews the certificate.

Users sign insign in — To show the Backend who you are, with a sign-in provider or a single-user token. The verb is "sign in"; the noun and the adjective are "sign-in". Glossary with a static list of users, and the Desktop AppDesktop App — The program that each user installs on their own computer to work with Platforma. It is a client of the Backend. Glossary connects to the host on port 443. A Backend node of this size is enough for up to about 30 users who work at the same time. For the time and the cost of the analyses, see Size and cost of an analysis.

Before you start

Prepare these items before the first apply:

  • Rights. The roots need the rights in the AWS account or the Google Cloud project and in the cluster that Rights to install lists. An administrator of the account or the project has them.

  • Quotas. The vCPU quota of the region must have room for the nodes at their maximum size: see Cloud quotas.

  • A host and its DNS zone. Choose the host name that users type in the Desktop App, for example platforma.example.com, and a public DNS zone that contains it: a Route 53 hosted zone on AWS, a Cloud DNS zone on Google Cloud. The parent zone must delegate to this zone before the first apply, because the cloud checks the domain through it before it gives the certificate. Check the delegation with dig +short NS <zone name>, for example dig +short NS example.com: the answer must show the name servers of the zone.

  • The license key. See License.

  • A clone of platforma-install at a release tag. See Where the modules are.

  • Network access from the computer that runs Terraform to github.com (the modules) and ghcr.io (the charts), or a clone and a chart mirror in the corporate network. For all hosts, see Outbound connections.

  • Tools on the computer that runs Terraform: Terraform 1.12 or later, kubectl (at most one minor version from the version of the cluster), openssl and htpasswd (the package apache2-utils or httpd-tools). Terraform installs the charts itself, so the helm tool is not necessary. OpenTofu 1.12 or later also works: then use tofu in place of terraform in the commands.

    The AWS CLI, with the credentials of the account:

    Terminal window
    aws configure # or: aws sso login --profile <profile>
    aws sts get-caller-identity

When the cluster cannot reach the public registries, make a mirror of each of them before the first apply, and keep the mirrors for as long as Platforma runs: see Registries mirroring.

Where the modules are

The Terraform modules, their example roots and the Helm charts are in the public repository platforma-install. Each release of Platforma is a tag of this repository. Use the same tag for all the modules and charts of one installation.

Folder What it holds
terraform/aws, terraform/gcp The modules platforma-tf-cloud-base and platforma-tf-cloud-cluster of the cloud, and its example roots in examples/
terraform/cloud-agnostic The modules platforma-tf-services-cluster and platforma-tf-services, and their example roots in examples/
helm/charts The charts platforma-backend and appwrapper

Each path has example roots: you apply them where they are, with a file of your values.

Path Root cloud Root cluster Root services
AWS terraform/aws/examples/cloud terraform/aws/examples/cluster terraform/cloud-agnostic/examples/services
Google Cloud terraform/gcp/examples/cloud terraform/gcp/examples/cluster terraform/cloud-agnostic/examples/services
A cluster that exists none terraform/cloud-agnostic/examples/services-cluster terraform/cloud-agnostic/examples/services

To use the example roots, clone the repository at a release tag:

Terminal window
git clone --branch <release tag> https://github.com/milaboratory/platforma-install.git

The example roots read the charts from the folder helm/charts of the same clone, so keep the whole clone. On the installation pages, <platforma-install> is the folder of this clone on your computer.

In a Terraform root of your own, use a module as a git source at the release tag. Such a module gets its chart from oci://ghcr.io/milaboratory/platforma-install/<chart>, at the version that the module pins. On a computer without internet access, set chart_repository to the folder helm/charts of the clone. For example:

source = "git::https://github.com/milaboratory/platforma-install.git//terraform/aws/platforma-tf-cloud-base?ref=<release tag>"

Secret values

The Backend needs three secret values. Make them one time, in a folder that only you can read, and keep the folder in a safe place:

  1. Put the license key into a file, with no final newline. For the key, see License.

    Terminal window
    mkdir -p ~/platforma-secrets && chmod 700 ~/platforma-secrets && cd ~/platforma-secrets
    printf '%s' '<license-key>' > license.txt
  2. Make the master secret. Keep this file: a new master secret signs out all users (see The secrets of Platforma).

    Terminal window
    openssl rand -base64 32 | tr -d '\n' > master-secret.txt
  3. Make the list of users with one user, admin. The examples give this login the administrator roleadministrator role — The role in the Backend that can read and change the data of all users and run the pl-cli administrator commands. The operator sets rules that give it to users by login, group or attribute. Glossary.

    Terminal window
    htpasswd -cB users.htpasswd admin # asks for the password of admin

Steps

Run all commands on the computer with the tools. Each root keeps its Terraform state in a local file in its folder: keep the folder of the clone, or move the state to the storage of Terraform states of the company.

  1. Apply the root cloud. It makes the network, the cluster, the storage and the entry point. Write the values into the file terraform.tfvars of the root: Terraform reads it by itself, and git ignores it. The name is the name of the cluster and the start of the names of most cloud resources. Use 1 to 18 characters (lowercase letters, digits and -), start with a letter, and end with a letter or a digit. The module refuses a longer name before it changes anything.

    Terminal window
    cd <platforma-install>/terraform/aws/examples/cloud
    terraform.tfvars
    region = "eu-central-1"
    name = "platforma"
    hosts = ["platforma.example.com"]
    dns = { zone_id = "<Route 53 zone ID>" }
    tls = { mode = "managed" } # the default
    # The networks that can reach the Kubernetes API
    kubernetes = { api_allowed_cidrs = ["198.51.100.0/24"] } # computers that run Terraform and kubectl

    kubernetes.api_allowed_cidrs does not have a default: the plan stops until you set it. We recommend the networks of the computers that run Terraform and kubectl only. To open the Kubernetes API to the whole internet, set ["0.0.0.0/0"].

    The entry point of Platforma is open to all addresses by default (gateway.allowed_cidrs, default ["0.0.0.0/0"]), so users connect from any network. Each request still needs a session of a user. To let only some networks reach the entry point, set them, for example gateway = { allowed_cidrs = ["203.0.113.0/24"] }. The list becomes the rules of the security group of the load balancer.

    The apply takes about 15 minutes. When the AWS credentials are a named profile, also set aws_profile = "<profile>" in this file, and add -var aws_profile=<profile> to the apply of the roots cluster and services.

    Terminal window
    terraform init
    terraform apply
    terraform output -json platforma_infrastructure > ../handoff/platforma-infrastructure.json
    terraform output -json cluster_connection > ../handoff/cluster-connection.json
    export KUBECONFIG="$HOME/.kube/platforma" # optional: keeps your other kubeconfig unchanged
    eval "$(terraform output -raw kubeconfig_command)"

    Result: kubectl get nodes shows the system nodes Ready.

    To change the sizes of the nodes or to add GPU nodes, see Jobs and resources. To limit the networks that reach the cluster and the entry point, to use a private entry point or a certificate of the company, see Domain and TLS. For the buckets of the data librariesdata library — A folder or bucket with input data of the company. Users select files from it in the Desktop App. Platforma only reads it. Glossary, see Data libraries.

  2. Apply the root cluster. It installs the storage drivers, the Gateway and the cloud controllers, then KueueKueue — A Kubernetes add-on that holds jobs in a queue until the cluster has free CPU, memory and GPU for them. Glossary, AppWrapperAppWrapper — A Kubernetes add-on that wraps the pods of one job into a single unit, so that Kueue admits and starts them together. Glossary and the job queues, and creates the namespace platforma. It reads the hand-off files of the root cloud, so it does not need values of its own. The apply takes about 2 minutes.

    Terminal window
    cd ../cluster
    terraform init
    terraform apply
    terraform output -json infrastructure > ../handoff/infrastructure.json

    Result: kubectl get namespace platforma shows Active.

  3. Create the Secrets, from the three files of the secret values. These are the default names and keys of the modules, so the values of the root services do not name them.

    Terminal window
    cd ~/platforma-secrets
    kubectl -n platforma create secret generic platforma-license --from-file=MI_LICENSE=license.txt
    kubectl -n platforma create secret generic platforma-master-secret --from-file=master-secret=master-secret.txt
    kubectl -n platforma create secret generic platforma-users --from-file=htpasswd=users.htpasswd

    Result: kubectl -n platforma get secrets lists the three Secrets.

    For the Secrets of other sign-in providerssign-in provider — A configured way for users to sign in to the Backend: single sign-on (SSO), LDAP or a static list of users. One Backend can have more than one. Glossary, see Authentication.

  4. Apply the root services. It installs the Backend.

    Terminal window
    cd <platforma-install>/terraform/cloud-agnostic/examples/services
    terraform.tfvars
    backend_service = {
    auth = {
    providers = [
    {
    name = "local"
    title = "Local password"
    htpasswd = { secret = { name = "platforma-users", key = "htpasswd" } }
    admin_users = ["admin"]
    },
    ]
    }
    }

    To pull the Backend image through the Backend cache of the root cloud, also add to backend_service the value registries.backend_image_repository of handoff/platforma-infrastructure.json of the root cloud:

    terraform.tfvars, in backend_service
    backend = { image = { repository = "<registries.backend_image_repository>" } }
    Terminal window
    terraform init
    terraform apply \
    -var infrastructure_file=../../../aws/examples/handoff/infrastructure.json \
    -var cluster_connection_file=../../../aws/examples/handoff/cluster-connection.json

    The apply waits until the Backend is ready: about 2 minutes.

    Result: kubectl -n platforma get pods shows the Backend pod Running, and terraform output entry_points shows the host.

    To change the sign-in, see Authentication and Users and roles. For the other settings of the Backend, see Storage, Data libraries, Jobs and resources, Proxy and custom CA and Registries.

  5. Check DNS and the certificate.

    The root cluster writes the DNS record of the host. For about 2 minutes after the apply of the root services, the Gateway can show Accepted=False: the load balancer controller then tries again by itself. Do not change anything in this time.

    Terminal window
    kubectl -n platforma-gateway get gateway platforma-gateway # PROGRAMMED: True
    Terminal window
    dig +short platforma.example.com
    openssl s_client -connect platforma.example.com:443 -servername platforma.example.com \
    -verify_hostname platforma.example.com -verify_return_error -alpn h2 </dev/null >/dev/null 2>&1 \
    && echo "certificate OK"

    Result: the host resolves to the address of the load balancer, and the second command shows certificate OK. When it shows nothing, the certificate is not valid for the host name: run openssl again without >/dev/null 2>&1 to see the error.

  6. Verify the installation. See Verify the installation.

  7. Connect the Desktop App to https://platforma.example.com, and sign in as admin with the password of the list of users. See Connect clients.

After a change of the values of one root, apply it, write its hand-off files again, and then run terraform plan in each later root, in the order of the roots. Apply each root whose plan shows changes. On Google Cloud, a change of gateway.scheme needs more applies: see Change the entry point type on Google Cloud. To put the modules into the infrastructure code of the company, use the example roots as a reference, with the inputs in Terraform modules.

Caches of the cloud-specific modules

By default, the root cloud makes two pull-through caches in the registry service of the cloud (Amazon ECR or Artifact Registry). A cache gets an image at the first pull and keeps it: the nodes do not pull each image from the internet, and the large software images of the jobs come faster.

Cache Images Default upstream in AWS Default upstream in Google Cloud
<name>-software the software images of the jobs, milaboratories/pl-containers https://quay.io https://containers.pl-open.science
<name>-backend the Backend image, milaboratories/platforma https://quay.io https://quay.io

The input registry_mirrors of the root cloud sets the caches:

terraform.tfvars
registry_mirrors = {
software = { enabled = true } # upstream = "..." to change the upstream
backend = { enabled = true }
}

enabled = false turns a cache off: the nodes then pull these images from the upstream. In AWS, ECR accepts only https://quay.io, https://public.ecr.aws and https://registry.k8s.io as an upstream, and the module always gives the nodes the right to read the caches. In Google Cloud, any upstream is possible, and the input also takes grant_node_access (default true): it gives the nodes the right to read the caches, and with false, the module does not use the caches.

The jobs use the software cache by themselves: when registries.default_docker_registry is empty, the module sets it to the path of this cache. A value that you set wins.

The Backend does not use its cache by itself. In the root services, set backend_service.backend.image.repository to the value registries.backend_image_repository of the hand-off file platforma-infrastructure.json. This value is empty when the Backend cache is off or the nodes cannot read it.

For mirrors that the company makes itself, see Registries mirroring.

Next