Ops Autoscaling
Ops Autoscaling
Autoscaling
Try this hands-on lab with the Oracle Cloud Free Tier. If you do not have a free
account, click here to get one.
Overview
In this practice, you create a load balancer. When you create a load balancer, you choose its
shape (size) and specify subnets from different Availability Domains. This ensures that the
load balancer is highly available.
Tasks
1. Log in to the OCI free tier account
2. From the OCI Services menu, select Load Balancers under Networking.
3. Click Create Load Balancer. Fill out the dialog box:
Under Add Details
Load Balancer Name: Enter a name for your load balancer, for example, opslb.
Choose Visibility Type: Select Public.
Virtual Cloud Network: Choose the OpsVCN Virtual Cloud Network.
Subnet: Choose the Public Subnet.
Click Next Step.
4. Under Choose Backends:
Specify a Load Balancing Policy: Weighted Round Robin
Add Backends: Don't add any backend. This will be managed by the instance pool.
Overview
Configuring an instance pool requires creating an instance configuration.
Tasks
1. From the OCI services menu, select Instances under Compute.
2. Click Create Instance. Fill out the dialog box:
Name your instance: opsauto
Compartment: Ensure that the Compartment assigned to you is selected.
Availability Domain: Select any Availability Domain.
Image Operating System: Use the default, the latest Oracle Linux available.
Shape: Select - VM.Standard.E2.1.Micro. Ensure to use Virtual Machine instance
type and change the shape if this is not selected by default.
Configure Networking:
Network: Choose Select existing cloud network.
VCN Compartment: The same that has been allocated to you
For VCN: Select OpsVCN created earlier.
Subnet: Select the Public Subnet of your VNC.
Select Assign a public IP address.
SSH Key: Select the Paste public keys option and paste the public ssh key you had
created earlier using Cloud Shell.
Boot Volume: Use the default; leave this section as is.
yum_repos:
# The name of the repository
epel-testing:
# Any repository configuration options
# See: man yum.conf
#
# This one is required!
baseurl:
https://yum$ociregion.oracle.com/repo/OracleLinux/OL7/developer_
EPEL/$basearch/
enabled: true
failovermethod: priority
gpgcheck: false
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
name: Extra Packages for Enterprise Linux 5 - Testing
packages:
- httpd
- stress
runcmd:
- [sh, -c, echo "<html>Web Server IP `hostname --ip-
address`</html>" > /var/www/html/index.html]
- [firewall-offline-cmd, --add-port=80/tcp]
- [systemctl, start, httpd]
- [systemctl, restart, firewalld]
10. Select the Load Balancer you created previously, and then the only Backend Set in the
menu. Enter port 80 and then “Primary VNIC”. Click Attach.
11. On the Instance Pool Details page, from the More Actions menu, select Create Auto
Scaling Configuration. Fill out the dialog box:
Compartment: Choose your compartment.
Autoscaling Configuration Name: Provide a name.
Instance Pool: This should show your instance pool name created earlier.
Copyright © 2021, Oracle and/or its affiliates.
We have now created an autoscaling policy that will start with creating one compute instance
in the designated pool.
Once the CPU utilization is determined to be above 40% for at least 300 seconds
another compute instance will be launched automatically.
Once the CPU utilization is determined to be less than 10% for 300 seconds, one
compute instance will be removed.
At all times, there will be at least one compute instance in the pool.
The original image can be deleted because it's not part of the pool.
Tasks
This test may not succeed on always free-account because of limits, however the process
done here will give you idea on auto-scaling with load-balancers, scaling rules, backend
sets
1. Click Instance Pools under Compute and then your pool name. You should see a
Compute instance created. You may have to wait a few minutes for it to be provisioned.
Click the Compute Instance name.
2. Note down the Public and Private IP of compute instance from the details page (under the
Primary VNIC Information section).
3. Open a web browser and enter load balancer's public IP address. You should see the
message: Web Server IP: <instance private IP>. If you get an error such as
“502 Invalid Gateway”, wait a few minutes for the compute instance to be fully
initialized and try again.
Note: In case you wait 10 minutes and still encounter an error, check the back-end pool
status. Check the assigned port number.
4. Connect to the instance from the local machine, use the Terminal.
$ ssh –i <path-of-pub-ssh-key> opc@<Public_IP_of_Compute>
5. Now start CPU stress; enter the command:
$ sudo stress --cpu 4 --timeout 700
Spawn 4 workers spinning on sqrt() with a timeout of 700 seconds.
6. Switch back to OCI console and navigate to the Instance Pool Details page. Click your
instance name and scroll down to the Metric screen. You should see CPU spiking up after
a minute or so.
8. When the second instance is up and running and the instance pool status is Running,
switch to the web browser and refresh the page multiple times and observe the load
balancer balancing traffic between the two web servers.
9. Switch back to the terminal window and if the stress tool is still running, press Ctrl + C to
stop the script.
10. Switch back to the OCI console window and navigate to your compute instance details
page. Verify that the CPU utilization goes down after a minute.
11. Navigate to the Instance Pool Details page and after 3-4 minutes, the Instance pool status
will change to Scaling. Additional compute instances will be deleted.
This is because your criteria of CPU utilization < 10 is met.