Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Use the Public OCI Flexible Network Load Balancer to Expose your Webserver Pool to the Internet
Introduction
In this tutorial, we will describe how to set up three Oracle Cloud Infrastructure (OCI) instances that will act as a webserver. These webservers will all be connected to a private subnet and will be made reachable from the internet using an OCI Flexible Network Load Balancer. The network load balancer will not only make the websites available through the internet but will also balance the load of the incoming connections to these three OCI Compute instances.
Objectives
-
We will create three OCI Compute instances that will act as a webserver and attach these to a private subnet. Then we will create an OCI Flexible Network Load Balancer that is accessible from the internet. With this, the OCI Flexible Network Load Balancer will balance the load based on the 5-tuple load balancing policy to the OCI Compute instances. We will also do some extensive testing by bringing down two of the three OCI Compute instances and verify if the OCI Flexible Network Load Balancer can detect this and act as expected.
-
Task 1: Create a new virtual cloud network (VCN).
-
Task 2: Create a new public subnet and private subnet.
-
Task 3: Create three new OCI Compute instances.
-
Task 4: Create a new OCI Flexible Network Load Balancer.
-
Task 5: Test the new OCI Flexible Network Load Balancer.
-
Task 1: Create a new Virtual Cloud Network (VCN)
We already have a VCN created but if you still need to create a new VCN, follow the tutorial: Create a New VCN with IPv6 Enabled.
Click the hamburger menu from the upper left corner. Click Virtual Cloud Networking to verify if the virtual cloud network exists.
Task 2: Create a new Public Subnet and Private Subnet
We already have a public and private subnet created but if you still need to create new subnets, follow the tutorials: Create a new Public Subnet with IPv6 Enabled and Create a Private Subnet inside the VCN.
-
Click the VCN to review the subnets.
- Inside this VCN, we have a public and private subnet available.
- Click the hamburger menu from the upper left corner to navigate to the OCI instances.
We will connect OCI Compute instance to the public subnet and OCI Database to the private subnet.
Task 3: Create Three new OCI Compute Instances
-
Click Instances to create three new OCI Compute instances.
-
To create the first instance, click Create Instance.
- Enter the Name of the instance.
- Scroll down.
-
Click Change Image.
Note:
-
We are deploying a custom image because the instance that we are deploying needs to have a webserver installed. In the previous tutorial we have already created an instance where we have installed the NGINX webserver with PHP and created a custom image based on this instance so that we do not have to install NGINX with PHP on three separate instances. For more information, see Use Oracle Cloud Infrastructure to Publish a Webserver Accessible from the Internet with IPv6.
-
To install the NGINX webserver with PHP, see Task 6: Install a Webserver on Instance.
- Click My Images.
- Scroll down.
- For this tutorial, we will select a custom image that we have created before that has the NGINX webserver with PHP pre-installed.
- Click Select Image.
-
Review the selected custom image.
-
Scroll down.
Note:
-
If you do not have any custom image feel free to select the Oracle Linux 8 image.
-
To manually install NGINX and PHP, see Task 6: Install a Webserver on Instance.
-
To install the custom webpage for testing purposes, see Task 8: Create a Custom Website with NGINX and PHP.
-
- For the Primary network, select Select existing virtual cloud network.
- Select the VCN created in Task 1.
- For the private subnet, select Select existing subnet.
- Select the subnet created in Task 2.
- Scroll down.
- For the Private IPv4 address, select Automatically assign private IPv4 address.
- Scroll down.
-
-
For this tutorial, we will use existing SSH keys. If you do not have any existing keys you can select Generate a key pair for me.
- Select Upload public key files (
.pub
). - Click Browse and select the public key that is already available.
- Make sure the
.pub
SSH key is selected. - Scroll down.
- Select Upload public key files (
-
Click Create.
-
When the first OCI Compute instance is created repeat the steps another two times to create two additional instances. So, the result should be that three OCI instances are running.
- Make sure the first OCI Compute instance is running. For this tutorial, it is
IH-WEBSERVER-01
. - Make sure the second OCI Compute instance is running. For this tutorial, it is
IH-WEBSERVER-02
. - Make sure the third OCI Compute instance is running. For this tutorial, it is
IH-WEBSERVER-03
. - Click the hamburger menu from the upper left corner to navigate to the network load balancers.
- Make sure the first OCI Compute instance is running. For this tutorial, it is
We have three webservers with a private IP address assigned.
Webserver and website on instances
For this tutorial, we have deployed a custom image and this image already has a webserver with NGINX and PHP installed. If you select to deploy a new vanilla Oracle Linux image, you need to install NGINX with PHP and the custom webpage manually. This is required to test the network load balancer. If you do not have any custom image feel free to select the Oracle Linux 8 image.
-
To manually install NGINX and PHP, see Task 6: Install a Webserver on Instance.
-
To create the custom webpage for testing purposes, see Task 8: Create a Custom Website with NGINX and PHP. Make sure you do this on all three OCI Compute instances.
Task 4: Create a new OCI Flexible Network Load Balancer
-
We have OCI Compute instances created. Let’s create a new network load balancer.
- Click Networking.
- Click Network load balancer.
-
Click Create network load balancer.
-
In Create network load balancer, enter the following information.
- Enter the Load balancer name.
- Select Public for the visibility type as we want this network load balancer to be reachable from the internet.
- Select Ephemeral IPv4 address as the public IP address.
- Click Next.
- Select the VCN created in Task 1.
- Select the public subnet created in Task 2.
- Click Next.
-
In Configure listener, enter the following information.
- Enter the Lister name.
- Select TCP for the type of traffic that the network load balancer needs to listen to.
- Select Specify the port and specify port
80
as we want the network load balancer to listen on TCP port80
for incoming connections. - Click Next.
-
In Configure backend, enter the following information.
- Enter the Backend set name.
- Click Add backends.
- Make sure the first OCI Compute instance is selected with the correct port. We will keep default Weight for now.
- Click + Another backend.
- Make sure the second OCI Compute instance is selected with the correct port. We will keep default Weight for now.
- Make sure the third OCI Compute instance is selected with the correct port. We will keep default Weight for now.
- Click Add backends.
- Review the backends.
- Click Next.
-
In the Specify health check policy section, enter the following information.
- Select HTTP as the Protocol to use for checking the backend servers.
- Select port
80
as the Port to use for checking the backend servers. - Click Next.
- Review the Load balancer details and the Listener details.
- Scroll down.
- Review the Backend set details.
- Scroll down.
- Review the Health check policy.
- Click Create network load balancer.
-
When the network load balancer is created the status will start with CREATING.
- After a few minutes the status will be changed to ACTIVE.
- As the health check policy still needs to kick in it may be that the overall health is started with the Unknown status.
- The same goes for the backend set health that may start with the Unknown status.
- After sometime the overall health is set to OK.
- The backend set health is also set to OK.
- Make a note of the public IP address that is assigned to the network load balancer.
We have built the setup shown in the following image.
Task 5: Test the new OCI Network Load Balancer
-
We have created all three OCI instances and the network load balancer. It is time to test the network load balancer.
- Open the browser and enter the public IP address of the network load balancer.
- Notice the public client IP address that we are browsing from.
- Notice the private server IP address which is the IP address of one of the OCI Compute instances.
-
Select the algorithm that is used for the OCI Compute instance.
- Scroll down
- Notice that the default Load balancing policy is set to 5-tuple-hash.
- To change this or review the other options, click the three dots.
- Click Edit.
- Notice that the 5-tuple-hash is selected.
- Click Cancel.
-
Go back to the browser.
- Click the refresh icon.
- Notice that the private server IP address which is the IP address of one of the OCI Compute instances has been changed from
10.0.2.140
to10.0.2.7
. This confirms that the network load balancer is working.
The visual representation of the path that is taken.
- Open the browser in private or incognito mode.
- Browse to the public IP address of the network load balancer.
- Notice that the private server IP address which is the IP address of one of the OCI Compute instances has been changed from
10.0.2.7
to10.0.2.140
.
The visual representation of the path that is taken.
- Click the refresh icon.
- Notice that the private server IP address which is the IP address of one of the OCI Compute instances has been changed from
10.0.2.140
to10.0.2.150
.
The visual representation of the path that is taken.
-
Let’s do one final test and bring down two OCI Compute instances.
- Click the hamburger menu from the upper left corner
- Click Instances.
- Select the first OCI Compute instance.
- Select the second OCI Compute instance.
- Click Actions.
- Click Stop.
-
Click Stop.
The stop is being processed.
-
Click Close.
- Notice that the first OCI Compute instance is stopped.
- Notice that the second OCI Compute instance is stopped.
- Notice that the third OCI Compute instance is still running.
The visual representation of the OCI Compute instances.
- Click the hamburger menu from the upper left corner.
- Click Networking.
- Click Network load balancer.
- Review the Overall health, the status is Critical.
- Click the network load balancer.
- Review the Overall health, the status is Critical.
- Review the Backend sets health, the status is Critical.
- Scroll down.
- Review the Overall health, the status is Critical.
- Click the backend set.
- Review the Overall Health, the status is Critical.
- The Backend health has 2 next to Critical and this corresponds with the OCI Compute instances that have gone down.
- The 1 that is OK is the only OCI Compute instance that is still up.
- Click Backends.
- Notice that the first OCI Compute instance has Critical health.
- Notice that the second OCI Compute instance has Critical health.
- Notice that the third OCI Compute instance has OK health.
- Refresh the webpage.
- Notice the private server IP address which is the IP address of the only OCI compute instance that is up.
The visual representation of the path that is taken.
- Go back to the instance page.
- Select the first OCI Compute instance.
- Select the second OCI Compute instance.
- Click Actions.
- Click Start.
-
Click Start.
The start is being processed.
-
Click Close.
Notice that the first and second OCI Compute instances are running again.
- Go back to the network load balancer page.
- Review the Overall health, the status is OK.
- Click the network load balancer.
- Review the health, the status is OK.
- Review the Backend set health, the status is OK.
- Click Backend sets.
- Review the health, the status is OK.
- Click the backend set.
- Review the Health, the status is OK.
- The 3 that is OK is the only OCI Compute instance that is up.
- Click Backends.
Notice that all OCI Compute instances have OK health.
Acknowledgments
- Author - Iwan Hoogendoorn (OCI Network Specialist)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Use the Public OCI Flexible Network Load Balancer to Expose your Webserver Pool to the Internet
F94477-01
March 2024