Deploy a PFN using GCP
This tutorial explains how to configure and deploy a PFN using Google Cloud (GCP). Running a PFN in the cloud usually provides better stability and availability compared to running it on your laptop.
This tutorial defaults to deploying a PFN in the Aptos devnet
network. To connect to other networks
(e.g., mainnet
and testnet
), replace all instances of devnet
with the appropriate network name.
Prerequisites
You can run the commands in this guide to deploy your PFN on Google Kubernetes Engine from any machine you want, e.g. a VM on GCP, Google Cloud Shell, or your personal computer.
The following packages are pre-installed with Cloud Shell. Make sure to review the documentation around ephemeral mode if you choose to use Cloud Shell. However, if you are running the installation from your laptop or another machine, you need to install:
- Terraform 1.3.6: https://www.terraform.io/downloads.html
- Kubernetes CLI: https://kubernetes.io/docs/tasks/tools/
- Google Cloud CLI: https://cloud.google.com/sdk/docs/install-sdk
After you have installed the gcloud CLI, log into GCP using gcloud:
gcloud auth login --update-adc
If you already have a GCP account setup, skip to Getting Started. If you do not have a GCP account, then follow the below sections to create and configure your GCP account.
GCP setup
Sign up for the 90-day free trial
Google Cloud offers a 90 day, $300 free trial for every new user. The $300 are given as credits to your account and you can use them to get a sense of Google Cloud products. Some GCP feature such as GPUs and Windows servers are not available in the free trial. Sign up for the credits, here.
Create a new GCP project
- Create a new project on the GCP Console or using the gcloud command from the Google Cloud CLI. Be sure to familiarize yourself with the resource hierarchy on GCP.
- Follow these instructions to setup a new project.
Enable billing, upgrade your account
You will still be able to use the free trial credits, but enabling billing allows you to have full access to all the features of GCP and not experience any interruption to your nodes. Upgrade your account by following the steps outlined here.
Additional GCP resources
This should be enough to get your GCP setup ready to start deploying your PFN. But if you are new to GCP, you may want to check out some of their guides and Google Cloud Skills Boost.
Getting started
From here on, this guide assumes that you have already set up your GCP account, and have created a new project for deploying an Aptos PFN.
You can deploy a PFN on GCP by using the Aptos Terraform module.
-
Create a working directory for your configuration.
- Choose a workspace name e.g.
devnet
. Note: This defines the Terraform workspace name, which in turn is used to form resource names. Feel free to choose a different name if you are connecting to a different network.
export WORKSPACE=devnet
- Create a directory for the workspace
mkdir -p ~/$WORKSPACE
- Choose a workspace name e.g.
-
Create a storage bucket for storing the Terraform state on Google Cloud Storage. Use the console or this gcs command to create the bucket. The name of the bucket must be unique. See the Google Cloud Storage documentation, here.
gsutil mb gs://BUCKET_NAME
# for example
gsutil mb gs://<project-name>-aptos-terraform-dev
- Create Terraform file called
main.tf
in your working directory:
cd ~/$WORKSPACE
touch main.tf
- Modify the
main.tf
file to configure Terraform and create a PFN from the Terraform module.
Note: If you are using a different version of Terraform, you will need to use the tfenv
command to change the required version.
You can find the Docker image tag for devnet
on the Aptos Docker Hub.
If you wish to connect to a different network than devnet
, you will need to find the appropriate Docker image
tag for that network and replace all references to it.
Example content for main.tf
:
terraform {
required_version = "~> 1.3.6"
backend "gcs" {
bucket = "BUCKET_NAME" # bucket name created in step 2
prefix = "state/fullnode"
}
}
module "fullnode" {
# download Terraform module from aptos-labs/aptos-core repo
source = "github.com/aptos-labs/aptos-core.git//terraform/fullnode/gcp?ref=main"
region = "us-central1" # Specify the region
zone = "c" # Specify the zone suffix
project = "gcp-fullnode" # Specify your GCP project ID
fullnode_name = "BUCKET_NAME" #bucket name created in step 2
era = 1 # bump era number to wipe the chain
image_tag = "devnet" # Specify the docker image tag
}
- Initialize Terraform in the same directory of your
main.tf
file:
terraform init