-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the basic example easier to deploy and test
- Loading branch information
Showing
3 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
# Basic example | ||
|
||
A simple example with 3 servers and a load balancer that distributes the traffic between them. The example assumes that each of the servers has some application listening on port 3000. | ||
A simple example with 3 servers and a load balancer that distributes the traffic between them. The example uses an user-data script to launch a HTTP server listening to port 80 on each server. The example does not enable TLS on frontend by default. | ||
|
||
Once you deploy it, go to your domain settings and add a CNAME record that points to the `lb_url` output variable. After the change gets propagated, all the traffic to your domain (`my.domain.com` in this example) will be distributed among the 3 servers. | ||
## Getting started | ||
|
||
To deploy private network, three servers, and load balancer on your UpCloud account, run: | ||
|
||
```bash | ||
terraform init | ||
terraform apply | ||
``` | ||
|
||
Once the deployment is complete and load balancer has reached `running` state you can use `curl` or your browser to send request to the load balancer available in the URL defined by `lb_url` output variable: | ||
|
||
```bash | ||
curl $(terraform output -raw lb_url) | ||
``` | ||
|
||
Note that it might take some time for the DNS name to propagate. During this time the above `curl` command will likely fail with `Could not resolve host: ...` error message. | ||
|
||
The output should include hostname of the backend server, for example: | ||
|
||
```txt | ||
Hello from lb-module-basic-example-server-1 | ||
``` | ||
|
||
## Enable TLS | ||
|
||
The example does not enable TLS on frontend by default. To enable TLS, uncomment `domains` variable in [main.tf](./main.tf) and replace example domain with your domain. Change also the value for `frontend_port` from `80` to `443`. | ||
|
||
Deploy the changes with `terraform apply`. When the deployment is completed, go to your domain settings and add a CNAME record that points to the `lb_url` output variable. After the change gets propagated, all the traffic to your domain will be distributed among the 3 servers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# Install HTTP server and firewall | ||
apt update | ||
apt install -y apache2 ufw | ||
|
||
# Add hostname to HTTP response to identify back-end server | ||
echo "Hello from $(hostname)" > /var/www/html/index.html | ||
|
||
# Allow incoming traffic only from private network | ||
ufw enable | ||
ufw allow in on eth2 |