File size: 7,376 Bytes
0a84888 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
---
#https://www.notion.so/n8n/Frontmatter-432c2b8dff1f43d4b1c8d20075510fe4
contentType: tutorial
---
# Hosting n8n on Amazon Web Services
This hosting guide shows you how to self-host n8n with Amazon Web Services (AWS). It uses n8n with Postgres as a database backend using Kubernetes to manage the necessary resources and reverse proxy.
## Hosting options
AWS offers several ways suitable for hosting n8n, including EC2 (virtual machines), and EKS (containers running with Kubernetes).
This guide uses [EKS](https://aws.amazon.com/eks/){:target=_blank .external-link} as the hosting option. Using Kubernetes requires some additional complexity and configuration, but is the best method for scaling n8n as demand changes.
## Prerequisites
The steps in this guide use a mix of the AWS UI and [the eksctl CLI tool for EKS](https://eksctl.io){:target=_blank .external-link}.
While not mentioned in the documentation for eksctl, you also need to [install the AWS CLI tool](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html){:target=_blank .external-link}, and [configure authentication of the tool](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html){:target=_blank .external-link}.
--8<-- "_snippets/self-hosting/warning.md"
--8<-- "_snippets/self-hosting/installation/latest-next-version.md"
## Create a cluster
Use the eksctl tool to create a cluster specifying a name and a region with the following command:
```shell
eksctl create cluster --name n8n --region <your-aws-region>
```
This can take a while to create the cluster.
Once the cluster is created, eksctl automatically sets the kubectl context to the cluster.
## Clone configuration repository
Kubernetes and n8n require a series of configuration files. You can clone these from [this repository](https://github.com/n8n-io/n8n-kubernetes-hosting/tree/aws){:target=_blank .external-link}. The following steps tell you what each file does, and what settings you need to change.
Clone the repository with the following command:
```shell
git clone https://github.com/n8n-io/n8n-kubernetes-hosting.git -b aws
```
And change directory to the root of the repository you cloned:
```shell
cd n8n-kubernetes-hosting
```
## Configure Postgres
For larger scale n8n deployments, Postgres provides a more robust database backend than SQLite.
### Configure volume for persistent storage
To maintain data between pod restarts, the Postgres deployment needs a persistent volume. The default AWS storage class, [gp2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/general-purpose.html#EBSVolumeTypes_gp2){:target=_blank .external-link}, is suitable for this purpose. This is defined in the `postgres-claaim0-persistentvolumeclaim.yaml` manifest.
```yaml
…
spec:
storageClassName: gp2
accessModes:
- ReadWriteOnce
…
```
### Postgres environment variables
Postgres needs some environment variables set to pass to the application running in the containers.
The example `postgres-secret.yaml` file contains placeholders you need to replace with values of your own for user details and the database to use.
The `postgres-deployment.yaml` manifest then uses the values from this manifest file to send to the application pods.
## Configure n8n
### Create a volume for file storage
While not essential for running n8n, using persistent volumes helps maintain files uploaded while using n8n and if you want to persist [manual n8n encryption keys](/hosting/configuration/environment-variables/deployment.md) between restarts, which saves a file containing the key into file storage during startup.
The `n8n-claim0-persistentvolumeclaim.yaml` manifest creates this, and the n8n Deployment mounts that claim in the `volumes` section of the `n8n-deployment.yaml` manifest.
```yaml
…
volumes:
- name: n8n-claim0
persistentVolumeClaim:
claimName: n8n-claim0
…
```
### Pod resources
[Kubernetes](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/){:target=_blank .external-link} lets you specify the minimum resources application containers need and the limits they can run to. The example YAML files cloned above contain the following in the `resources` section of the `n8n-deployment.yaml` file:
```yaml
…
resources:
requests:
memory: "250Mi"
limits:
memory: "500Mi"
…
```
This defines a minimum of 250mb per container, a maximum of 500mb, and lets Kubernetes handle CPU. You can change these values to match your own needs. As a guide, here are the resources values for the n8n cloud offerings:
--8<-- "_snippets/self-hosting/installation/suggested-pod-resources.md"
### Optional: Environment variables
You can configure n8n settings and behaviors using environment variables.
Create an `n8n-secret.yaml` file. Refer to [Environment variables](/hosting/configuration/environment-variables/index.md) for n8n environment variables details.
## Deployments
The two deployment manifests (`n8n-deployment.yaml` and `postgres-deployment.yaml`) define the n8n and Postgres applications to Kubernetes.
The manifests define the following:
- Send the environment variables defined to each application pod
- Define the container image to use
- Set resource consumption limits
- The `volumes` defined earlier and `volumeMounts` to define the path in the container to mount volumes.
- Scaling and restart policies. The example manifests define one instance of each pod. You should change this to meet your needs.
## Services
The two service manifests (`postgres-service.yaml` and `n8n-service.yaml`) expose the services to the outside world using the Kubernetes load balancer using ports 5432 and 5678 respectively by default.
## Send to Kubernetes cluster
Send all the manifests to the cluster by running the following command in the `n8n-kubernetes-hosting` directory:
```shell
kubectl apply -f .
```
/// note | Namespace error
You may see an error message about not finding an "n8n" namespace as that resources isn't ready yet. You can run the same command again, or apply the namespace manifest first with the following command:
```shell
kubectl apply -f namespace.yaml
```
///
## Set up DNS
n8n typically operates on a subdomain. Create a DNS record with your provider for the subdomain and point it to a static address of the instance.
To find the address of the n8n service running on the instance:
1. Open the **Clusters** section of the **Amazon Elastic Kubernetes Service** page in the AWS console.
2. Select the name of the cluster to open its configuration page.
3. Select the **Resources** tab, then **Service and networking** > **Services**.
4. Select the **n8n** service and copy the **Load balancer URLs** value. Use this value suffixed with the n8n service port (5678) for DNS.
/// note | Use HTTP
This guide uses HTTP connections for the services it defines, for example in `n8n-deployment.yaml`. However, if you click the **Load balancer URLs** value, EKS takes you to an "HTTPS" URL which results in an error. To solve this, when you open the n8n subdomain, make sure to use HTTP.
///
## Delete resources
If you need to delete the setup, you can remove the resources created by the manifests with the following command:
```shell
kubectl delete -f .
```
## Next steps
--8<-- "_snippets/self-hosting/installation/server-setups-next-steps.md"
|