|
| 1 | +# Infernet Node Deployment |
| 2 | + |
| 3 | +Deploy a cluster of heterogenous [Infernet](https://github.com/ritual-net/infernet-node) nodes on Amazon Web Services (AWS) and / or Google Cloud Platform (GCP), using [Terraform](https://www.terraform.io/) for infrastructure procurement and [Docker compose](https://docs.docker.com/compose/) for deployment. |
| 4 | + |
| 5 | + |
| 6 | +### Setup |
| 7 | +1. [Install Terraform](https://developer.hashicorp.com/terraform/install) |
| 8 | +2. **Configure nodes**: A node configuration file **for each** node being deployed. |
| 9 | + - See [example configuration](configs/0.json.example). |
| 10 | + - They must be named `0.json`, `1.json`, etc... |
| 11 | + - Misnamed files are ignored. |
| 12 | + - They must be placed under the top-level `configs/` directory. |
| 13 | + - Each node *strictly* requires its own configuration `.json` file, even if those are identical. |
| 14 | + - Number of `.json` files must match the `node_count` variable in `terraform.tfvars`. |
| 15 | + - Extra files are ignored. |
| 16 | + - For instructions on configuring nodes, refer to the [Infernet Node](https://github.com/ritual-net/infernet-node). |
| 17 | + |
| 18 | +#### Infernet Router: |
| 19 | +The Infernet Router REST server is configured automatically by Terraform. However, if you plan to use it, you need to understand its implications: |
| 20 | +> **IMPORTANT:** When configuring a heterogeneous node cluster (i.e. `0.json`, `1.json`, etc. are not identical), container IDs should be reserved for a **unique container setup at the cluster level, i.e. across nodes (and thus `.json` files)**. That is becuase the router uses container IDs to make routing decisions between services running across the cluster. |
| 21 | +> |
| 22 | +> _Example:_ Consider nodes A and B, each running a single LLM inference container; node A runs `image1`, and node B runs `image2`. If we set `id: "llm-inference"` in both containers (`containers[0].id` attribute in `0.json`, `1.json`), the router will be **unable to disambiguate** between the two services, and will consider them interchangeable, _which they are not._ Any requests for `"llm-inference"` will be routed to either container, which is an error. |
| 23 | +> |
| 24 | +> Therefore, **re-using a IDs across configuration files must imply an identical container configuration**, including image, environment variables, command, etc. This will explicitly tell the router which containers are interchangeable, and allow it to distribute requests for those containers across _all nodes running that container._ |
| 25 | +
|
| 26 | +### Deploy on AWS |
| 27 | + |
| 28 | +1. Create an AWS service account for deployment: |
| 29 | + ```bash |
| 30 | + cd procure/aws |
| 31 | + chmod 700 create_service_account.sh |
| 32 | + ./create_service_account.sh |
| 33 | + ``` |
| 34 | + This will require local authentication with the AWS CLI. Add `access_key_id` and `secret_access_key` to your Terraform variables (see step 3). |
| 35 | + |
| 36 | +2. Make a copy of the example configuration file [terraform.tfvars.example](procure/aws/terraform.tfvars.example): |
| 37 | + ```bash |
| 38 | + cd procure/aws |
| 39 | + cp terraform.tfvars.example terraform.tfvars |
| 40 | + ``` |
| 41 | + |
| 42 | +3. Configure your `terraform.tfvars` file. See [variables.tf](procure/aws/variables.tf) for config descriptions. |
| 43 | + |
| 44 | +4. Run Terraform: |
| 45 | + ```bash |
| 46 | + # Initialize |
| 47 | + cd procure |
| 48 | + make init provider=aws |
| 49 | +
|
| 50 | + # Print deployment plan |
| 51 | + make plan provider=aws |
| 52 | +
|
| 53 | + # Deploy |
| 54 | + make apply provider=aws |
| 55 | +
|
| 56 | + # WARNING: Destructive |
| 57 | + # Destroy deployment |
| 58 | + make destroy provider=aws |
| 59 | + ``` |
| 60 | + |
| 61 | +### Deploy on GCP |
| 62 | + |
| 63 | + |
| 64 | +1. Create a GCP service account for deployment: |
| 65 | + ```bash |
| 66 | + cd procure/gcp |
| 67 | + chmod 700 create_service_account.sh |
| 68 | + ./create_service_account.sh |
| 69 | + ``` |
| 70 | + This will require local authentication with the GCP CLI, and create a local credentials file. Add the path to the credentials file (`gcp_credentials_file_path`) to your Terraform variables (see step 3). |
| 71 | + |
| 72 | +2. Make a copy of the example configuration file [terraform.tfvars.example](procure/gcp/terraform.tfvars.example): |
| 73 | + ```bash |
| 74 | + cd procure/gcp |
| 75 | + cp terraform.tfvars.example terraform.tfvars |
| 76 | + ``` |
| 77 | +3. Configure your `terraform.tfvars` file. See [variables.tf](procure/gcp/variables.tf) for config descriptions. |
| 78 | + |
| 79 | +4. Run Terraform: |
| 80 | + ```bash |
| 81 | + # Initialize |
| 82 | + cd procure |
| 83 | + make init provider=gcp |
| 84 | +
|
| 85 | + # Print deployment plan |
| 86 | + make plan provider=gcp |
| 87 | +
|
| 88 | + # Deploy |
| 89 | + make apply provider=gcp |
| 90 | +
|
| 91 | + # WARNING: Destructive |
| 92 | + # Destroy deployment |
| 93 | + make destroy provider=gcp |
| 94 | + ``` |
| 95 | + |
| 96 | +### Using TfLint |
| 97 | + |
| 98 | +```bash |
| 99 | +# Install tflint |
| 100 | +brew install tflint |
| 101 | +
|
| 102 | +# Install plugins |
| 103 | +tflint --init |
| 104 | +
|
| 105 | +# Run on all directories |
| 106 | +tflint --recursive |
| 107 | +``` |
| 108 | + |
| 109 | +## License |
| 110 | + |
| 111 | +[BSD 3-clause Clear](./LICENSE) |
0 commit comments